Example #1
0
 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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
 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)
Example #5
0
def test_schedules(verbose=False, test_random=False):
    #random_module.seed(int(sys.argv[1]) if len(sys.argv)>1 else 0)
    halide.exit_on_signal()
    f = halide.Func('f')
    x = halide.Var('x')
    y = halide.Var('y')
    c = halide.Var('c')
    g = halide.Func('g')
    v = halide.Var('v')
    input = halide.UniformImage(halide.UInt(16), 3)
    int_t = halide.Int(32)
    f[x, y, c] = input[
        halide.clamp(x, halide.cast(int_t, 0
                                    ), halide.cast(int_t,
                                                   input.width() - 1)),
        halide.clamp(y, halide.cast(int_t, 0
                                    ), halide.cast(int_t,
                                                   input.height() - 1)),
        halide.clamp(c, halide.cast(int_t, 0), halide.cast(int_t, 2))]
    #g[v] = f[v,v]
    g[x, y, c] = f[x, y, c] + 1
    assert sorted(halide.all_vars(g).keys()) == sorted(['x', 'y',
                                                        'c'])  #, 'v'])

    if verbose:
        print halide.func_varlist(f)
        print 'caller_vars(f) =', caller_vars(g, f)
        print 'caller_vars(g) =', caller_vars(g, g)


#    validL = list(valid_schedules(g, f, 4))
#    validL = [repr(_x) for _x in validL]
#
#    for L in sorted(validL):
#        print repr(L)
    T0 = time.time()
    if not test_random:
        random = True  #False
        nvalid_determ = 0
        for L in schedules_func(g, f, 0, 3):
            nvalid_determ += 1
            if verbose:
                print L
        nvalid_random = 0
        for i in range(100):
            for L in schedules_func(
                    g, f, 0, DEFAULT_MAX_DEPTH, random=True
            ):  #sorted([repr(_x) for _x in valid_schedules(g, f, 3)]):
                if verbose and 0:
                    print L  #repr(L)
                nvalid_random += 1
    s = []
    for i in range(400):
        d = random_schedule(g, 0, DEFAULT_MAX_DEPTH)
        si = str(d)
        s.append(si)
        if verbose:
            print 'Schedule:', si

        d.apply()
        evaluate = d.test((36, 36, 3), input)
        print 'evaluate'
        evaluate()
        if test_random:
            print 'Success'
            sys.exit()
    T1 = time.time()

    s = '\n'.join(s)
    assert 'f.chunk(_c0)' in s
    assert 'f.root().vectorize' in s
    assert 'f.root().unroll' in s
    assert 'f.root().split' in s
    assert 'f.root().tile' in s
    assert 'f.root().parallel' in s
    assert 'f.root().transpose' in s

    assert nvalid_random == 100
    if verbose:
        print 'generated in %.3f secs' % (T1 - T0)
    print 'random_schedule: OK'
Example #6
0
def test_schedules(verbose=False, test_random=False):
    #random_module.seed(int(sys.argv[1]) if len(sys.argv)>1 else 0)
    halide.exit_on_signal()
    f = halide.Func('f')
    x = halide.Var('x')
    y = halide.Var('y')
    c = halide.Var('c')
    g = halide.Func('g')
    v = halide.Var('v')
    input = halide.UniformImage(halide.UInt(16), 3)
    int_t = halide.Int(32)
    f[x,y,c] = input[halide.clamp(x,halide.cast(int_t,0),halide.cast(int_t,input.width()-1)),
                     halide.clamp(y,halide.cast(int_t,0),halide.cast(int_t,input.height()-1)),
                     halide.clamp(c,halide.cast(int_t,0),halide.cast(int_t,2))]
    #g[v] = f[v,v]
    g[x,y,c] = f[x,y,c]+1
    assert sorted(halide.all_vars(g).keys()) == sorted(['x', 'y', 'c']) #, 'v'])

    if verbose:
        print halide.func_varlist(f)
        print 'caller_vars(f) =', caller_vars(g, f)
        print 'caller_vars(g) =', caller_vars(g, g)
    
#    validL = list(valid_schedules(g, f, 4))
#    validL = [repr(_x) for _x in validL]
#    
#    for L in sorted(validL):
#        print repr(L)
    T0 = time.time()
    if not test_random:
        random = True #False
        nvalid_determ = 0
        for L in schedules_func(g, f, 0, 3):
            nvalid_determ += 1
            if verbose:
                print L
        nvalid_random = 0
        for i in range(100):
            for L in schedules_func(g, f, 0, DEFAULT_MAX_DEPTH, random=True): #sorted([repr(_x) for _x in valid_schedules(g, f, 3)]):
                if verbose and 0:
                    print L#repr(L)
                nvalid_random += 1
    s = []
    for i in range(400):
        d = random_schedule(g, 0, DEFAULT_MAX_DEPTH)
        si = str(d)
        s.append(si)
        if verbose:
            print 'Schedule:', si

        d.apply()
        evaluate = d.test((36, 36, 3), input)
        print 'evaluate'
        evaluate()
        if test_random:
            print 'Success'
            sys.exit()
    T1 = time.time()
    
    s = '\n'.join(s)
    assert 'f.chunk(_c0)' in s
    assert 'f.root().vectorize' in s
    assert 'f.root().unroll' in s
    assert 'f.root().split' in s
    assert 'f.root().tile' in s
    assert 'f.root().parallel' in s
    assert 'f.root().transpose' in s

    assert nvalid_random == 100
    if verbose:
        print 'generated in %.3f secs' % (T1-T0)
    print 'random_schedule: OK'