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

Numerical error with atomic add on shared array elements #7510

Closed
turbo0628 opened this issue Mar 8, 2023 · 1 comment · Fixed by #7513
Closed

Numerical error with atomic add on shared array elements #7510

turbo0628 opened this issue Mar 8, 2023 · 1 comment · Fixed by #7513
Assignees
Milestone

Comments

@turbo0628
Copy link
Member

turbo0628 commented Mar 8, 2023

Minimal reproduction:

import taichi as ti

block_dim = 64
N=256

ti.init(arch=ti.cuda, print_ir=True, print_kernel_llvm_ir=True)

@ti.kernel
def test(out:ti.types.ndarray()):
   ti.loop_config(block_dim=block_dim)
   for i in range(N):
      #gtid = ti.global_thread_idx()
      tid = i % block_dim
      val = i * 1.0
      sharr = ti.simt.block.SharedArray((block_dim,), ti.f32)
      sharr[tid] = val
      ti.simt.block.sync()
      #ti.atomic_add(sharr[0], val)
      sharr[0] += sharr[tid]
      ti.simt.block.sync()
      out[i] = sharr[tid]

arr = ti.ndarray(ti.f32, (N))
test(arr)
print(arr.to_numpy())

This gives unexpected numerical results.

@turbo0628
Copy link
Member Author

The atomic add is somehow demoted.

Maybe this is due to the fact that some pass treat it as a local variable and then removed the atomic add. Will keep on investigating.

@turbo0628 turbo0628 self-assigned this Mar 8, 2023
@turbo0628 turbo0628 added this to the v1.5.0 milestone Mar 8, 2023
@FantasyVR FantasyVR moved this from Untriaged to In Progress in Taichi Lang Mar 10, 2023
turbo0628 added a commit that referenced this issue Mar 10, 2023
Fixes: #7510

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from In Progress to Done in Taichi Lang Mar 10, 2023
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Fixes: taichi-dev#7510

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant