Skip to content

Commit

Permalink
Added MultipleTransfromations example to HowToLCIR
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-bertolacci committed Apr 12, 2016
1 parent a6fd132 commit f0f9474
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 5 deletions.
12 changes: 7 additions & 5 deletions HowToLoopChainIR/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PROJECT_DIR=..
SRC=$(PROJECT_DIR)/src
BIN=$(PROJECT_DIR)/bin
LIB=$(PROJECT_DIR)/lib

THIRD_PARTY=$(PROJECT_DIR)/third-party
THIRD_PARTY_SRC=$(THIRD_PARTY)/source
Expand All @@ -11,8 +12,8 @@ INITED_FILE=$(THIRD_PARTY)/initialized

DOC_PATH = $(PROJECT_DIR)/doxygen

LIB=$(THIRD_PARTY_INSTALL)/lib
INC=$(THIRD_PARTY_INSTALL)/include
T_LIB=$(THIRD_PARTY_INSTALL)/lib
T_INC=$(THIRD_PARTY_INSTALL)/include

EX_SRC=./src
EX_BIN=./bin
Expand All @@ -22,18 +23,19 @@ EXAMPLES = RectangularDomainHowTo \
LoopChainHowTo \
ScheduleHowTo \
FusionTransformationHowTo \
ShiftTransformationHowTo
ShiftTransformationHowTo \
MultipleTransformations

LONG_EXAMPLES=$(addprefix $(EX_BIN)/,$(EXAMPLES))

LCIR_LIB=$(BIN)/LoopChainIR.a
LCIR_LIB=$(LIB)/libloopchainIR.a

all: $(LONG_EXAMPLES)

$(EXAMPLES): % : $(EX_BIN)/%

$(LONG_EXAMPLES): $(EX_BIN)/% : $(EX_SRC)/%.cpp $(LCIR_LIB)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(SRC) -Wl,-rpath -Wl,$(LIB) $^ -L$(LIB) -lisl -o $@
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(SRC) -Wl,-rpath -Wl,$(T_LIB) $^ -L$(T_LIB) -lisl -o $@

clean:
- rm $(EX_BIN)/*
Empty file added HowToLoopChainIR/bin/.gitkeep
Empty file.
114 changes: 114 additions & 0 deletions HowToLoopChainIR/src/MultipleTransformations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/******************************************************************************
How To Schedule
Recommended Reading:
+ ScheduleHowTo.cpp
******************************************************************************/
#include "ShiftTransformation.hpp"
#include "FusionTransformation.hpp"
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main(){
{
cout << "Shift-Fuse example on 2N_1D example" << endl;
LoopChain chain;
{
string lower[1] = { "1" };
string upper[1] = { "N" };
string symbols[1] = { "N" };
chain.append( LoopNest( RectangularDomain( lower, upper, 1, symbols, 1 ) ) );
}
{
// This loop is a shifted version of the previous one.
// How handy!
string lower[1] = { "1+9" };
string upper[1] = { "N+9" };
string symbols[1] = { "N" };
chain.append( LoopNest( RectangularDomain( lower, upper, 1, symbols, 1 ) ) );
}
// Create Schedule object from chain
Schedule sched( chain );

// Print everything
cout << "Before Transformation:\n"
<< "Schedule state:\n" << sched
<< "\nDefault scheduled code:\n" << sched.codegen()
<< "-------------------------------------" << endl;
/*
Before Transformation:
Schedule state:
Domains:
[N] -> {statement_0[idx_0] : 1 <= idx_0 <= N}
[N] -> {statement_1[idx_0] : 1+9 <= idx_0 <= N+9}
Transformations:
{statement_0[idx_0] -> [0,idx_0,0]; statement_1[idx_0] -> [1,idx_0,0]; }
Default scheduled code:
{
for (int c1 = 1; c1 <= N; c1 += 1)
statement_0(c1);
for (int c1 = 10; c1 <= N + 9; c1 += 1)
statement_1(c1);
}
*/

// Let's shift and fuse our loops.
vector<Transformation*> transformations;
// Create our shift transformation
{
// We are shifting the second loop backwards by 9
// could also shift the first loop forwards by 9
ShiftTransformation* transformation = new ShiftTransformation(1, "-9");
transformations.push_back( transformation );
}
{
// Fuse our two loops
vector<LoopChain::size_type> fuse_these;
fuse_these.push_back( (LoopChain::size_type) 0 );
fuse_these.push_back( (LoopChain::size_type) 1 );
FusionTransformation* transformation = new FusionTransformation( fuse_these );
transformations.push_back( transformation );
}

// Apply the transformations
sched.apply( transformations );

// Print everything
cout << "After Shift Transformation:\n"
<< "Schedule state:\n" << sched
<< "\nTransformed code:\n" << sched.codegen()
<< endl;

/*
After Shift Transformation:
Schedule state:
Domains:
[N] -> {statement_0[idx_0] : 1 <= idx_0 <= N}
[N] -> {statement_1[idx_0] : 1+9 <= idx_0 <= N+9}
Transformations:
{statement_0[idx_0] -> [0,idx_0,0]; statement_1[idx_0] -> [1,idx_0,0]; }
{
[t,i0,i1]->[t,i0+(-9),i1] : (t = 1);
[t,i0,i1]->[t,i0,i1] : (t != 1);
}
{
[f,i1,i2] -> [t,i1,f] : ( t = 0 ) and (f = 0 or f = 1);
[f,i1,i2] -> [f,i1,i2] : !(f = 0 or f = 1)
};
Transformed code:
for (int c1 = 1; c1 <= N; c1 += 1) {
statement_0(c1);
statement_1(c1 + 9);
}
You can see that our two loop statements are now within a single loop over
the domain {1..N};
*/
}
}

0 comments on commit f0f9474

Please sign in to comment.