cornell-zhang/heterocl

[Tensor] Cannot access attribute if type is not struct

Closed this issue · 17 comments

Error message

riginal exception was:
Traceback (most recent call last):
File "codegens/codegen_adi.py", line 56, in
mu2, a, b, c, d, e, f, dtype, target=target)
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line 58, in top_adi
s = hcl.create_schedule([u, v, p, q], kernel_adi)
File "/scratch/users/dp638/Work/heterocl_pocc/python/heterocl/api.py", line 210, in create_schedule
ret = func(*inputs) File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line 56, in kernel_adi
hcl.mutate((NT,), lambda m: sweep(u, v, p, q), "main_loop")
File "/scratch/users/dp638/Work/heterocl_pocc/python/heterocl/compute_api.py", line 433, in mutate
fcompute(*var_list)
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line 56, in
hcl.mutate((NT,), lambda m: sweep(u, v, p, q), "main_loop")
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line 38, in sweep
p[i][j] = c / (p[i][j - 1])
File "/scratch/users/dp638/Work/heterocl_pocc/python/heterocl/tensor.py", line 184, in getattr
"Cannot access attribute if type is not struct")
heterocl.debug.TensorError: [Tensor] Cannot access attribute if type is not struct

How to reproduce

git clone https://github.com/cornell-zhang/poly-heterocl.git -b mpr-feb2021
cd poly-heterocl/polybench_fpga
python codegens/codegen_adi.py -S MINI -D Float -B adi -T merlinc

Location of necessary artifacts

Source code: stencils/adi
Codegen: codegens

Observation

If I remove the a , b, and c in line 37, the code works. By default a, b, and c are of NumPy Float data type coming from the codegens/codegen_adi.py . All parameters are defined in stencils/adi/config.py.

HeteroCL commit used

commit c51ac66

It seems the Github file does not match the error message. Am I referring to the wrong file?

Interesting. I double-checked, And that's the file I am trying to compile with that commit of HCL.

I mean it doesn't match with the error message you paste. If you look at line 38, there is no p[i][j] = c / (p[i][j - 1]).

Oh I see. The actual line is the code that you see in the file. I removed everything but c and still error happened (Was trying to narrow down the cause). You are seeing the line with c only in the error message because I generated the error message with that modified line of p[i][j] = c / (p[i][j - 1]). When you remove all the a, b, and c the code runs.

I believe the problem is you cannot directly operate numpy numbers with HeteroCL expressions.

You should convert them to Python numbers first. I guess that should solve the problem.

But then the Python float is 64 bits. It used to cause result mismatch.

What do you mean? I believe there exist NumPy methods that can transform NumPy numbers to Python numbers without losing accuracy.

Ok. I shall double-check and update here. I think you are referring to .item() method in NumPy.

In the worst case you can wrap them with HeteroCL empty placeholders, i.e., a = placeholder(()).

Seems like .item() worked. Thanks!

But is there a way we can add a more informative error message?

Another solution is to switch numpy numbers to the RHS. If the numpy number is in the LHS, Python will be using its operator (e.g., +, -, *, /).

@paldebjit please try #343 and let me know if that works. Thanks.

@paldebjit any update?

No. I was busy with something else. I will update you in another 1-2 days. I have come back to this one today!

ok, thanks.

Generating code for the non-optimized kernel...
File "codegens/codegen_adi.py", line 56, in
mu2, a, b, c, d, e, f, dtype, target=target)
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line
57, in top_adi
s = hcl.create_schedule([u, v, p, q], kernel_adi)
File "/home/dp638/.local/lib/python3.7/site-packages/heterocl-0.3-py3.7.egg/heterocl/api.py
", line 207, in create_schedule
ret = func(*inputs)
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line
55, in kernel_adi
hcl.mutate((NT,), lambda m: sweep(u, v, p, q), "main_loop")
File "/home/dp638/.local/lib/python3.7/site-packages/heterocl-0.3-py3.7.egg/heterocl/comput
e_api.py", line 386, in mutate
fcompute(*var_list)
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line
55, in
hcl.mutate((NT,), lambda m: sweep(u, v, p, q), "main_loop")
File "/scratch/users/dp638/Work/PolyHCL/examples/polybench_fpga/stencils/adi/adi.py", line
38, in sweep
q[i][j] = (-1.0 * d * u[j][i - 1] + (1.0 + 2.0 * d) * u[j][i] - f * u[j][i + 1] - a * q[i
][j - 1])/(a * p[i][j - 1] + b)
File "/home/dp638/.local/lib/python3.7/site-packages/heterocl-0.3-py3.7.egg/heterocl/tensor
.py", line 183, in getattr
"Cannot use NumPy numbers as left-hand-side operand")
[HeteroCL Error][API] Cannot use NumPy numbers as left-hand-side operand

I get this error message and the last line is color-coded. This is much helpful. Thanks, @seanlatias for this. I will be closing issue now.