Skip to content

Commit

Permalink
Worked on expansion of transitive closure #169. This is a current tri…
Browse files Browse the repository at this point in the history
…vial solution, and a test case was added
  • Loading branch information
tpops committed Jan 16, 2022
1 parent 264870e commit 6d9f15a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 27 deletions.
32 changes: 15 additions & 17 deletions src/computation/computation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1687,14 +1687,14 @@ TEST_F(ComputationTest, NestedUFComputationTest) {
EXPECT_EQ("#undef s0\n"
"#undef s_0\n"
"#define s_0(n, k) s0 \n"
"#define s0(__x0, a1, tv2, __x2, a3, __x4) s_0(a1, a3);\n"
"#define s0(__x0, a1, tv2, __x3, a3, __x5) s_0(a1, a3);\n"
"\n"
"#undef row_1\n"
"#undef rowptr_0\n"
"#undef row_0\n"
"#undef rowptr_1\n"
"#define row(t0) row[t0]\n"
"#define row_1(__tv0, __tv1) row(__tv1)\n"
"#define row_0(__tv0, __tv1) row(__tv1)\n"
"#define rowptr(t0) rowptr[t0]\n"
"#define rowptr_0(__tv0, __tv1, __tv2) rowptr(__tv2 + 1)\n"
"#define rowptr_1(__tv0, __tv1, __tv2) rowptr(__tv2 + 1)\n"
"\n"
"t1 = 0; \n"
"t2 = 0; \n"
Expand All @@ -1704,16 +1704,16 @@ TEST_F(ComputationTest, NestedUFComputationTest) {
"t6 = 0; \n"
"\n"
"for(t2 = 0; t2 <= NNZ-1; t2++) {\n"
" t3=row_1(t1,t2);\n"
" for(t5 = rowptr_0(t1,t2,t3); t5 <= P-1; t5++) {\n"
" t3=row_0(t1,t2);\n"
" for(t5 = rowptr_1(t1,t2,t3); t5 <= P-1; t5++) {\n"
" s0(0,t2,t3,0,t5,0);\n"
" }\n"
"}\n"
"\n"
"#undef s0\n"
"#undef s_0\n"
"#undef row_1\n"
"#undef rowptr_0\n"
"#undef row_0\n"
"#undef rowptr_1\n"
"",codeGenStr);

delete comp;
Expand Down Expand Up @@ -1759,7 +1759,7 @@ TEST_F(ComputationTest, NestedUFComputationTest) {
"#define s_0(tv0, tv1, tv2) P.insert(row(n), col2(n)) \n"
"#define s0(__x0, a1, __x2, a3, __x4, a5, __x6) s_0(a1, a3, a5);\n"
"#define s_1(n, k) ACSR(n,k) = ACOO(n,k) \n"
"#define s1(__x0, a1, tv2, __x2, a3, __x4, __x5, __x6, _x7) s_1(a1, a3);\n"
"#define s1(__x0, a1, tv2, __x3, __x4, __x5, __x6, __x7, __x8) s_1(a1, a3);\n"
"\n"
"#undef P_2\n"
"#undef col1_3\n"
Expand Down Expand Up @@ -1798,14 +1798,12 @@ TEST_F(ComputationTest, NestedUFComputationTest) {
" }\n"
" }\n"
" for(t2 = 0; t2 <= NNZ-1; t2++) {\n"
" if (col2_1(t1,t2) >= 0 && row_0(t1,t2) >= 0 && NC >= col2_1(t1,t2)+1 && NR >= row_0(t1,t2)+1) {\n"
" if (col2_1(t1,t2) == 0 && NR >= row_0(t1,t2)+1 && row_0(t1,t2) >= 0) {\n"
" t3=row_0(t1,t2);\n"
" if (rowptr_5(t1,t2,t3) >= rowptr_4(t1,t2,t3)+1) {\n"
" t4=col2_1(t1,t2);\n"
" if (rowptr_5(t1,t2,t3) >= P_2(t1,t2,t3,t4)+1 && P_2(t1,t2,t3,t4) >= rowptr_4(t1,t2,t3)) {\n"
" t6=P_2(t1,t2,t3,t4);\n"
" if (col1_3(t1,t2,t3,t4,t5,t6) == col2_1(t1,t2)) {\n"
" s1(1,t2,t3,t4,0,t6,0,0,0);\n"
" if (rowptr_4(t1,t2,t3) <= 0 && rowptr_5(t1,t2,t3) >= 1) {\n"
" if (P_2(t1,t2,t3,t4) == 0) {\n"
" if (col1_3(t1,t2,t3,t4,t5,t6) == 0) {\n"
" s1(1,t2,t3,0,0,0,0,0,0);\n"
" }\n"
" }\n"
" }\n"
Expand Down
5 changes: 1 addition & 4 deletions src/set_relation/set_relation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,6 @@ Conjunction* Conjunction::TransitiveClosure(){
// information.
for (std::list<Exp*>::const_iterator i=retVal->mEqualities.begin();
i != retVal->mEqualities.end(); i++) {
//TODO: Make this a function.
// Split Terms as different nodes
Vertex lhsNode;
Vertex rhsNode;
Expand All @@ -1668,7 +1667,6 @@ Conjunction* Conjunction::TransitiveClosure(){
lhsNode.addTerm(t->clone());
}
}
// TODO: Remove current expression from the list.
// Add edge between lhs and rhs in the graph.
g->addEdge(lhsNode,rhsNode,EdgeType::EQUAL);

Expand All @@ -1689,7 +1687,6 @@ Conjunction* Conjunction::TransitiveClosure(){
lhsNode.addTerm(t->clone());
}
}
// TODO: Remove current expression from the list.
// Add edge between lhs and rhs in the graph.
g->addEdge(lhsNode,rhsNode,EdgeType::GREATER_OR_EQUAL_TO);
}
Expand All @@ -1698,7 +1695,7 @@ Conjunction* Conjunction::TransitiveClosure(){
g->simplifyGreaterOrEqual();
g->transitiveClosure();
g->findAddMonotonicity ();
// std::cout << "After: \n";
//std::cout << "After: \n";
//std::cout << g->toDotString();
// Delete all expressions in the retVal conjunction.
retVal->reset();
Expand Down
23 changes: 23 additions & 0 deletions src/set_relation/set_relation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4724,6 +4724,29 @@ TEST_F(SetRelationTest, TransitiveClosure){
" n - idx(i) - 1 >= 0 && n - idx(i + 1) - 1"
" >= 0 && -idx(i) + idx(i + 1) - 1 >= 0 }"
,clo5->prettyPrintString());
rel = new Relation("{ [n] -> [i, k] : i - row1(n) = 0 "
"&& k - P1(row1(n), col1(n)) = 0 &&"
" col1(n) - col2(k) = 0 && n >= 0 &&"
" i >= 0 && col1(n) >= 0 &&"
" row1(n) >= 0 && k - rowptr(i) >= 0 &&"
" -n + NNZ - 1 >= 0 &&"
" -i + NR - 1 >= 0 && -k + rowptr(i + 1) - 1 >= 0 &&"
" NC - col1(n) - 1 >= 0 &&"
" NR - row1(n) - 1 >= 0 }");
closure = rel->TransitiveClosure();
EXPECT_EQ("{ [n] -> [i, k] : i - row1(n) = 0 &&"
" k - P1(row1(n), col1(n)) = 0 && col1(n) - col2(k) = 0 &&"
" n >= 0 && i >= 0 && col1(n) >= 0 && col2(k) >= 0 &&"
" row1(n) >= 0 && k - rowptr(i) >= 0 &&"
" NC - 1 >= 0 && NNZ - 1 >= 0 && NR - 1 >= 0"
" && P1(row1(n), col1(n)) - rowptr(i) >= 0"
" && -n + NNZ - 1 >= 0 && -i + NR - 1 >= 0"
" && -k + rowptr(i + 1) - 1 >= 0 && NC - col1(n) - 1 >= 0 &&"
" NC - col2(k) - 1 >= 0 && NR - row1(n) - 1 >= 0 &&"
" -P1(row1(n) + 1, col1(n)) + P1(row1(n), col1(n)) - 1 >= 0 &&"
" -P1(row1(n), col1(n)) + rowptr(i + 1) - 1 >= 0 &&"
" -rowptr(i) + rowptr(i + 1) - 1 >= 0 }",
closure->prettyPrintString());

delete set;
delete clo5;
Expand Down
44 changes: 38 additions & 6 deletions src/set_relation/transitive_closure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ void DiGraph::transitiveClosure(){
}


std::vector<Term*> DiGraph::getAliasTerms(Term& t){
Vertex tVert;
tVert.addTerm(&t);
std::vector<Term*> res;
for(int i = 0; i < vertices.size() ; i++){
Vertex& vertex = vertices[i];
if (vertex == tVert){
// Find vertices with equality relationships
// we are currently only concerned with
// single terms
for( int j = 0; j < adj[i].size(); j++){
if(i!=j && adj[i][j] == EdgeType::EQUAL){
Vertex& jVertex = vertices[j];
if(jVertex.getTermList().size() == 1){
res.push_back(jVertex.getTermList().front());
}
}
}
}
}
return res;
}

void DiGraph::simplifyGreaterOrEqual(){
int size = adj.size();
Expand Down Expand Up @@ -431,21 +453,31 @@ void DiGraph::findAddMonotonicity (){
for( int q = 0; q < currentUF->numArgs(); q++){
Exp* exp = currentClone->getParamExp(q);
for(auto term: exp->getTermList()){

// At this point there are new relationships
// and a term T might be equal to some other
// terms so we need to get alias terms
auto aliasTerms= getAliasTerms(*term);
auto it = std::find_if(paramExpPairs.begin(),
paramExpPairs.end(),
[term](
[term,&aliasTerms](
std::pair<Exp*,Exp*>& e){
return e.first->dependsOn(*term)

bool res = false;
for(auto t : aliasTerms){
res|= e.first->dependsOn(*t) ||
e.second->dependsOn(*t);
}
res |= e.first->dependsOn(*term)
|| e.second->dependsOn(*term);
return res;
});
if (it!=paramExpPairs.end()){

Exp* expTemp = (*it).second->clone();
Exp* expTempUBound = (*it).second->clone();
Exp* expTempLBound = (*it).first->clone();
expTempLBound->multiplyBy(-1);
expTemp->addExp(expTempLBound);
exp->addExp(expTemp);
expTempUBound->addExp(expTempLBound);
exp->addExp(expTempUBound);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/set_relation/transitive_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class DiGraph{

//! Converts an edge to an actual string.
std::string edgeToString (const EdgeType e)const;
//! This function performs a lookup of nodes in
//the graph and returns single term nodes that
//have a direct equality relationship with this term
// \param t term being aliased for and is not adopted.
std::vector<Term*> getAliasTerms(Term& t);
public:

DiGraph();
Expand Down

0 comments on commit 6d9f15a

Please sign in to comment.