You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The idea is to bypass particle that has 0 mass using if statement, but it turns out that the code will still evaluate the content inside the if statement even when mass is 0. Also, different content inside if statement is generating different execution time when it should have been bypassed by the false condition.
To Reproduce
importtaichiastifromtaichi.mathimportvec3,vec2importtimeti.init(arch=ti.gpu, debug=False)
Particle=ti.types.struct(mass=ti.uint32,pos=vec3,vel=vec3,force=vec3,density=float)
bufferP0,bufferP1=Particle.field(shape=(128,64,32)),Particle.field(shape=(128,64,32))
@ti.kerneldeftest_Main_exec():
forposinti.grouped(ti.ndrange(128,64,32)):
p0,p1=Particle(),Particle()
foroffsetinti.grouped(ti.ndrange((-1,10),(-1,10),(-1,10))):
NPos=pos+offsetincoming0,incoming1=bufferP0[NPos],bufferP1[NPos]
ifincoming0.mass>0: #deleting content inside this statement generate different execution time resultp0.pos=p0.pos*p0.mass+incoming0.pos*incoming0.massp0.mass=incoming0.massifincoming1.mass>0: #same herep1.pos=p1.pos*p1.mass+incoming1.pos*incoming1.massp1.mass=incoming1.massbufferP0[pos],bufferP1[pos]=p0,p1if__name__=="__main__":
start_time=time.time()
prev_time=0whileTrue:
test_Main_exec()
ti.sync()
end_time=time.time()
execution_time= (end_time-start_time)*1000print(f"Execution time: {execution_time-prev_time:.1f} ms per frame")
prev_time=execution_time
deleting
p0.mass=incoming0.massp1.mass=incoming1.mass
will generate different execution time (60ms to 8ms), which means the content inside if statement is not bypassed. Also 8ms to 60ms is waaaay too much for just a simple p0.mass = incoming0.mass and p1.mass = incoming1.mass.
The text was updated successfully, but these errors were encountered:
FieryAery
changed the title
[perf] Taichi ignoring "if" statement and create devastating performance drop (from 1ms to 200 ms), with a lot of weird behavior
Taichi ignoring "if" statement and create devastating performance drop (from 1ms to 200 ms), with a lot of weird behavior
Nov 9, 2023
FieryAery
changed the title
Taichi ignoring "if" statement and create devastating performance drop (from 1ms to 200 ms), with a lot of weird behavior
Taichi if statement bug that causes performance issue
Nov 10, 2023
Describe the bug
The idea is to bypass particle that has 0 mass using if statement, but it turns out that the code will still evaluate the content inside the if statement even when mass is 0. Also, different content inside if statement is generating different execution time when it should have been bypassed by the false condition.
To Reproduce
deleting
will generate different execution time (60ms to 8ms), which means the content inside if statement is not bypassed. Also 8ms to 60ms is waaaay too much for just a simple p0.mass = incoming0.mass and p1.mass = incoming1.mass.
The text was updated successfully, but these errors were encountered: