You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need an explicit API to use struct as integer instead of implicit type cast. We can use .as_int() on struct type expression or a struct scalar.
Use .as_int() on struct type scalar
importheteroclashcldeftest_struct_scalar_int():
hcl.init()
defkernel():
stype=hcl.Struct({"x": hcl.Int(16), "y": hcl.Int(16)})
xy=hcl.scalar(0x12, "xy", dtype=stype)
# Assigning integer to a struct type scalarxy.set(0x1234) # recommendedxy.v=0x1234# legal, deprecated# Use struct as an integera=hcl.scalar(0)
a.set(xy.as_int()) # recommendeda.v=xy.as_int() # legal, deprecateda.v=xy.v.as_int() # API error, .as_int() should be applied to a scalara.v=xy.v# Type error, .v is a struct type, should use xy.as_int()s=hcl.create_schedule([], kernel)
Use .as_int() on struct type expressions
deftest_struct_tensor_int():
hcl.init()
defkernel():
stype=hcl.Struct({"x": hcl.Int(16), "y": hcl.Int(16)})
xy=hcl.compute((10,), lambdax: 0x12, "xy", dtype=stype)
# Assigning integer to a struct type tensor elementwithhcl.for_(0, 10) asi:
xy[i] =0x1234# recommendedxy[i].set(0x1234) # API error, .set() is for scalar only# Use struct as an integera=hcl.compute((10,), lambdax: 0)
withhcl.for_(0, 10) asi:
a[i] =xy[i].as_int() # recommendeda[i].set(xy[i].as_int()) # API error, .set() is for scalar onlys=hcl.create_schedule([], kernel)
The text was updated successfully, but these errors were encountered:
We need an explicit API to use struct as integer instead of implicit type cast. We can use
.as_int()
on struct type expression or a struct scalar.Use
.as_int()
on struct type scalarUse
.as_int()
on struct type expressionsThe text was updated successfully, but these errors were encountered: