1
$\begingroup$

On Ubuntu 16.04 (used as a headless renderer with dual GTX 970 STRIX GPUs) after upgrading to blender 2.78b I'm now seeing:

$ blender -b Lightsaber.blend -o //Lightsaber-tst-1_ -E CYCLES -F PNG -x 1 -P cuda0.py -f 1
AL lib: (WW) alc_initconfig: Failed to initialize backend "pulse"
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
read blend: /home/shady/usermaatre/School/Lightsaber.blend
Traceback (most recent call last):
  File "/home/shady/usermaatre/School/cuda0.py", line 4, in <module>
    bpy.context.user_preferences.system.compute_device_type = 'CUDA'

The cuda0.py script is simple (it comes from BlenderArtists):

$ cat cuda0.py 
import bpy, _cycles

bpy.context.scene.cycles.device = 'GPU'
bpy.context.user_preferences.system.compute_device_type = 'CUDA'

# this is different in each cuda[x].py file, CUDA_0, CUDA_1, CUDA_2, CUDA_3
bpy.context.user_preferences.system.compute_device = 'CUDA_0'

I had been running NVIDIA-Linux-x86_64-367.44.run and cuda_7.5.18_linux.run so we tried upgrading to the latest NVIDIA-Linux-x86_64-375.39.run and cuda_8.0.61_375.26_linux.run but that did not help.

I figured maybe the CUDA card has been renamed, so I tried running the script at How do I get Cycles to use GPU on a linux server? and I get a similar result:

$ blender -b -P compute_device_type.py 
AL lib: (WW) alc_initconfig: Failed to initialize backend "pulse"
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
Traceback (most recent call last):
  File "/home/steven/usermaatre/School/compute_device_type.py", line 7, in <module>
    devt = sysp.compute_device_type
AttributeError: 'UserPreferencesSystem' object has no attribute 'compute_device_type'

Blender quit

I'm thinking that something has changed in the naming of the card? Is there a simple way to determine the card attributes? And should the 8.0 drivers work on a headless system or should I go back to 7.5? I'd really rather not have to drop back to 2.78a which had worked...

$\endgroup$

2 Answers 2

2
$\begingroup$

From the 2.78b, it's necessary to recover them via the preferences of the Cycles addon. You cant get it with

bpy.context.user_preferences.addon['cycles'].preferences.compute_device_type

And for the devices:

for card in bpy.context.user_preferences.addons['cycles'].preferences.devices:
    print(card.name)
$\endgroup$
5
  • $\begingroup$ Also of note - compute_device_type is an enum - so if you try compute_device_type = 'XXX' you will get a TypeError message that lists the valid enum values. $\endgroup$
    – sambler
    Feb 21, 2017 at 4:48
  • $\begingroup$ @sambler @pistiwique Thanks, I get enum "XXX" not found in ('NONE', 'CUDA') so setting prefs.compute_device_type = 'CUDA' works and both cards are used. I would also like to be able to address GPU0 & GPU1 separately, but prefs.compute_device = 'CUDA_0' fails. $\endgroup$
    – Shady Puck
    Feb 21, 2017 at 23:35
  • $\begingroup$ I haven't tested this but it appears that the devices list shown in the above loop, is what you use to enable/disable devices. Set compute_device_type = 'CUDA' and then use addons['cycles'].preferences.devices[0].use = False to disable the first device and devices[1] for the second. Each device has id, name, type and use properties. $\endgroup$
    – sambler
    Feb 22, 2017 at 0:45
  • $\begingroup$ @sambler thanks - prefs.devices[0].use = False worked! The above loop printed out <bpy_struct, CyclesDeviceSettings("GeForce GTX 970")> twice but I was not able to determine the deeper structure. How did you determine to set .use = False (where the old way was .compute_device = 'CUDA_0')? I wonder what other options might exist? $\endgroup$
    – Shady Puck
    Feb 22, 2017 at 20:46
  • $\begingroup$ I used the source @ShadyPuck ;) - You can find CyclesDeviceSettings defined in properties.py inside the cycles addon. I expect this is a simpler approach to controlling the many variations of different devices. It has just been added so expect more changes to come. $\endgroup$
    – sambler
    Feb 23, 2017 at 3:12
1
$\begingroup$

It seems this method doesnt work with 2.79? I get the error:

AttributeError: 'UserPreferences' object has no attribute 'addon'

Edit: Got it working! a stupid missing 's'

Here is the working script i'm using to force the worker station to use all cuda devices:

import bpy
bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
bpy.context.user_preferences.addons['cycles'].preferences.compute_device = 'CUDA_MULTI_2'
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .