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

VHLS Codegen Overshift Issue #471

Open wyanzhao opened 2 years ago

wyanzhao commented 2 years ago

Hi, I am writing the following heteroCL code, which can cause an overshift code. But there's no warning during the code generation . Is it possible to add overshift detections in the heteroCL.

import heterocl as hcl
import numpy

hcl.init()

def kernel(A, B):  
        hcl.update(B, lambda x: A[x] >> -9223372036854775808 )

A = hcl.placeholder((1,), "A", hcl.UInt(64))
B = hcl.placeholder((1,), "B", hcl.UInt(64))
s = hcl.create_schedule([A, B], kernel)

print(hcl.lower(s))

f = hcl.build(s, "vhls")
print(f)
void default_function(ap_uint<64> A[1], ap_uint<64> B[1]) {
  int _top;
  int update0;
  update0_x: for (int x = 0; x < 1; ++x) {
    B[x] = (A[x] >> -9223372036854775808);
  }
}

Above is the output VHLS code, which could have undefined behaviors during execution:

hecmay commented 2 years ago

@wyanzhao Thanks for the suggestion ! Sure. it will be very useful to add some extra legality checking on this. I will try to open a new PR for it.