def calc_update_access_relations(mapir): iegen.print_progress('Updating access relations...') #Update each access relation's iteration to data relation to # match its statement's scattering function for statement in mapir.get_statements(): for access_relation in statement.get_access_relations(): iegen.print_detail("Updating iter_to_data of access relation '%s'..."%(access_relation.name)) before=str(access_relation.iter_to_data) #Compose the access relation to be in terms of the statement's scattering function access_relation.iter_to_data=access_relation.iter_to_data.compose(statement.scatter.inverse()) iegen.print_modified("Updated iter_to_data of access relation '%s': %s -> %s"%(access_relation.name,before,access_relation.iter_to_data))
def calc_unupdate_access_relations(mapir,full_to_iter): from iegen import Relation iegen.print_progress('Un-updating access relations...') #Update each access relation's iteration to data relation to # match its statement's iteration space for statement in mapir.get_statements(): for access_relation in statement.get_access_relations(): iegen.print_detail("Un-updating iter_to_data of access relation '%s'..."%(access_relation.name)) before=str(access_relation.iter_to_data) #Compose the access relation to be in terms of the statement's iteration space access_relation.iter_to_data=full_to_iter[statement.name].compose(access_relation.iter_to_data.inverse()).inverse() iegen.print_modified("Un-updated iter_to_data of access relation '%s': %s -> %s"%(access_relation.name,before,access_relation.iter_to_data))
def do_calc(mapir): from iegen.codegen import calc_initial_idg,calc_full_iter_space,calc_update_access_relations,calc_unupdate_access_relations iegen.print_progress('Starting calculation phase...') #Update iteration spaces and access relations before we start calculations calc_update(mapir) #Calculate the initial IDG calc_initial_idg(mapir) iegen.print_progress('Calculating full iteration space...') #Calculate the full iteration space based on the current iteration spaces of the statements mapir.full_iter_space=calc_full_iter_space(mapir.get_statements()) iegen.print_detail('----- Current full iteration space: -----') iegen.print_detail(mapir.full_iter_space) iegen.print_detail('-----------------------------------------') #Do calculations for each reordering for transformation in mapir.transformations: iegen.print_progress("Applying transformation '%s'..."%(transformation.name)) iegen.print_detail('----- Transformation: -----') iegen.print_detail(transformation) iegen.print_detail('------------------------------------') #Determine if the current transformation is a transformation or an ITO is_transformation=False is_ito=False #Assume the current transformation is a transformation, not an ITO try: #Ensure the transformation has the four expected methods calc_input=transformation.calc_input calc_output=transformation.calc_output update_mapir=transformation.update_mapir update_idg=transformation.update_idg is_transformation=True except AttributeError as e1: #Try the current transformation as an ITO try: #Ensure the ito has the single 'apply' method apply=transformation.apply is_ito=True except AttributeError as e2: pass if is_transformation: iegen.print_progress('Calculating inputs to transformation...') #Tell the transformation to calculate the inputs that it will need at runtime transformation.calc_input(mapir) iegen.print_progress('Calculating outputs from transformation...') #Tell the transformation to calculate the outputs it will produce at runtime transformation.calc_output(mapir) iegen.print_progress('Updating the MapIR...') #Tell the transformation to update the access relations, scattering functions and other components of the MapIR transformation.update_mapir(mapir) iegen.print_progress('Updating the IDG...') #Tell the transformation to update the IDG transformation.update_idg(mapir) elif is_ito: iegen.print_progress("Applying intertransopt '%s'..."%(transformation.name)) iegen.print_detail('----- InterTransOpt: -----') iegen.print_detail(transformation) iegen.print_detail('------------------------------------') transformation.apply(mapir) else: raise ValueError("Current transformation '%s' is neither a transformation nor an ITO"%(transformation.name)) #Calculate IDG dependences calc_idg_deps(mapir) iegen.print_modified("----- Updated statements (after transformation '%s'): -----"%(transformation.name)) for statement in mapir.get_statements(): iegen.print_modified(statement) iegen.print_modified("\n") iegen.print_modified('-----------------------------------------') iegen.print_progress('Calculating full iteration space...') #Calculate the full iteration space based on the current iteration spaces of the statements mapir.full_iter_space=calc_full_iter_space(mapir.get_statements()) iegen.print_detail('----- Current full iteration space: -----') iegen.print_detail(mapir.full_iter_space) iegen.print_detail('-----------------------------------------') #Un-update iteration spaces and access relations now that the calculation phase is over calc_unupdate(mapir) from iegen.idg.visitor import DotVisitor v=DotVisitor().visit(mapir.idg) v.write_dot('test.dot') iegen.print_progress('Calculation phase completed...')