-
Notifications
You must be signed in to change notification settings - Fork 17
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
Undefined behavior introduced by reuse_at
transformation in HeteroCL
#185
Comments
Thanks for providing the issue. In this piece of code, those undefined values will not be used in actual computation, so if you plug in some example inputs, the output should be the same as the original program. Indeed, it would be better to initialize those arrays, but we have not figured out a clean way that will not introduce hardware overheads. Explicitly writing |
Thank you for your response. According to some research, writing an uninitialized value back to the same location can lead to undefined behavior on some specific backends, such as C-based compilers, as mentioned in this article: https://queue.acm.org/detail.cfm?id=3041020, please check this example in the article:
|
Right, this is problematic. We need to discuss what is the best way to initialize the array. It seems MLIR does not provide shorthands like |
It appears that using
|
Just a note that in practical hardware design, we do not want to initialize a memory block if it does not affect the functionality. The overhead is too high. So adding a fill operation or an initializer is not the solution here. @chhzh123 can we avoid reading from the uninitialized array in this specific case? |
It also requires some control logic to skip those uninitialized elements, which may also increase hardware complexity. |
We are currently performing formal verification on HeteroCL, and we have discovered an undefined behavior introduced by the
reuse_at
transformation. The input code is as follows:After running
hcl-opt -opt
, the output code is:The issue occurs when HeteroCL allocates a new memory block
(%0 = memref.alloc() {name = "s_reuse_0"} : memref<3x10xf32>)
and reads from it without initializing it first(%1 = affine.load %0[1, %arg3] : memref<3x10xf32>
.In MLIR, reading uninitialized memory is considered undefined behavior. The input code only has undefined behavior of reading from A and B when they are uninitialized, which implies that the
reuse_at
transformation introduces new undefined behavior does not exist in the input code.The text was updated successfully, but these errors were encountered: