Skip to content

Commit

Permalink
Realized there is no need for transitive closure to correctly synthsi…
Browse files Browse the repository at this point in the history
…ze code
  • Loading branch information
tpops committed Feb 14, 2023
1 parent bee393c commit 0a517ac
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,49 @@ more formats will be added
```shell script
cd build
./bin/CodeSynthesis_Driver -src <formatname>,<dataName> -dest <formatName>,<dataName>\
[-fuse <statement-list-delimited-by-comma> -fuselevel <level>]
[-fuse <statement-list-delimited-by-comma> -fuselevel <level>] [-known "<set>"]
```



Driver generates synth.h and synth.c files which can be compiled / added to a pre-existing project.

### Optimization options

Fuse Syntax:

Example S0: {[0,i,0,j,0] | stuff}; S1:{[1,i,0,j,0] | stuff}

Option: -fuse S0,S1 -fuselevel 2

```cpp
for (i to ..)
for (j to ..)
S0

for (i to ..)
for (j to ..)
S1
```

Result
S0: {[0,i,0,j,0] | stuff}; S1:{[0,i,1,j,0] | stuff}


```cpp
for (i to ..)
for (j to ..)
S0
S1
```

Constraint simplification:

option: -known "<iteration space>"

The iteration space explores constraints that are true and not needed to be generated


### Examples

COO TO CSR + Fusion
Expand Down
6 changes: 3 additions & 3 deletions src/CodeSynthesis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ CodeSynthesis::CodeSynthesis(SparseFormat* source,

//std::cout << "Composed Rel: " << composeRel->prettyPrintString() << "\n";

transRel = composeRel->TransitiveClosure();
transRel = new Relation(*composeRel);
// Expanded candidates for statement selections.
transRelExpanded = substituteDirectEqualities(transRel);

Expand Down Expand Up @@ -1475,7 +1475,7 @@ CodeSynthesis::getCopyReadAccess() {


std::string CodeSynthesis::generateFullCode(std::vector<int>& fuseStmts,
int level) {
int level,iegenlib::Set* known ) {
Computation* comp = generateInspectorComputation();
// Manual Fusion
ReadReductionFusionOptimization(comp,fuseStmts,level);
Expand Down Expand Up @@ -1582,7 +1582,7 @@ std::string CodeSynthesis::generateFullCode(std::vector<int>& fuseStmts,
destDataAccessMap->getTupleDecl().elemVarString(i)) << "]";
}
ss << "\n";
std::string code = comp->codeGen();
std::string code = comp->codeGen(known);

for(auto permute : permutes) {
// This has to be modified to use
Expand Down
3 changes: 2 additions & 1 deletion src/CodeSynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class CodeSynthesis {

~CodeSynthesis();

std::string generateFullCode( std::vector<int>& fuseStmts,int level);
std::string generateFullCode( std::vector<int>& fuseStmts,int level,
iegenlib::Set* known = NULL);


/// This gets the list of all expressions in a conjunction.
Expand Down
17 changes: 12 additions & 5 deletions src/drivers/code_synthesis_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

using namespace code_synthesis;
int main(int argc, char**argv) {
if(argc != 5 && argc != 9) {
if(argc != 5 && argc != 9 && argc!=7 && argc!= 11) {
std::cerr << "Usage: synthDriver -src "
<<"<formatname>,<dataName> -dest <formatName>,<dataName> "
<<" [-fuse <fuse-list> -fuselevel <level>]\n";
<<" [-fuse <fuse-list> -fuselevel <level> ] [-known \"<space>\"] \n";
return 0;
}
// Load preset optimizations
Expand Down Expand Up @@ -213,7 +213,7 @@ int main(int argc, char**argv) {
SparseFormat* sourceFormat = NULL;
SparseFormat* destFormat = NULL;


Set* known = NULL;
while(currIndex < argc ) {
std::string argString (argv[currIndex]);
if(argString == "-src") {
Expand Down Expand Up @@ -259,12 +259,19 @@ int main(int argc, char**argv) {
std::string level(argv[++currIndex]);
fuseLevel = std::stoi(level);
}
currIndex++;

if (argString == "-known"){
std::string s(argv[++currIndex]);
std::cout << "test: "<< s << "\n";
known = new Set(s);
}

currIndex++;
}
assert(sourceFormat && destFormat
&& "Unsopported Source or Destination Format");
CodeSynthesis* synth = new CodeSynthesis(sourceFormat, destFormat);
std::string code = synth->generateFullCode(fuseStmts,fuseLevel);
std::string code = synth->generateFullCode(fuseStmts,fuseLevel,known);
std::ofstream fileOut;
fileOut.open("synth.h");
fileOut << synth->GetSupportHeader();
Expand Down

0 comments on commit 0a517ac

Please sign in to comment.