About DiffTaichi data access rule

Hi, I have a question about difftaichi data access rule from Differentiable programming | Taichi Docs

In the difftaichi example code mass_spring.py, I found that in the kernel function:

@ti.kernel
def nn2(t: ti.i32):
    for i in range(n_springs):
        actuation = 0.0
        for j in ti.static(range(n_hidden)):
            actuation += weights2[i, j] * hidden[t, j]
        actuation += bias2[i]
        actuation = ti.tanh(actuation)
        act[t, i] = actuation

It seems the variable actuation violates the rule 2? actuation = ti.tanh(actuation) is not a atomic operation? Could anyone help me to explain this please. Thanks

Kind Regards,

Jianhui

cc @mzhang

Hi @yjhp1016 , the data access rule is applied to a global field. In this case, the actuation is a local variable, which does not has this access limitation. :grinning:

1 Like

Thanks! That’s clear now :+1: :grinning: