1
$\begingroup$

I am using blender 2.79, and I am trying to set up Cycles Compute Devices devices in system tab of user preferences menu in python console. What I can do is a list of available devices.

import _cycles
_cycles.available_devices()

and it shows an available device, but I can't find a way to set up this device in user preferences.

enter image description here

The setting I would like to change is marked by the red box.

$\endgroup$
1
$\begingroup$

In Blender 2.79 you can use:

import bpy

preferences = bpy.context.user_preferences
cycles_preferences = preferences.addons['cycles'].preferences
cuda_devices, opencl_devices = cycles_preferences.get_devices()

cycles_preferences.compute_device_type = "CUDA"

for device in cuda_devices:
    print('Activating {}'.format(device.name))
    device.use = True

In Blender 2.80 you can use:

import bpy

preferences = bpy.context.preferences
cycles_preferences = preferences.addons['cycles'].preferences
cuda_devices, opencl_devices = cycles_preferences.get_devices()

cycles_preferences.compute_device_type = "CUDA"

for device in cuda_devices:
    print(f'Activating {device.name}')
    device.use = True

Be aware that the script doesn't perform error handling for the case that the device isn't CUDA capable. You will get a TypeError with an OpenCL device.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.