cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
326 stars 92 forks source link

Unexpected heterocl.scalar result when expression is passed through function call #407

Closed jcasas00 closed 3 years ago

jcasas00 commented 3 years ago

Code:

def somefn(addr):
    _a = hcl.scalar(addr[0], name="addr", dtype=addr.dtype)
    hcl.print((addr,_a), "reading addr=%d _a=%d\n")

def test (addr):
    somefn (addr)          # reading 1

    addr1 = addr + 1
    somefn (addr1)         # reading 2

    _a2 = hcl.scalar(addr1, name="addr", dtype=addr.dtype)          # reading 3
    hcl.print((_a2), "reading _a2=%d\n")

ADDR    = hcl.placeholder((1,), "addr", dtype=hcl.UInt(16))
s = hcl.create_schedule([ADDR], test)
f = hcl.build(s)
addr    = hcl.asarray ([10], dtype=ADDR.dtype)
f (addr)

Output:

reading addr=10 _a=10
reading addr=11 _a=1                <--- _a = 1 ????
reading _a2=11

From the output, first reading looks okay. But the second reading (where addr1 is passed to somefn), the value of addr and _a inside somefn() are not the same.
The third reading passes addr1 directly to hcl.scalar (not going though somefn) and this seems to be right.

jcasas00 commented 3 years ago

Sorry -- ignore. Of course just as a filed, occurred to me what I was doing wrong. Should be passing addr[0] to somefn instead of doing addr[0] from inside somefn.