Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jansel opened this issue Jun 18, 2024 · 0 comments
Labels
bug python Issues related to Halide/Python interop

Comments

@jansel
Copy link
Contributor

jansel commented Jun 18, 2024

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.

@jansel jansel changed the title Error: Can't index into a reference to Func "tmp12", because it does not return a Tuple Error: Can't index into a reference to Func because it does not return a Tuple Jun 18, 2024
@abadams abadams added bug python Issues related to Halide/Python interop labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug python Issues related to Halide/Python interop
Projects
None yet
Development

No branches or pull requests

2 participants