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

How to tell if hcl.assert_ fired programmatically? #413

Open jcasas00 opened 3 years ago

jcasas00 commented 3 years ago

hcl.assert terminates the LLVM execution when it fires. However, there doesn't seem to be any indication at the top-level that the hcl.assert fired. Can it raise an exception HCLAssert (for example) ?

seanlatias commented 3 years ago

Hmmmm... I'll see if I can enable the return value of the top function. If the return value is non-zero then the program is wrong.

seanlatias commented 3 years ago

@jcasas00 I proposed a solution in #414. Please see if this is similar to what you have in mind.

jcasas00 commented 3 years ago

Yes, this is pretty much what I was envisioning.

seanlatias commented 3 years ago

Please check #414. Now it is merged.

jcasas00 commented 3 years ago

I tried https://github.com/cornell-zhang/heterocl/pull/414 and it indeed raises an exception. One thing though, while the assert error message is printed, the string associated with the caught exception seem to be always "[Assert] Assert Failed!!!" (which we already know by being in the except block). Is it possible to have the actual assertion message also be passed to the exception object?

For example:

    try:
        f(dram, addr)
    except hcl.debug.AssertError as e:
        print ("Got exception: " + str(e))

Output:

Invalid index=3                                                # this is printed by the hcl.assert_
Got exception: [Assert] Assert Failed!!             # could str(e) also be the same assert_ message string (instead of printing)?
seanlatias commented 3 years ago

Right, ideally we want to return the error message. For now, it would take some extra work to implement that. I'll mark it as enhancement.