Skip to content

Instantly share code, notes, and snippets.

@redthing1
Created March 3, 2023 20:48
Show Gist options
  • Save redthing1/68ea855848a47249610608cffe642ee1 to your computer and use it in GitHub Desktop.
Save redthing1/68ea855848a47249610608cffe642ee1 to your computer and use it in GitHub Desktop.
blender cycles CUDA render
import bpy
def enable_gpus(device_type, use_cpus=False):
preferences = bpy.context.preferences
cycles_preferences = preferences.addons["cycles"].preferences
cuda_devices, opencl_devices = cycles_preferences.get_devices()
if device_type == "CUDA":
devices = cuda_devices
elif device_type == "OPENCL":
devices = opencl_devices
else:
raise RuntimeError("Unsupported device type")
activated_gpus = []
for device in devices:
if device.type == "CPU":
device.use = use_cpus
else:
device.use = True
activated_gpus.append(device.name)
cycles_preferences.compute_device_type = device_type
bpy.context.scene.cycles.device = "GPU"
return activated_gpus
enable_gpus("CUDA", use_cpus=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment