For enabling the device for use, see bpy.context.user_preferences.system.compute_device_type
and
bpy.context.user_preferences.system.compute_device
.
To check these from a shell, put the python you wish to execute in a file and run
blender --background --python <file.py>
Or, more concisely for quick tests,
blender -b --python-expr 'import bpy; <python code here>'
For convenience, here's a script which will print the possible and current values of compute_device_type
and compute_device
:
import bpy
sysp = bpy.context.user_preferences.system
devt = sysp.compute_device_type
dev = sysp.compute_device
# get list of possible values of enum, see http://blender.stackexchange.com/a/2268/599
devt_list = sysp.bl_rna.properties['compute_device_type'].enum_items.keys()
dev_list = sysp.bl_rna.properties['compute_device'].enum_items.keys()
# pretty print
lines=[
("Property", "Value", "Possible Values"),
("Device Type:", devt, str(devt_list)),
("Device:", dev, str(dev_list)),
]
print("\nGPU compute configuration:")
for l in lines:
print("{0:<20} {1:<20} {2:<50}".format(*l))
If CUDA
shows up in the possible values for device type, then enabling the device should be as simple as doing something like this in python:
devt = sysp.compute_device_type = 'CUDA'
dev = sysp.compute_device = 'CUDA_0'
To find the identifier for the device, you can use the script above with a line to set compute_device_type
to CUDA
before getting the list of possible devices.
Once that's all enabled we must still tell cycles to actually use it; to do this set bpy.context.scene.cycles.device
to GPU
.