commaai / openpilot

openpilot is an operating system for robotics. Currently, it upgrades the driver assistance system in 275+ supported cars.
https://comma.ai/openpilot
MIT License
49.19k stars 8.96k forks source link

Move UI from GPU -> CPU #30294

Open adeebshihadeh opened 10 months ago

adeebshihadeh commented 10 months ago

In order to run larger models, we need to make the GPU exclusive for the driving model. This means we need to offload several processes that currently use the GPU onto the CPU. A good start will be moving the UI to the CPU, which is probably a significant portion of the GPU usage

jnewb1 commented 9 months ago

@deanlee We are working on larger driving models, but we need to move the UI and a few other components to the CPU for that to be feasible on device. A good start would be analyzing and optimizing the maprenderer. We moved mapsd to the CPU as an experiment for CPU rendering, and it takes about 10x the time to render on the CPU (about 30ms, rendering a 256x256 grayscale map at 2hz), so we'd likely need quite a few speedups to render the stylized UI map on device. We have a nice test for this in CI that can also run standalone on device. Would you be interested in looking into optimizing that?

deanlee commented 9 months ago

@jnewb1 will there be any improvement if enable threading?

jnewb1 commented 9 months ago

@jnewb1 will there be any improvement if enable threading?

The latency would most likely be better with threads (you can try it with LP_NUM_THREADS), however the goal would be trying to fit the whole UI on the cpu without bogging down the system, which would mean we would need to significantly optimize overall, not just use more threads. We also don't really care that much about the latency as long as it's reasonable (mapsd is fine with 30ms delay)

deanlee commented 9 months ago

Think it's difficult to optimize the performance based on the current available map API (there is also a lack of other header files from mapbox, only qmapbox.hpp in mapbox-gl-native-qt/include). I've tried using static rending, but always get an error:

render error! "Map is currently rendering an image"

I looked at the source code of the qmapbox, but still can't figure out what's causing the issue. Maybe we can do this optimization later, after switching the map API to MapLibre? https://github.com/commaai/openpilot/issues/26739

adeebshihadeh commented 9 months ago

Sure, @deanlee wanna try to do the MapLibre move?

jnewb1 commented 9 months ago

GPU render time breakdown

Onroad Total 4-6ms

Map (when enabled): 1.2-2.5ms ( depending on scene complexity )

andiradulescu commented 5 hours ago

@adeebshihadeh do you prefer this to be done in openpilot, so that we control each process that runs on CPU?

or we want an AGNOS approach, where everything qt and/or EGL runs on CPU without any changes in openpilot?

if you prefer in AGNOS, I will create a separate issue explaining the two possible variants (with weston or without).

adeebshihadeh commented 4 hours ago

There's a tradeoff. More control with openpilot, but then it's a little harder to run arbitrary stuff. I think it'll end up being the cleanest to cut out Weston and do almost everything in openpilot.