Hi,
I am new to Taichi programming and having some problems about using Taichi class with multiple image buffers. I created a short test case that has two image buffers in a Taichi class and I want to use the buffers programmatically but got some error, the code is:
import numpy as np
import taichi as ti
ti.init(arch=ti.cuda) # use gpu
@ti.data_oriented
class test:
def __init__(self, kin, sizeX, sizeY):
self.k = kin
self.imgA = ti.var(ti.f32)
self.imgB = ti.var(ti.f32)
ti.root.dense(ti.ij, (sizeX,sizeY)).place(self.imgA)
ti.root.dense(ti.ij, (sizeX,sizeY)).place(self.imgB)
@ti.func
def runker(self,img:ti.f32, x:ti.i32, y:ti.i32):
return self.k + img[x,y]
@ti.kernel
def convolve(self,imgSrc:ti.f32,imgDest:ti.f32,sx:ti.i32,sy:ti.i32):
# the following line caused ti error:
# RuntimeError: [expr.cpp:snode@81] is<GlobalVariableExpression>()
for i,j in imgDest:
imgDest[i,j] = self.runker(imgSrc,i,j)
nr = 0.2
sx = 1024
sy = 1024
testImg = nr * np.random.rand(sx, sy)
x = test(2,sx,sy)
x.convolve(x.imgA,x.imgB,sx,sy)
And the error is:
Traceback (most recent call last):
File "/home/ling/proj-taichi/test/ti-bug2.py", line 58, in <module>
x.convolve(x.imgA,x.imgB,sx,sy)
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/kernel.py", line 574, in __call__
return self._primal(self._kernel_owner, *args, **kwargs)
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/kernel.py", line 469, in __call__
self.materialize(key=key, args=args, arg_features=arg_features)
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/kernel.py", line 348, in materialize
taichi_kernel = taichi_kernel.define(taichi_ast_generator)
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/kernel.py", line 345, in taichi_ast_generator
compiled()
File "/home/ling/proj-taichi/test/ti-bug2.py", line 40, in convolve
# the following line caused ti error:
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/impl.py", line 63, in begin_frontend_struct_for
if group.size() != len(loop_range.shape):
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/expr.py", line 136, in shape
return self.snode().shape
File "/home/ling/.local/lib/python3.7/site-packages/taichi/lang/expr.py", line 129, in snode
return SNode(self.ptr.snode())
RuntimeError: [expr.cpp:snode@81] is<GlobalVariableExpression>()
I am using Taichi version 0.6.22, llvm 10.0.0, commit f5283775, python 3.7.8
Can someone help?
Thanks.