Hybrid Inter-function call wrong


#1

Hello, everyone, I’m a fresh man of tvm, recently i run the test code about hybrid in “tests/python/unittest/test_hybrid_script.py”。When i run test_func_call(), everything is OK,but when i change the called func name, there has something wrong, I can’t find the reason.Can you help me?
Thank you very much.
My code is:
def test_func_call():
@tvm.hybrid.script
def outer_productss(n, m, a, b):
“”“This is a simple outer product.”""
c = output_tensor((n,m), a.dtype)
for i in range(n):
for j in range(m):
assert i<n and j<m, “index out of range!”
c[i,j] = a[i]*b[j]
return c

@tvm.hybrid.script
def foo(a, b):
    for i in range(len(a)):
        a[i] = i + 1.0
    for i in range(len(a)):
        b[i] = i + 1.0
    c = outer_productss(10, 10, a, b)
    d = output_tensor(c.shape, c.dtype)
    for i in range(10):
        for j in range(10):
            d[i, j] = c[i, j] + i * j
    return d

a = tvm.placeholder((10, ), name='a')
b = tvm.placeholder((10, ), name='b')
func, ins, outs = run_and_check(foo, [a, b])
run_and_check(func, ins, outs=outs)

Error is :
Traceback (most recent call last):
File “test_hybrid.py”, line 380, in
test_func_call()
File “test_hybrid.py”, line 332, in test_func_call
func, ins, outs = run_and_check(foo, [a, b])
File “test_hybrid.py”, line 22, in run_and_check
outs = func(*tuple(tvm.convert(i) if isinstance(i,list) else i for i in args))
File “</home/s50004646/.local/lib/python3.5/site-packages/decorator.py:decorator-gen-4>”, line 2, in foo
File “/home/s50004646/tvm-master/python/tvm/hybrid/init.py”, line 62, in wrapped_func
return source_to_op(src, args, func.globals, closure_vars)
File “/home/s50004646/tvm-master/python/tvm/hybrid/parser.py”, line 652, in source_to_op
parser = parse_python(src, args, symbols, closure_vars)
File “/home/s50004646/tvm-master/python/tvm/hybrid/parser.py”, line 620, in parse_python
var_usage = determine_variable_usage(root, args, symbols, closure_vars)
File “/home/s50004646/tvm-master/python/tvm/hybrid/preprocessor.py”, line 116, in determine_variable_usage
visitor.visit(root)
File “/usr/lib/python3.5/ast.py”, line 245, in visit
return visitor(node)
File “/usr/lib/python3.5/ast.py”, line 253, in generic_visit
self.visit(item)
File “/usr/lib/python3.5/ast.py”, line 245, in visit
return visitor(node)
File “/home/s50004646/tvm-master/python/tvm/hybrid/preprocessor.py”, line 46, in visit_FunctionDef
self.visit(i)
File “/usr/lib/python3.5/ast.py”, line 245, in visit
return visitor(node)
File “/usr/lib/python3.5/ast.py”, line 255, in generic_visit
self.visit(value)
File “/usr/lib/python3.5/ast.py”, line 245, in visit
return visitor(node)
File “/home/s50004646/tvm-master/python/tvm/hybrid/preprocessor.py”, line 66, in visit_Call
“Function call id not in intrinsics’ list”)
File “/home/s50004646/tvm-master/python/tvm/hybrid/util.py”, line 42, in _internal_assert
raise ValueError(err)
ValueError: Function call id not in intrinsics’ list


#2

CC: @were if you have bandwidth


#3

This is a bug. I apologize.
If you move productss as a global function, you can work this around.
I will be fixing it as soon as possible.


#4

@were as you said,I move productss as a global function, it works, Thank you very much.