def transform(self): """To perform loop tiling""" # parse the text in the annotation orio.module.body to extract the tiling information tiling_params = ann_parser.AnnParser(self.perf_params).parse(self.module_body_code) # parse the code (in the annotation body) to extract the corresponding AST stmts = code_parser.getParser().parse(self.annot_body_code) # check and enforce the AST semantics stmts = semant.SemanticChecker().check(stmts) # perform loop-tiling transformation (stmts, int_vars) = transformation.Transformation(tiling_params).transform(stmts) # generate the tiled code code = self.__generate(stmts, int_vars) # return the tiled code return code
def transform(self): '''To apply loop tiling on the annotated code''' # parse the text in the annotation orio.module.body to extract tiling information tiling_info = ann_parser.AnnParser(self.perf_params).parse(self.module_body_code) # parse the code (in the annotation body) to extract the corresponding AST stmts = code_parser.getParser().parse(self.annot_body_code) # analyze the AST semantics stmts = semant.SemanticAnalyzer(tiling_info).analyze(stmts) # perform loop-tiling transformation t = transformation.Transformation(tiling_info) (stmts, int_vars) = t.transform(stmts) # generate the tiled code code = self.__generateCode(stmts, int_vars) # return the tiled code return code
def transform(self): '''To perform loop tiling''' # parse the text in the annotation orio.module.body to extract the tiling information tiling_params = ann_parser.AnnParser(self.perf_params).parse( self.module_body_code) # parse the code (in the annotation body) to extract the corresponding AST stmts = code_parser.getParser().parse(self.annot_body_code) # check and enforce the AST semantics stmts = semant.SemanticChecker().check(stmts) # perform loop-tiling transformation (stmts, int_vars ) = transformation.Transformation(tiling_params).transform(stmts) # generate the tiled code code = self.__generate(stmts, int_vars) # return the tiled code return code
def transform(self): """To apply loop tiling on the annotated code""" # parse the text in the annotation orio.module.body to extract variable value pairs var_val_pairs = ann_parser.AnnParser(self.perf_params).parse( self.module_body_code ) # filter out some variables used for turning on/off the optimizations unroll = 1 vectorize = 1 scalar_replacement = 1 constant_folding = 1 tile_sizes = [] for var, val in var_val_pairs: if var == "unroll": unroll = val elif var == "vectorize": vectorize = val elif var == "scalar_replacement": scalar_replacement = val elif var == "constant_folding": constant_folding = val else: tile_sizes.append((var, val)) # remove all annotations from the annotation body text ann_re = r"/\*@\s*(.|\n)*?\s*@\*/" code = re.sub(ann_re, "", self.annot_body_code) # extract code regions that cover the full core tiles code_regions = self.__extractCoreTiles(code, tile_sizes) # parse the full core-tile code and generate a corresponding AST n_code_regions = [] for cr in code_regions: if isinstance(cr, str): n_code_regions.append(cr) continue i, v, c = cr stmts = code_parser.getParser().parse(c) if len(stmts) != 1 or not isinstance(stmts[0], ast.ForStmt): err("orio.module.ortildriver.ortildriver: invalid full core-tile code") n_code_regions.append((i, v, stmts[0])) code_regions = n_code_regions # transform the full core-tile code transformed_code = "" for cr in code_regions: if isinstance(cr, str): transformed_code += cr continue i, v, s = cr t = transformation.Transformation( unroll, vectorize, scalar_replacement, constant_folding ) transformed_code += t.transform(i, v, s) # insert the declaration code for the tile sizes decl_code = "" for i, (tvar, tval) in enumerate(tile_sizes): decl_code += " %s = %s;\n" % (tvar, tval) if transformed_code[0] != "\n": transformed_code = "\n" + transformed_code transformed_code = "\n" + decl_code + transformed_code # return the transformed code return transformed_code
def transform(self): '''To apply loop tiling on the annotated code''' # parse the text in the annotation orio.module.body to extract variable value pairs var_val_pairs = ann_parser.AnnParser(self.perf_params).parse(self.module_body_code) # filter out some variables used for turning on/off the optimizations unroll = 1 vectorize = 1 scalar_replacement = 1 constant_folding = 1 tile_sizes = [] for var,val in var_val_pairs: if var == 'unroll': unroll = val elif var == 'vectorize': vectorize = val elif var == 'scalar_replacement': scalar_replacement = val elif var == 'constant_folding': constant_folding = val else: tile_sizes.append((var, val)) # remove all annotations from the annotation body text ann_re = r'/\*@\s*(.|\n)*?\s*@\*/' code = re.sub(ann_re, '', self.annot_body_code) # extract code regions that cover the full core tiles code_regions = self.__extractCoreTiles(code, tile_sizes) # parse the full core-tile code and generate a corresponding AST n_code_regions = [] for cr in code_regions: if isinstance(cr, str): n_code_regions.append(cr) continue i,v,c = cr stmts = code_parser.getParser().parse(c) if len(stmts) != 1 or not isinstance(stmts[0], ast.ForStmt): err('orio.module.ortildriver.ortildriver: invalid full core-tile code') n_code_regions.append((i,v,stmts[0])) code_regions = n_code_regions # transform the full core-tile code transformed_code = '' for cr in code_regions: if isinstance(cr, str): transformed_code += cr continue i,v,s = cr t = transformation.Transformation(unroll, vectorize, scalar_replacement, constant_folding) transformed_code += t.transform(i,v,s) # insert the declaration code for the tile sizes decl_code = '' for i, (tvar, tval) in enumerate(tile_sizes): decl_code += ' %s = %s;\n' % (tvar, tval) if transformed_code[0] != '\n': transformed_code = '\n' + transformed_code transformed_code = '\n' + decl_code + transformed_code # return the transformed code return transformed_code