halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.86k stars 1.07k forks source link

Error: Can't index into a reference to Func because it does not return a Tuple #8299

Open jansel opened 3 months ago

jansel commented 3 months ago
import halide as hl

@hl.generator(name="kernel")
class Kernel:
    in_ptr0 = hl.InputBuffer(hl.Float(32), 1)
    out_ptr0 = hl.OutputBuffer(hl.Float(32), 1)

    def generate(g):
        in_ptr0 = g.in_ptr0
        out_ptr0 = g.out_ptr0
        h0 = hl.Var("h0")
        tmp12 = hl.Func("tmp12")
        tmp12[h0] = 0
        out_ptr0[h0] = in_ptr0[tmp12[h0]]

target = hl.Target("host")
with hl.GeneratorContext(target):
    Kernel().compile_to_callable()

Output

Traceback (most recent call last):
  File "/home/jansel/pytorch/repro.py", line 19, in <module>
    Kernel().compile_to_callable()
  File "/home/jansel/conda/envs/pytorch/lib/python3.10/site-packages/halide/_generator_helpers.py", line 449, in compile_to_callable
    pipeline = self._build_pipeline()
  File "/home/jansel/conda/envs/pytorch/lib/python3.10/site-packages/halide/_generator_helpers.py", line 707, in _build_pipeline
    self.generate()
  File "/home/jansel/pytorch/repro.py", line 14, in generate
    out_ptr0[h0] = in_ptr0[tmp12[h0]]
halide.halide_.HalideError: Error: Can't index into a reference to Func "tmp12", because it does not return a Tuple.

You can workaround with the following change:

diff --git a/repro.py b/repro.py
index a306f11da22..76d44699bdb 100644
--- a/repro.py
+++ b/repro.py
@@ -12,7 +12,7 @@ class Kernel:
         h0 = hl.Var("h0")
         tmp12 = hl.Func("tmp12")
         tmp12[h0] = 0
-        out_ptr0[h0] = in_ptr0[tmp12[h0]]
+        out_ptr0[h0] = in_ptr0[tmp12[h0] + 0]

 target = hl.Target("host")

It is a pretty easy workaround to generate, but seems like a bug.