Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodiff failed on cases where the condition of a if depends on the for loop index #6204

Closed
erizmr opened this issue Sep 29, 2022 · 1 comment
Assignees
Labels
potential bug Something that looks like a bug but not yet confirmed

Comments

@erizmr
Copy link
Contributor

erizmr commented Sep 29, 2022

Describe the bug
Autodiff failed on cases where the condition of a if depends on the for loop index (on cuda backend).

To Reproduce

import taichi as ti
ti.init(arch=ti.cuda)

scalar = lambda: ti.field(dtype=ti.f32)
vec = lambda: ti.Vector.field(3, dtype=ti.f32)

pos=vec()
F=vec()
f_bend=scalar()
loss_n=scalar()
ti.root.dense(ti.ij,(10, 10)).place(pos, F)
ti.root.dense(ti.i,1).place(f_bend)
ti.root.place(loss_n)
ti.root.lazy_grad()


@ti.kernel
def simulation(t:ti.i32):
    for i,j in pos:
        coord = ti.Vector([i,j])
        for n in range(12): 
            f = ti.Vector([0.0,0.0,0.0])
            if n < 4:
                f = ti.Vector([1.0, 1.0, 1.0])
            else:
                f = f_bend[0] * pos[coord]
            F[coord] += f
        pos[coord] += 1.0 * t


with ti.ad.Tape(loss=loss_n):
    simulation(5)
 

Log/Screenshots
Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:

[Taichi] version 1.1.4, llvm 10.0.0, commit 50e5e3fd, linux, python 3.8.10
[Taichi] Starting on arch=cuda
[W 09/29/22 16:33:33.523 1504275] [llvm_offline_cache.cpp:load_meta_data@138] Lock /home/mingrui/.cache/taichi/ticache/llvm/metadata.lock failed
[E 09/29/22 16:33:34.432 1504275] [cuda_driver.h:operator()@87] CUDA Error CUDA_ERROR_ILLEGAL_ADDRESS: an illegal memory access was encountered while calling stream_synchronize (cuStreamSynchronize)
...

Additional comments
Related question on forum:
https://forum.taichi.graphics/t/topic/3138

@erizmr erizmr added the potential bug Something that looks like a bug but not yet confirmed label Sep 29, 2022
@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Sep 29, 2022
@erizmr erizmr moved this from Untriaged to In Progress in Taichi Lang Sep 30, 2022
@erizmr erizmr self-assigned this Sep 30, 2022
ailzhang pushed a commit that referenced this issue Sep 30, 2022
Issue: #6204 

### Brief Summary
Autodiff failed on cases where the condition of a if depends on the for
loop index. This PR makes the if condition stored in adstack to handle
these cases.
@erizmr
Copy link
Contributor Author

erizmr commented Oct 8, 2022

Fixed by #6207

@erizmr erizmr closed this as completed Oct 8, 2022
Repository owner moved this from In Progress to Done in Taichi Lang Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential bug Something that looks like a bug but not yet confirmed
Projects
Status: Done
Development

No branches or pull requests

1 participant