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

a for loop under vulkan doesn't work with count = count + k but ok with count += k, and Ok under cpu #8432

Closed
deMesnard opened this issue Dec 8, 2023 · 3 comments

Comments

@deMesnard
Copy link

A for loop in @ti.kernel and under acrh vulkan give incorrect result with count=count+k but is OK with count+= k and is also OK under arch cpu.

--coding:Latin-1 -

import taichi as ti
ti.init(arch=ti.vulkan)
@ti.kernel
def count_primes(n: int) -> int:
count = 0
for k in range(0, n):
count = count + k
#count += k
return count
print(count_primes(30))
#ti.profiler.print_kernel_profiler_info()

Result :
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbb, win, python 3.11.6
[Taichi] Starting on arch=vulkan
28

Process finished with exit code 0
28 is incorrect should be 435
With count+= k :

--coding:Latin-1 -

import taichi as ti
#ti.init(arch=ti.cpu, debug = True, verbose= True)
#ti.init(arch=ti.cpu)
#ti.init(arch=ti.vulkan, debug = True, verbose= True)
#ti.init(arch=ti.cuda)
#ti.init(arch=ti.opengl)
ti.init(arch=ti.vulkan)
#ti.init(kernel_profiler=True)

@ti.kernel
def count_primes(n: int) -> int:
count = 0
for k in range(0, n):
#count = count + k
count += k
return count
print(count_primes(30))
Result:
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbb, win, python 3.11.6
[Taichi] Starting on arch=vulkan
435

Process finished with exit code 0
is correct and work fine also in any cases under cpu instead vulkan

@deMesnard
Copy link
Author

I am under Windows 11 PC : HP, CPU :AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx 2.30 GHz
GPU : AMD radeon RX Vega 10, Vulkan : version up -to-date 31.0.21905.1001

@FieryAery
Copy link

count = count + k is not atomics
count += k is automatically atomics

@deMesnard
Copy link
Author

OK thank you I found in the Taichi's guide the explanations about this question of "atomics", I understand now

@github-project-automation github-project-automation bot moved this from Untriaged to Done in Taichi Lang Dec 15, 2023
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

No branches or pull requests

2 participants