-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use GPU for Blender rendering? #224
Comments
Hi, @Wuziyi616, I also ran into this problem, have you solved it? |
I have not used a GPU from within the docker, so I cannot comment on that. But it works nicely on my linux machine where I have built and installed the Blender python module natively. That way of installing can be a bit finicky, but on Ubuntu, you should be able to follow the dockerfile to make it work. |
I encountered the same issue, and I solved it by changing the build script of the Docker image. Let me share my workaround below. The current The above problem was solved by
The following commit contains the actual changes: ganow@206eecd The execution log is as follows: $ docker run --rm \
--interactive \
--gpus all \
--env KUBRIC_USE_GPU=1 \
--volume "$(pwd):/kubric" \
kubricdockerhub/kubruntu \
/usr/bin/python3 examples/helloworld.py
INFO:kubric.renderer.blender:Using the following GPU Device(s): ['NVIDIA GeForce RTX 2080 Ti', 'NVIDIA GeForce RTX 2080 Ti']
INFO:kubric.renderer.blender:Saving 'output/helloworld.blend'
INFO:kubric.renderer.blender:Using scratch rendering folder: '/tmp/tmpdwy3_o_l'
INFO:kubric.renderer.blender:Rendered frame '/tmp/tmpdwy3_o_l/images/frame_0001.png'
INFO:root:Writing to 'output/helloworld.png'
INFO:root:Writing to 'output/helloworld_segmentation.png'
INFO:root:Writing to 'output/helloworld_depth.png'
INFO:root:Depth scale: {'min': 3.359675884246826, 'max': 11.91185188293457}
Error: Not freed memory blocks: 1, total unfreed memory 0.001259 MB |
Hi @ganow thank you so much for your reply, the solution seems very reasonable. However, since I'm new to docker, can you kindly tell me how to build the docker image after applying your modification? Say I've Thanks in advance! |
Hi @Wuziyi616.
Would you try the following commands? $ git clone https://github.com/ganow/kubric.git
$ cd kubric
$ docker build -f docker/Blender.Dockerfile -t kubricdockerhub/blender:latest . # build a blender image first
$ docker build -f docker/Kubruntu.Dockerfile -t kubricdockerhub/kubruntu:latest . # then build a kubric image of which base image is the blender image above The above command overwrites the name of the existing Docker image locally, so perhaps you should give it a different name for the GPU-enabled image like kubric/docker/Kubruntu.Dockerfile Line 10 in a3d5eaa
BTW, thanks to this issue I was able to find the option to enable GPU in kubric. Thank you very much! |
@ganow Ah yes I forgot to change the name of this image haha. I tried your solution and it works! Thank you so much for your kind reply. Glad this issue help :) |
A few problems I've encountered and how I solve them:
See #88, you need to build the kubric wheel packages first by running
See this issue, this is likely because you didn't install the Hope this helps! |
@ganow just out of curiosity, do you benchmark the performance improvement after using GPU for rendering? I tried to render some 1024x1024 images with a 3090 GPU (the program indeed prints |
@Wuziyi616 To be honest, I have confirmed no difference in rendering performance between CPU and GPU (NVIDIA GeForce RTX 2080 Ti), even in my environment. However, in my case, the target I wanted to render was 128px and not very high resolution, so the computing resources may not necessarily be the bottleneck, and I cannot determine if it is a configuration error. If there is no performance difference even when rendering 1024px images, I thought that maybe I have the wrong settings somewhere. If you can use a Blender GUI, you may load the .blend file generated by kubric with the GUI App and measure how long it takes to render it. |
According to these problems,
Sorry, I forgot to mention this procedure. Thank you for providing a full description.
Yes, we need to set up NVIDIA docker first. |
Thanks for the pointers and help how to enable GPU rendering! Now that I managed to make it run I am wondering how I could find out whether Blender actually is using the GPU at all since as you already noted, it does not feel like there is any speedup. What I find strange is that whilst my log shows I am wondering if there are some additional steps required in the configuration? The blender docs say:
|
I dug around a bit and as it turns out the current code does only detect the GPU devices, but it does not activate them to be actually used. I found a code snippet (here: https://blender.stackexchange.com/questions/154249/how-setup-cycles-compute-device-in-console) which does the activation and changed the use_gpu() setter method in blender.py like this:
And voilá now I am seeing a 5x speedup for my larger renders - instead of 50 seconds it takes only 10 seconds. |
I can confirm that the solution here works. FYI: I'm using 3090, the performance of rendering 128x128 images is similar, but 1024x1024 is much faster. |
Since I have recently tried what's been provided in this thread I want to share what worked for me.
my solution was to add
...
To check available devices use the following:
Hope this helps anyone wanting to utilize the GPU powered kubric-docker. |
Activate GPUs to be used, according to: google-research#224 (comment)
Thanks @Orchidaceae , you comment is very helpful! |
Thank you all for exposing and solving this problem! Just to add: you need to change the
You can change the code locally, which is adding
Maybe useful to some rookies like myself. |
- Requires the nvidia-container-toolkit on the host machine - Should be ran with Docker options `--gpus all --env KUBRIC_USE_GPU=1` - Source: google-research#224
- Requires the nvidia-container-toolkit on the host machine - Should be ran with Docker options `--gpus all --env KUBRIC_USE_GPU=1` - Source: google-research#224
Hi, thanks for the great work! I want to use GPU to accelerate rendering. According to this line, I try to set the environment by:
However, it doesn't seem to detect any GPUs as it prints:
I bash into the docker image and copy-paste the GPU detection code into python shell, it only detects my CPU:
However, when I do
nvidia-smi
there is indeed outputAny thought on this? I tried on multiple machines (desktop, cluster) but they all failed
The text was updated successfully, but these errors were encountered: