Python CUDA devices showing up as blank

I just updated from Blender 2.83 to 2.9 on my headless Ubuntu server, and it seems to have broken the ability to enable my GPUs using python.

The basic test script I’m running is

import bpy
prefs = bpy.context.preferences.addons['cycles'].preferences
devices = prefs.get_devices()
print(devices)

When I run it on my main workstation (Win10, Blender 2.9) I get the following

Updating device list
([<bpy_struct, CyclesDeviceSettings("GeForce GTX 1070")>, <bpy_struct, CyclesDeviceSettings("GeForce GTX 970 (Display)")>, <bpy_struct, CyclesDeviceSettings("Intel Core i7-6700K CPU @ 4.00GHz")>], [<bpy_struct, CyclesDeviceSettings("Intel Core i7-6700K CPU @ 4.00GHz")>])

This is what I am expecting, and everything works as planned.

When I run it on my headless Ubuntu 18.04 server with 2x Nvidia P106-100 cards, I get this:

([<bpy_struct, CyclesDeviceSettings("")>, <bpy_struct, CyclesDeviceSettings("")>, <bpy_struct, CyclesDeviceSettings("")>], [<bpy_struct, CyclesDeviceSettings("AMD FX(tm)-6350 Six-Core Processor")>])

It’s detecting the right amt of devices, but my 2 P106-100 and the CPU in the first array appear blank.

I’ve tried:

  • Rebooting
  • Loading factory default settings
  • Re-installing the Nvidia and Cuda drivers

Is there any way to manually trigger a device refresh?

Ok, so after beating my head against the wall for 2 streight days on this, I managed to figure it out in less than 5 minutes after posting, go figure.

Solution is to run

import bpy
prefs = bpy.context.preferences.addons['cycles'].preferences
prefs.compute_device_type = 'CUDA'
bpy.ops.wm.save_userpref()

and then separately run afterwards.

import bpy
prefs = bpy.context.preferences.addons['cycles'].preferences
devices = prefs.get_devices()
print(devices)

This gives me the correct result of:

([<bpy_struct, CyclesDeviceSettings("P106-100")>, <bpy_struct, CyclesDeviceSettings("P106-100")>, <bpy_struct, CyclesDeviceSettings("AMD FX(tm)-6350 Six-Core Processor")>], [<bpy_struct, CyclesDeviceSettings("AMD FX(tm)-6350 Six-Core Processor")>])