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

HeteroCL data struct results in incomplete generated code #163

Open hecmay opened 4 years ago

hecmay commented 4 years ago
  1. I was trying to write some imperative code with data struct, where we multiply two values from a data struct and assign the product back to another struct.
stype = hcl.Struct({"fa": ccl.Int(), "fb": ccl.Fixed(12,8)})
t = hcl.scalar(tensor[r,c], dtype=stype)          
r = hcl.scalar(0, dtype=stype)
r.v.fa = t.v.fa * t.v.fb

The generated code failed to capture the computation r.v.fa = t.v.fa * t.v.fb and outputs some incomplete convertors for it like this.

ap_uint<32> _converter2;
_converter2(      _converter3(

The workaround is to write the program in the following way.


stype = hcl.Struct({"fa": ccl.Int(), "fb": ccl.Fixed(12,8)})
t = hcl.scalar(tensor[r,c], dtype=stype)          
r = hcl.scalar(0, dtype=stype)
x = hcl.scalar(t.v.fa)
y = hcl.scalar(t.v.fb)
r.v.fa = x.v * y.v
  1. The generated code has some redundant bit slicing operations, which confuses Vivado HLS in streaming channel analysis, and leads to pre-synthesis failure.
ap_uint<32> _converter;
// Vivado HLS complains grad_x has been consumed more than once
_converter(31, 0) = grad_x[(x + (y * 1024))](31,0);

// We have to manually remove the bit-slicing operation 
// so that grad_x can be implemented as a FIFO
_converter(31, 0) = grad_x[(x + (y * 1024))];