4
$\begingroup$

I installed wsl2 Ubuntu on windows,
and then installed docker desktop to get a docker engine.
I ran a image from osrf/ros, the gazebo started sucessfully, but ran slowly.
And I checked the nvidia-smi, gazebo didn't use gpu to accerlate.
My question is how to setup the environment corretly to make gazebo use gpu?

I already searched a lot, but sadly that all failed for me.

And I can't run the container with --runtime=nvidia, the error msg is below

docker: Error response from daemon: unknown or invalid runtime name: nvidia.

nvidia-smi output in wsl2 ubuntu nvidia-smi output in wsl2 ubuntu

nvidia-smi output in container nvidia-smi output in container

What I did:

docker pull osrf/ros:jazzy-desktop-full

docker run --name test -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -it --gpus all --device /dev/dri:/dev/dri --privileged -v /dev:/dev --env="NVIDIA_DRIVER_CAPABILITIES=all" --net=host osrf/ros:jazzy-desktop-full /bin/bash

I'm not sure that if I need to install Nvidia-Container-toolkit in wsl2. And the nvidia-smi can recognize the gpu, so I think there is no need.
but I have installed once, and it didn't work.

similar question:ROS2 on Windows with NVidia GPU

He gave up!!! So I have no choice./(ㄒoㄒ)/~~😢

No more words can describe my appreciation if someone fix it..

$\endgroup$
0

1 Answer 1

4
$\begingroup$

Yes Yes!!!✌
I finally finally find a solution after two days hard working.
To those who suffer same question, I now post an answer.

It's all about Containerizing GUI applications with WSLg

Thanks for rr-robot posting an issue about WSL2 + Docker + OpenGL + NVIDIA not working (uses llvmpipe) and giving the solution.

Now run the container with following command:

 docker run --name test  -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/wslg:/mnt/wslg \
-e DISPLAY=unix$DISPLAY \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
--device=/dev/dxg \
-v /usr/lib/wsl:/usr/lib/wsl \
-it --gpus all --device /dev/dri:/dev/dri --privileged \
-v /dev:/dev -e NVIDIA_DRIVER_CAPABILITIES=all \
-e LD_LIBRARY_PATH=/usr/lib/wsl/lib \
--net=host osrf/ros:jazzy-desktop-full /bin/bash

The additional part:

-v /mnt/wslg:/mnt/wslg \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
--device=/dev/dxg \
-v /usr/lib/wsl:/usr/lib/wsl \
-e LD_LIBRARY_PATH=/usr/lib/wsl/lib \

In this case:

  • The container simulates the prius example in gz sim quick start faster.
  • Now the camera fps is about 62.
  • The output from nvidia-smi covers the two processes named "ruby" relates to simulator.

But in Quadcopter teleop example, the camera is only 20 fps. I'm not sure that it's because the complexity of project or not. Is RTX 2060 good enough to simulate or not? And the nvidia-smi also prints two "ruby" processes.

$\endgroup$
2
  • $\begingroup$ It's great that you found a solution. You last paragraph seems to contain a follow-up question. If so, then you will need to post a new question (maybe link back to this question for context), as answers on Stack Exchange can not contain additional questions, and you won't receive a follow up answer. $\endgroup$ Commented Jun 12 at 10:17
  • $\begingroup$ Thanks. The follow-up question doesn't really matter. I will find on the internet to see if I can solve it or not. If not, I may post a question. $\endgroup$ Commented Jun 13 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.