Closed tonyjie closed 5 years ago
HeteroCL does not support return_
statement inside a normal Python function call. In this case, you have several options.
Use hcl.select
def compare_with_zero(a):
return hcl.select(a > 0, a ,0)
Use an intermediate variable to hold the result
def compare_with_zero(a):
b = hcl.local(0)
with hcl.if_(a > 0):
b[0] = a
with hcl.else_():
b[0] = 0
return b[0]
Please close this issue if this solves the problem.
HeteroCL does not support
return_
statement inside a normal Python function call. In this case, you have several options.
- Use
hcl.select
def compare_with_zero(a): return hcl.select(a > 0, a ,0)
- Use an intermediate variable to hold the result
def compare_with_zero(a): b = hcl.local(0) with hcl.if_(a > 0): b[0] = a with hcl.else_(): b[0] = 0 return b[0]
Please close this issue if this solves the problem.
Thanks! Both of the methods can work. In this case, I think the second option is a general solution for now, using a local intermediate variable to hold the result. By the way, another question is that when using return instead of hcl.return_(), the normal Python function didn't work. To be specific:
def conv_layer(input, filter, bias):
def compare_with_zero(a):
with hcl.if_(a > 0):
return a
with hcl.else_():
return 0
when printing hcl.lower(s)
, this function only became an output = input
. That's the reason why I'm using hcl.return_()
. I think the reason is that when we use some dsl function of hcl, such as hcl.if_()
and hcl.else_()
, HeteroCL doesn't support normal return. I'm not sure is that correct?
Anyway, the respond helps. Thanks
Yes, you are right. It would be a good idea to support hcl.return_
within an if/else statement in the future.
Fixed by #116.
I'm trying to write a conv_layer using HeteroCL, but a memory error can't be solved.
Above program went error when doing with f = hcl.build(s) However, when the input placeholder's dimension is 2, this program works. And when the dimension becomes 3 or 4, the error of Segmentation Fault (core dumped) came.