Doesn't seem to support GPUs assigned through python script
olibd opened this issue · 1 comments
With a headless blender it is normally possible to use a python script to assign specific devices before rendering, but for some weird reasons, all the version (2.83, 2.90, 2.91) containerized with this repo that I tried seems to ignore the instructions given by the file. For example, if I use the following command
docker run --gpus all --ipc=host -v /mnt/vol_b/blender_input:/volume/blender_input -v /mnt/vol_b/blender_output:/volume/output nytimes/blender:2.90-gpu-ubuntu18.04 blender -b /volume/blender_input/water_sim.blend -E CYCLES -P /volume/blender_input/device_select.py -a
The expected behavior is that a render will be started with the script device_select.py (shown below) activating only the CUDA graphics card.
import re
import bpy
import time
from datetime import datetime
scene = bpy.context.scene
scene.cycles.device = 'GPU'
print("~~~~~> scene device: {}".format(scene.cycles.device))
prefs = bpy.context.preferences
cprefs = prefs.addons['cycles'].preferences
cuda, opencl = cprefs.get_devices()
print("~~~~~> cprefs: {}".format(cprefs))
print("~~~~~> cuda devices: {}".format(cuda))
for compute_device_type in ('CUDA'):
try:
cprefs.compute_device_type = compute_device_type
print('~~~~~> compute device found type set', compute_device_type)
break
except TypeError:
pass
for device in cuda:
print('~~~~~> Activating', device)
device.use = (device.type != 'CPU')
print("~~~~~> device {} usage status: {}".format(device, device.use))
for device in opencl:
print('~~~~~> Deactivating', device)
device.use = (device.type != 'CPU')
print("~~~~~> device {} usage status: {}".format(device, device.use))
Unfortunalety, this doesn't work with the dockerized blender found in this repo. But it does locally on my machine.
Here’s all the things I verified and confirmed are:
- The cuda drivers are properly loaded in the docker container
- I tested with a different project (simple default cube project) and I get the same results
- I loaded and tried different versions of blender using the following containers nytimes/blender:2.83-gpu-ubuntu18.04, and nytimes/blender:2.91-gpu-ubuntu18.04 with the same problem
- Blender runs fine otherwise and renders properly on CPU
- The script print the modifications made before launching the animation render and the parameters are as expected
Any help would be appreciated.
Cheers!
For anyone stumbling on this post. There was a bug in the script which meant I was enumarating over the string 'CUDA' in the compute_device_type loop. The bug that was introduced when I removed the other elements in this tuple. I am now using the following cleaned script:
import bpy
scene = bpy.context.scene
scene.cycles.device = 'GPU'
print("~~~~~> scene device: {}".format(scene.cycles.device))
prefs = bpy.context.preferences
cprefs = prefs.addons['cycles'].preferences
cuda, opencl = cprefs.get_devices()
print("~~~~~> cprefs: {}".format(cprefs))
print("~~~~~> cuda devices: {}".format(cuda))
cprefs.compute_device_type = 'CUDA'
print('~~~~~> compute device type set to', cprefs.compute_device_type)
for device in opencl:
print('~~~~~> Deactivating', device)
device.use = False
print("~~~~~> device {} usage status: {}".format(device, device.use))
for device in cuda:
print('~~~~~> Activating', device)
device.use = (device.type != 'CPU')
print("~~~~~> device {} usage status: {}".format(device, device.use))