taichi-dev / taichi

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

Bottleneck in Taichi GGUI #8466

Open devpack opened 9 months ago

devpack commented 9 months ago

Dear Taichi team,

I was not able to use Taichi GGUI without a significant performance loss, is there any known bottleneck in GGUI ? Or things to disable, or not do, to get full performance ?

I made a simple N-Body experiment, test 1 is using Taichi GGUI and test 2 is using a custom ModernGL GUI replicating the same functionalities used in test 1. On both tests the same Taichi kernels are used for the computational part, so that the difference is only the rendering pipeline. Unfortunately Taichi GGUI performed 3 or 4 times slower and I don't get why. I first though that the Dear ImGUI integration was the main cause but it is not, something else is at play. For an order of magnitude here is what I do see on my system:

Test 1: Taichi GGUI +- 350 FPS Test 2: ModernGL GUI +- 2200 FPS Test 2: ModernGL (+ ImGUI) GUI +- 1250 FPS

One can found those tests here: https://github.com/devpack/taichi-opengl-nbody

Any insight would be greatly appreciate.

Thanks

alexspurling commented 9 months ago

I'd be interested to know how you are able to uncap GGUI to run faster than 60fps. On my machine, it always runs at 60FPS even with vsync set to False and fps_limit set to -1.

# Renders at a maximum of 60 fps
self.window = ti.ui.Window("LeapFrog N-body", res=(self.screen_width, self.screen_height), fps_limit=-1, vsync=False)

Edit: Apparently the answer is to set the "Vertical sync" setting in the Nvidia control panel to "Use the 3D application setting". That applies to both the taichi GGUI and ModernGL examples that you provided.

For what it's worth, I get the following performance figures on my AMD 5600X Windows system with an RTX 3060:

Test 1: Taichi GGUI +- 650 FPS Test 2: ModernGL GUI +- 2200 FPS Test 2: ModernGL (+ ImGUI) GUI +- 1250 FPS

devpack commented 7 months ago

Thanks for your tests, so you are seeing the same problem. In the command line, if you change --arch=cpu to --arch=gpu, do you see the same ?