3
$\begingroup$

I would like to store and load the activation of CPU and GPU in the device types. In the python console could I find this path:

bpy.context.preferences.addons['cycles'].preferences.compute_device_type 

This shows the device type but I can't find the access to the active GPU or CPU.

Any idea?

enter image description here

$\endgroup$
2

1 Answer 1

3
$\begingroup$

This information is in the cycles addon preferences. As you know, access to the preferences for that addon can be found using bpy.context.preferences.addons["cycles"].preferences.

The cycles preference has a method get_devices that returns a list of tuples of CyclesDeviceSettings. The information you want is in the tuples in the individual entries. Here's some code that prints that information:

This, of course, is an undocumented API and may change from release to release. This works for 2.93.6

import bpy

deviceList = bpy.context.preferences.addons["cycles"].preferences.get_devices()
for deviceTuple in deviceList:
    print("Devices:")
    for device in deviceTuple:
        print(f"\t{device.name} ({device.type}) {device.use}")

It is left as an exercise for the reader to determine how the tuples are used. On my machine in 2.93.6 The output from that script is

Devices:
    GeForce GTX 1070 (CUDA) True
    Intel Core i7-7700HQ CPU @ 2.80GHz (CPU) False
Devices:
    Intel Core i7-7700HQ CPU @ 2.80GHz (CPU) False

The relevant source can be found, with developer extras enabled, by right clicking on the fields with the red arrows and selecting "edit source" from the menu. It is, um, enlightening.

$\endgroup$

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