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


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

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


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

def fill_3d(x: ti.template()):
1 Like

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.


just add a plugin

1 Like