taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.35k stars 2.27k forks source link

Manual ti.sync() for ti.vulkan? #7764

Open zhouxian opened 1 year ago

zhouxian commented 1 year ago

Hi, I am playing around with this mpm example (https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/ggui_examples/mpm3d_ggui.py) , and i noticed that, if i disable all code related to the ggui visualization, i have to manual add ti.sync() after each substep(), otherwise the simulation will run superfast (which is probably not really doing anything) and then crash.

If i switch backend from vulkan to cuda, it works fine. But the simulation speed dropx 3x.

Is this expected?

bobcao3 commented 1 year ago

It's not recommended to add a sync every substep. You can sync every 50 substeps or something similar. Because GPU is async to CPU, the Vulkan backend is batching commands (however we do have some issues with batching too many...). For the simulation speed drop, are you comapring Vulkan with ti.sync() to CUDA with or without?

zhouxian commented 1 year ago

@bobcao3 Thanks for replying! Yes that's what i observed. after some crazy batching it crashes.

I was comparing ti.vulkan with ti.cuda. For ti.cuda, with or without ti.sync does not have any effect on the simulation speed. So in the 3D mpm case, ti.vulkan runs ~3x faster. But when i switch to another 2D example, ti.cuda is faster than vulkan. I was wondering, is there any best practice or guideline in choosing a proper backend?

bobcao3 commented 1 year ago

Hmmm that's interesting. It shouldn't have so much of a difference