def test_alloc_in_loop(self): a, tmp, b = [ te.BufHandle(name, [1], torch.float32) for name in ["a", "tmp", "b"] ] body = te.Block([tmp.store([0], a.load([0])), b.store([0], tmp.load([0]))]) for _ in range(4): i = te.VarHandle("i", torch.int32) body = te.For.make(i, 0, 100, body) nest = te.LoopNest(body, [b]) nest.prepare_for_codegen() f = te.construct_codegen("llvm", nest.simplify(), [a, b]) ta, tb = [torch.ones(1) for _ in range(2)] f.call([ta.data_ptr(), tb.data_ptr()])
def test_alloc_in_loop(self): a, tmp, b = [ te.Placeholder(name, te.Dtype.Float, [te.ExprHandle.int(1)]) for name in ["a", "tmp", "b"] ] t0, t100 = [te.ExprHandle.int(n) for n in [0, 100]] body = te.Block( [tmp.store([t0], a.load([t0])), b.store([t0], tmp.load([t0]))]) for _ in range(4): i = te.VarHandle("i", te.Dtype.Int) body = te.For.make(i, t0, t100, body) nest = te.LoopNest(body, [b.data()]) nest.prepare_for_codegen() f = te.construct_codegen("llvm", nest.simplify(), [a, b]) ta, tb = [torch.ones(1) for _ in range(2)] f.call([ta.data_ptr(), tb.data_ptr()])