-
Notifications
You must be signed in to change notification settings - Fork 16
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
Assign integer expression to struct type scalar #143
Comments
Yes it's related to #133 , general expr to initialize scalar with struct type is WIP |
Segmentation fault is caused by an
|
@jcasas00 What is the expected behavior when we cast |
I suggest we generate an error (not warning) instead. |
I think the most reasonable behavior would be the latter one -- extend the source data to the target type's size and then assign. |
Rethinking this ... as long as an explicit cast works (i.e., hcl.scalar(hcl.cast("int16", ), ...)), then generating an error is fine. This way the cast is forced to be explicit. |
This issue should be fixed by ddcb3d4. I agree that the cast should be explicit. The current integer to struct checks two things:
I've tested it with this test case: def test_struct_scalar_twice():
hcl.init()
dt4='int4'
dt8='int8'
dt32=hcl.Int(32)
def kernel():
stype = hcl.Struct({"x": dt8, "y": dt8})
xy = hcl.scalar(0x12, "foo", dtype=stype).v
stype2 = hcl.Struct({"a": dt4, "b": dt4})
ab = hcl.scalar(xy.x, "ab", dtype=stype2).v
r = hcl.compute((2,), lambda i: 0, dtype=dt32)
r[0] = xy.y
r[1] = ab.a
return r
s = hcl.create_schedule([], kernel)
hcl_res = hcl.asarray(np.zeros((2,), dtype=np.int32), dtype=dt32)
f = hcl.build(s)
f(hcl_res)
assert hcl_res.asnumpy()[0] == 0
assert hcl_res.asnumpy()[1] == 2 More test cases will be added. |
Regarding "All fields of struct are integers, i.e. no automatic bitcast." , I think this may be too restrictive.
I think as long as the value being assigned has the right bit width (e.g., 24 for a scalar assignment to type t2), the system should be able to assign the fields even if they are non-integers since the bit widths should match. That said -- I recall we discussed with Sean before about supporting structs in structs but I don't think it was fully implemented. It would be a good enhancement to have to make data abstractions simpler to manage. |
Misclicked ... didn't mean to close |
I agree, I think we should support nested structs. What I meant by "no automatic bitcast" is that we don't do integer slice -> float/fixed bitcast. |
This change seems to have caused a segfault in some other areas that used to work ... If the following code is added:
I see the following error:
|
The AST visitor removed the condition operation while it still has uses: Actually I don't think the new changes broke it, this is the same issue as #141. We need to revamp the logical operations. |
This issue is caused by struct op visitors. When their operands are removed but struct ops stayed, MLIR raises an "operation destroyed but still has uses" error. I have added remove and profile mode for struct op visitor with this commit: 7906b26. |
Thanks. Looks like this one works now. |
Removing the urgent tag on this as the primary issue has been resolved. |
The code above generates an LLVM segfault:
Not sure but this may be related to the comment about 'single expr' initialization not supported yet (#133 (comment))
The text was updated successfully, but these errors were encountered: