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

reduction of taichi is slower than numpy #46

Open
Frenchfries135 opened this issue Jun 10, 2021 · 0 comments
Open

reduction of taichi is slower than numpy #46

Frenchfries135 opened this issue Jun 10, 2021 · 0 comments

Comments

@Frenchfries135
Copy link

Frenchfries135 commented Jun 10, 2021

import taichi as ti
import numpy as np
import time
ti.init(arch=ti.cuda)#,debug=True)
n=1<<18
a=np.random.randn(n).astype(np.float32)
b=ti.field(ti.f32,n)
b.from_numpy(a)
@ti.kernel
def sum1()->ti.f32:
    result=0.0
    for i in b:
        result+=b[i]
    return result
#compile
sum1()
t1=time.time()
for _ in range(1000):
    a.sum()
t2=time.time()
for _ in range(1000):
    sum1()
ti.sync()
t3=time.time()
print('time numpy:',t2-t1,'time ti atomic_add:',t3-t2)
input('enter to continue')

result in RTX3060 and R7 5800H is:

time numpy: 0.07301616668701172 time ti atomic_add: 0.3090794086456299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant