-1
$\begingroup$

I have a shared server with 8 RTX A5000s and am trying to enable GPUs allocated via CUDA_VISIBLE_DEVICES=... when running blender. The code I have so far is:

def enable_gpus():
    # Enable CUDA
    bpy.context.preferences.addons['cycles'].preferences.compute_device_type = "CUDA"
    # Enable GPUs
    for device in bpy.context.preferences.addons['cycles'].preferences.devices:
        print(device['name'])

which should just list out the available GPUs that blender is detecting, however this comes back blank with no print statements because there are supposedly no devices blender is finding to iterate through. Any ideas on how I can get this to work? I've tried making sure that cycles is enabled, and have tried different configurations of GPUs to make visible, and am not quite sure where to go from here to troubleshoot. On my own PC without CUDA_VISIBLE_DEVICES this code is correctly finding my GPUs.

Here is the server output from nvidia-smi: enter image description here

$\endgroup$
1
  • $\begingroup$ There's no d defined when you use it print(d['name']). I think you meant device instead of d $\endgroup$
    – Harry McKenzie
    Commented Jun 20 at 8:16

1 Answer 1

0
$\begingroup$

Your code is not executing. I know this because it contains errors. For example, the last line should show this error:

NameError: the name 'd' is undefined.

Because you are using device in the for statement, not d.

So you should see this error, if it is not true, then your code is not executing.

And the correct ask for devices will be like this:

bpy.context.preferences.addons['cycles'].preferences.get_devices_for_type('CUDA')
$\endgroup$
1
  • $\begingroup$ Thanks for pointing this out, it was a typo in my post. Your correct ask worked though. Is there documentation for this that I can find? $\endgroup$
    – Nick M.
    Commented Jun 20 at 21:58

You must log in to answer this question.

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