How do I pass tensor into kernel

Passing argument into taichi’s kernel yields strange error logs as follows:

Attribute dim not found.

The MRE is as follows:

import taichi as ti

ti.init(arch=ti.gpu)

a = ti.var(dt=ti.f32, shape=(10, 10, 10))

@ti.kernel
def fill_3d(x: ti.f32):
    # Parallelized for all 3 <= i < 8, 1 <= j < 6, 0 <= k < 9
    for i, j, k in ti.ndrange((3, 8), (1, 6), 9):
        x[i, j, k] = i + j + k

fill_3d(a)

Hi @MARMOTatZJU, tensors should be passed in as templates:

@ti.kernel
def fill_3d(x: ti.template()):
    ...
1 个赞

Thanks a lot for your reply.

Little suggestion for forum: at the row on the bottom (like/link/reply/etc.), consider adding a button for marking “solution (解决方案)”. I met this design during my research internship at Megvii and I found this useful for others who search for similar answers.

2 个赞

just add a plugin

1 个赞