[Binding] Incorrect data extension for get_bit
chhzh123 opened this issue · 0 comments
chhzh123 commented
The following binary convolution kernel generates incorrect results which is due to incorrect data extension of get_bit
.
def test_bconv2D_nhwc_packed():
hcl.init(hcl.UInt(packing_factor))
A = hcl.placeholder((bs, ih, iw, ic // packing_factor))
F = hcl.placeholder((oc, kh, kw, ic // packing_factor))
def conv(A, F):
rc = hcl.reduce_axis(0, ic // packing_factor)
rh = hcl.reduce_axis(0, kh)
rw = hcl.reduce_axis(0, kw)
rb = hcl.reduce_axis(0, ic)
L = ic * kh * kw
B = hcl.compute(
(bs, oh, ow, oc),
lambda n, h, w, c: L
- (
hcl.sum(
(A[n, h + rh, w + rw, rc] ^ F[c, rh, rw, rc])[rb],
axis=[rh, rw, rc, rb],
dtype=hcl.Int(32),
)
<< 1
),
name="B",
dtype=hcl.Int(32),
)
return B
s = hcl.create_schedule([A, F], conv)
The original code uses signed extension, which is not the case. Since the obtained one-bit integer is unsigned, we should use unsigned extension.
%8 = hcl.get_bit(%7 : i16, %arg9) -> i1
%10 = arith.extsi %8 : i1 to i32