1

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...

Shady Puck
  • 8,847
  • 6
  • 34
  • 61

2 Answers2

2

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)
pistiwique
  • 1,106
  • 9
  • 22
  • 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. – sambler Feb 21 '17 at 04:48
  • @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. – Shady Puck Feb 21 '17 at 23:35
  • 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. – sambler Feb 22 '17 at 00:45
  • @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? – Shady Puck Feb 22 '17 at 20:46
  • 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. – sambler Feb 23 '17 at 03:12
1

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'
Joel
  • 61
  • 1
  • 4