cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

runtime assertion support #377

Closed zhenkun closed 3 years ago

zhenkun commented 3 years ago

similar to hcl.print, it would be nice to have a hcl.assert that will check the condition at runtime. Right now python assert is only valid at elaboration time.

seanlatias commented 3 years ago

Great idea. What kind of behavior do you expect? I would expect the HeteroCL program to stop but not the entire Python program. With this setting, users can run 10 HCL programs sequentially even if one of them fails the assertion.

zhenkun commented 3 years ago

I agree with you. Just stopping the HeteroCL program makes more sense. If it is possible, it would also be nice to support string formatting. For example, hcl.assert(a>b, "a and b are different: a=%d, b=%d\n", a, b), or something similar. But if it's too hard, we can always call hcl.print explicitly.

seanlatias commented 3 years ago

Solved in #385

seanlatias commented 3 years ago

@zhenkun please give it a try. The only difference with your example is we need to use hcl.assert_ with an underscore.