Skip to content

Commit

Permalink
Merge branch 'master' into autoconf
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-bertolacci committed Jun 13, 2017
2 parents 380bdb5 + f818fd4 commit 272155c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 67 deletions.
34 changes: 6 additions & 28 deletions HowToLoopChainIR/src/ShiftTransformationHowTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,11 @@ int main(){
*/
vector<string> extents;
extents.push_back("10");
extents.push_back("K");
extents.push_back("5");
extents.push_back("0");

// Because we have a symbolic, we also need to create a symbolics vector.
vector<string> symbols;
symbols.push_back("K");


// Create the transformation
ShiftTransformation transformation(1, extents, symbols);
ShiftTransformation transformation(1, extents );
transformations.push_back( &transformation );

// Apply the transformations
Expand Down Expand Up @@ -260,33 +255,16 @@ int main(){
// Lets create a dummy transformation that won't be applied to a schedule.
vector<string> extents;
extents.push_back("11");
extents.push_back("1+K*K");

vector<string> symbols;
symbols.push_back("K");
extents.push_back("12");

// Create the transformation
ShiftTransformation transformation(1, extents, symbols);
ShiftTransformation transformation(1, extents );

// We can get the id of the loop we will be transforming using getLoopId()
cout << "Loop id: " << transformation.getLoopId() << endl;
// We can get the extents as a vector using getExtents()
vector<string> gotExtents = transformation.getExtents();

cout << "Extents: ";
for( vector<string>::iterator it = gotExtents.begin(); it != gotExtents.end(); it++ ){
cout << "(" << *it << ") ";
}
cout << endl;

// We can get the symbols as a vector using getSymbols()
vector<string> gotSymbols = transformation.getSymbols();

cout << "Symbols: ";
for( vector<string>::iterator it = gotSymbols.begin(); it != gotSymbols.end(); it++ ){
cout << "\"" << *it << "\" ";
}
cout << endl;
Tuple gotExtents = transformation.getExtents();
cout << "Extents: " << gotExtents << endl;

}

Expand Down
46 changes: 33 additions & 13 deletions include/LoopChainIR/Subspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ namespace LoopChainIR {
/*! \brief Returns the stage assigned to this Subspace. */
timestamp_t get_stage() const;
/*! \brief Returns a string of the iterators at or before the specified stage, with option to use aliases. */
std::string get_iterators( timestamp_t stage, bool use_aliases );
std::string get_iterators( timestamp_t stage, bool use_aliases ) const;

/*! \brief Returns the index'th iterator, with option to use aliases. */
std::string get( size_type index, bool use_aliases );
std::string get( size_type index, bool use_aliases ) const;

/*! \brief Returns the index'th iterator, respecting alias state. */
std::string operator[]( size_type index );
std::string operator[]( size_type index ) const;
/*! \brief Returns true if the subspaces have the same iterators. Aliasing and stage not considered. */
bool operator==( const Subspace that ) const;
/*! \brief Returns true if the subspaces do not have the same iterators. Aliasing and stage not considered. */
Expand Down Expand Up @@ -159,6 +159,7 @@ namespace LoopChainIR {
public:
typedef std::vector<Subspace*> Container;
typedef Container::iterator iterator;
typedef Container::const_iterator const_iterator;

protected:
typedef std::insert_iterator<Container> insert_iterator;
Expand All @@ -179,43 +180,62 @@ namespace LoopChainIR {
iterator begin();
/*! \brief Returns an iterator to the end of the Subspaces. */
iterator end();

/*! \brief Returns an iterator to the first Subspace, with option to use aliases. */
const_iterator begin( bool use_aliases ) const;
/*! \brief Returns an iterator to the first Subspace, respecting alias state of Subspaces */
const_iterator begin() const;
/*! \brief Returns an iterator to the end of the Subspaces. */
const_iterator end() const;

/*! \brief Returns an itreator referencing the loops Subspace (typically [loops_c]). */
iterator get_iterator_to_loops()
iterator get_iterator_to_loops();
/*! \brief Returns an itreator referencing the nests Subspace (typically [i_0,i_1,...m,i_c]). */;
iterator get_iterator_to_nest();
/*! \brief Given a pointer to a Subspace this SubspaceManager manages, returns an iterator to it. */
iterator get_iterator_to_subspace( Subspace* subspace );
iterator get_iterator_to_subspace( const Subspace* subspace );
/*! \brief Returns a pointer to the loops Subspace. */
Subspace* get_loops();
/*! \brief Returns a pointer to the nests Subspace. */
Subspace* get_nest();

/*! \brief Returns an itreator referencing the loops Subspace (typically [loops_c]). */
const_iterator get_iterator_to_loops() const;
/*! \brief Returns an itreator referencing the nests Subspace (typically [i_0,i_1,...m,i_c]). */;
const_iterator get_iterator_to_nest() const;
/*! \brief Given a pointer to a Subspace this SubspaceManager manages, returns an iterator to it. */
const_iterator get_iterator_to_subspace( const Subspace* subspace ) const;
/*! \brief Returns a pointer to the loops Subspace. */
const Subspace* get_loops() const;
/*! \brief Returns a pointer to the nests Subspace. */
const Subspace* get_nest() const;

std::string get_safe_prefix( std::string basic );

iterator insert_left( Subspace* subpsace, iterator cursor );
iterator insert_right( Subspace* subpsace, iterator cursor );

Subspace::size_type size();
Subspace::size_type size() const;

/*! \brief Returns the current stage. */
timestamp_t get_current_stage();
timestamp_t get_current_stage() const;
/*! \brief Returns the stage that forms the input iteration space of a function created at this stage. */
timestamp_t get_input_stage();
timestamp_t get_input_stage() const;
/*! \brief Returns the stage that forms the output iteration space of a function created at this stage. */
timestamp_t get_output_stage();
timestamp_t get_output_stage() const;
/*! \brief Advances the curent stage forward by one. */
timestamp_t advance_stage();
/*! \brief Advances stage, and unsets alias for all managed subspaces. */
timestamp_t next_stage();

/*! \brief Returns string of iterators for this stage, with option to use aliases. */
std::string get_iterators( timestamp_t stage, bool use_aliases );
std::string get_iterators( timestamp_t stage, bool use_aliases ) const;
/*! \brief Returns string of iterators for the current stage, respecting all Subspaces alias state. */
std::string get_iterators( );
std::string get_iterators( ) const;
/*! \brief Returns string of iterators that forms the input iteration space of a function created at this stage, not respecting any Subspaces alias state. */
std::string get_input_iterators();
std::string get_input_iterators() const;
/*! \brief Returns string of iterators that forms the output iteration space of a function created at this stage, respecting all Subspaces alias state. */
std::string get_output_iterators();
std::string get_output_iterators() const;
};
}
#endif
21 changes: 12 additions & 9 deletions src/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,16 @@ IslAstRoot* Schedule::codegenToIslAst(){
isl_ast_build* build = isl_ast_build_alloc(ctx);
build = isl_ast_build_set_options( build, separate_map );

// Create iterator names by the thousands
int dims = 100;
isl_id_list* names = isl_id_list_alloc( ctx, dims );
for( int d = 0; d < dims; ++d ){
isl_id* id = isl_id_alloc( ctx, (this->getIteratorPrefix() + to_string(d)).c_str(), NULL );
names = isl_id_list_add( names, id );
// Create hundreds of iterator names
{
int dims = 100;
isl_id_list* names = isl_id_list_alloc( ctx, dims );
for( int d = 0; d < dims; ++d ){
isl_id* id = isl_id_alloc( ctx, (this->getIteratorPrefix() + to_string(d)).c_str(), NULL );
names = isl_id_list_add( names, id );
}
build = isl_ast_build_set_iterators( build, names );
}
build = isl_ast_build_set_iterators( build, names );


isl_ast_node* tree = isl_ast_build_node_from_schedule_map( build, schedule_map );

Expand Down Expand Up @@ -312,7 +313,9 @@ std::string Schedule::codegenToISCC( ) const {
for( int i = 1; i < stmt_count; i += 1 ){
os << ((i>1)?"+":"") << "S" << i;
}
os << ") );";
const Subspace* nest = manager.get_nest();;
os << ") ) using { [" << manager.get_input_iterators() << "] -> "
<< "separate[" << nest->get( nest->size() , false ) << "] };";
return std::string( os.str() );
}

Expand Down
69 changes: 52 additions & 17 deletions src/Subspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ timestamp_t Subspace::get_stage() const {
return this->stage;
}

std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ){
std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ) const {
ostringstream stream;

if( this->get_stage() <= stage ){
bool not_first = false;
for( Subspace::iterator iter = this->begin( use_aliases ); iter != this->end(); ++iter ){
for( Subspace::const_iterator iter = this->begin( use_aliases ); iter != this->end(); ++iter ){
stream << (not_first?",":"") << *iter ;
not_first = true;
}
Expand All @@ -117,7 +117,7 @@ std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ){
return stream.str();
}

std::string Subspace::get( Subspace::size_type index, bool use_aliases ){
std::string Subspace::get( Subspace::size_type index, bool use_aliases ) const {
if( this->is_aliased() && use_aliases ){
return SSTR( alias_prefix << this->all_iterators[index] );
} else {
Expand All @@ -126,7 +126,7 @@ std::string Subspace::get( Subspace::size_type index, bool use_aliases ){
}


std::string Subspace::operator[]( size_type index ){
std::string Subspace::operator[]( size_type index ) const {
return this->get( index, this->is_aliased() );
}

Expand Down Expand Up @@ -241,7 +241,15 @@ SubspaceManager::iterator SubspaceManager::end(){
return this->subspaces.end();
}

SubspaceManager::iterator SubspaceManager::get_iterator_to_subspace( Subspace* subspace ){
SubspaceManager::const_iterator SubspaceManager::begin() const {
return this->subspaces.begin();
}

SubspaceManager::const_iterator SubspaceManager::end() const {
return this->subspaces.end();
}

SubspaceManager::iterator SubspaceManager::get_iterator_to_subspace( const Subspace* subspace ){
SubspaceManager::iterator iter = this->subspaces.begin();
while( iter != this->subspaces.end() && *iter != subspace ){
++iter;
Expand All @@ -265,6 +273,32 @@ Subspace* SubspaceManager::get_nest(){
return *( this->get_iterator_to_nest() );
}


SubspaceManager::const_iterator SubspaceManager::get_iterator_to_subspace( const Subspace* subspace ) const {
SubspaceManager::const_iterator iter = this->subspaces.begin();
while( iter != this->subspaces.end() && *iter != subspace ){
++iter;
}
return iter;
}

SubspaceManager::const_iterator SubspaceManager::get_iterator_to_loops() const {
return this->get_iterator_to_subspace( this->loop );
}

SubspaceManager::const_iterator SubspaceManager::get_iterator_to_nest() const {
return this->get_iterator_to_subspace( this->nest );
}

const Subspace* SubspaceManager::get_loops() const {
return *( this->get_iterator_to_loops() );
}

const Subspace* SubspaceManager::get_nest() const {
return *( this->get_iterator_to_nest() );
}


std::string SubspaceManager::get_safe_prefix( std::string base ){
if( this->safe_prefixes.count( base ) == 0 ){
this->safe_prefixes[base] = 1;
Expand All @@ -289,23 +323,23 @@ SubspaceManager::iterator SubspaceManager::insert_right( Subspace* subspace, Sub
return this->insert_left( subspace, std::next(cursor) );
}

Subspace::size_type SubspaceManager::size(){
Subspace::size_type SubspaceManager::size() const {
Subspace::size_type size = 0;
for( Subspace* subspace : *this ){
size += subspace->complete_size();
for( SubspaceManager::const_iterator it = this->begin(); it != this->end(); ++it ){
size += (*it)->complete_size();
}
return size;
}

timestamp_t SubspaceManager::get_current_stage(){
timestamp_t SubspaceManager::get_current_stage() const {
return this->stage;
}

timestamp_t SubspaceManager::get_input_stage(){
timestamp_t SubspaceManager::get_input_stage() const {
return this->get_current_stage();
}

timestamp_t SubspaceManager::get_output_stage() {
timestamp_t SubspaceManager::get_output_stage() const {
return this->get_input_stage() + 1;
}

Expand All @@ -321,12 +355,13 @@ timestamp_t SubspaceManager::next_stage(){
return this->advance_stage();
}

std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases ){
std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases ) const {
ostringstream stream;

bool not_first = false;
for( Subspace* subspace : *this ){
std::string subspace_str = subspace->get_iterators( stage, use_aliases );
for( SubspaceManager::const_iterator it = this->begin(); it != this->end(); ++it ){
const Subspace* subspace = *it;
std::string subspace_str = subspace->get_iterators( stage, use_aliases );

if( subspace_str != "" ){
stream << (not_first? "," : "") << subspace_str;
Expand All @@ -338,14 +373,14 @@ std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases
return stream.str();
}

std::string SubspaceManager::get_iterators( ){
std::string SubspaceManager::get_iterators( ) const {
return this->get_iterators( this->get_current_stage(), true );
}

std::string SubspaceManager::get_input_iterators(){
std::string SubspaceManager::get_input_iterators() const {
return this->get_iterators( this->get_input_stage(), false );
}

std::string SubspaceManager::get_output_iterators(){
std::string SubspaceManager::get_output_iterators() const {
return this->get_iterators( this->get_output_stage(), true );
}

0 comments on commit 272155c

Please sign in to comment.