def random_schedule(root_func, min_depth=0, max_depth=DEFAULT_MAX_DEPTH, vars=None): """ Generate Schedule for all functions called by root_func (recursively). Same arguments as schedules_func(). """ if vars is None: vars = halide.func_varlist(root_func) d_new_vars = {} schedule = {} def callback(f, parent): extra_caller_vars = d_new_vars.get( parent.name() if parent is not None else None, []) # print 'schedule', f.name(), extra_caller_vars # ans = schedules_func(root_func, f, min_depth, max_depth, random=True, extra_caller_vars=extra_caller_vars, vars=vars).next() max_depth_sel = max_depth if f.name() != 'f' else 0 ans = schedules_func(root_func, f, min_depth, max_depth_sel, random=True, extra_caller_vars=extra_caller_vars).next() d_new_vars[f.name()] = ans.new_vars() schedule[f.name()] = ans halide.visit_funcs(root_func, callback) return Schedule(root_func, schedule)
def fromstring(root_func, s, genomelog='', generation=-1, index=-1): """ Constructor from a string s such as 'f.root().parallel(y)\ng.chunk(y)' (same format as returned by str() method). """ if '\\n' in s: raise ValueError('Bad newline character in %r'%s) #print 'Schedule.fromstring', root_func, s all_funcs = halide.all_funcs(root_func) root_func = root_func #print 'Schedule.fromstring', repr(s) #print s.strip().split('\n') #sys.exit(1) d = {} for line in s.strip().split('\n'): line = line.strip() if len(line) == 0: continue if not '.' in line: raise ValueError(s) dot = line.index('.') name = line[:dot] d[name] = FragmentList.fromstring(all_funcs[name], line) ans = {} def callback(f, parent): name = f.name() if name not in d: ans[name] = FragmentList.fromstring(f, '') else: ans[name] = d[name] halide.visit_funcs(root_func, callback) return Schedule(root_func, ans, genomelog, generation, index)
def fromstring(root_func, s, genomelog='', generation=-1, index=-1): """ Constructor from a string s such as 'f.root().parallel(y)\ng.chunk(y)' (same format as returned by str() method). """ if '\\n' in s: raise ValueError('Bad newline character in %r' % s) #print 'Schedule.fromstring', root_func, s all_funcs = halide.all_funcs(root_func) root_func = root_func #print 'Schedule.fromstring', repr(s) #print s.strip().split('\n') #sys.exit(1) d = {} for line in s.strip().split('\n'): line = line.strip() if len(line) == 0: continue if not '.' in line: raise ValueError(s) dot = line.index('.') name = line[:dot] d[name] = FragmentList.fromstring(all_funcs[name], line) ans = {} def callback(f, parent): name = f.name() if name not in d: ans[name] = FragmentList.fromstring(f, '') else: ans[name] = d[name] halide.visit_funcs(root_func, callback) return Schedule(root_func, ans, genomelog, generation, index)
def random_schedule(root_func, min_depth=0, max_depth=DEFAULT_MAX_DEPTH, vars=None): """ Generate Schedule for all functions called by root_func (recursively). Same arguments as schedules_func(). """ if vars is None: vars = halide.func_varlist(root_func) d_new_vars = {} schedule = {} def callback(f, parent): extra_caller_vars = d_new_vars.get(parent.name() if parent is not None else None,[]) # print 'schedule', f.name(), extra_caller_vars # ans = schedules_func(root_func, f, min_depth, max_depth, random=True, extra_caller_vars=extra_caller_vars, vars=vars).next() max_depth_sel = max_depth if f.name() != 'f' else 0 ans = schedules_func(root_func, f, min_depth, max_depth_sel, random=True, extra_caller_vars=extra_caller_vars).next() d_new_vars[f.name()] = ans.new_vars() schedule[f.name()] = ans halide.visit_funcs(root_func, callback) return Schedule(root_func, schedule)
def apply(self): # Apply schedule #print 'apply schedule:' #print str(self) halide.inline_all(self.root_func) scope = halide.all_vars(self.root_func) #print 'scope', scope.keys() new_vars = self.new_vars() #print 'new_vars', new_vars for varname in new_vars: scope[varname] = instantiate_var(varname) print 'scope:', scope def callback(f, parent): name = f.name() if name in self.d: s = str(self.d[name]) s = s.replace(name + '.', '__func.') scope['__func'] = f exec s in scope halide.visit_funcs(self.root_func, callback)
def apply(self, constraints, verbose=False): # Apply schedule #verbose = True #print 'apply schedule:' #print str(self) #halide.inline_all(self.root_func) scope = halide.all_vars(self.root_func) #print 'scope', scope.keys() new_vars = self.new_vars() if verbose: print 'apply, new_vars', new_vars for varname in new_vars: scope[varname] = instantiate_var(varname) if verbose: print 'apply, scope:', scope def callback(f, parent): name = f.name() if verbose: print 'apply, name', name, constraints if name in constraints.exclude_names: if verbose: print ' constrained, skipping' return if name in self.d: s = str(self.d[name]) f.reset() s = s.replace(name + '.', '__func.') scope['__func'] = f #print 'apply', s #print scope, s if verbose: print ' exec', s exec s in scope else: if verbose: print ' not in d, reset' f.reset() halide.visit_funcs(self.root_func, callback)