Skip to content

Instantly share code, notes, and snippets.

@Ahanio
Created March 4, 2024 20:41
Show Gist options
  • Save Ahanio/ebe4ad7eb0fb15bd70d25f7492e31af9 to your computer and use it in GitHub Desktop.
Save Ahanio/ebe4ad7eb0fb15bd70d25f7492e31af9 to your computer and use it in GitHub Desktop.
import bpy
bpy.data.scenes[0].render.engine = "CYCLES"
# Set the device_type
bpy.context.preferences.addons[
"cycles"
].preferences.compute_device_type = "CUDA" # or "OPENCL"
# Set the device and feature set
bpy.context.scene.cycles.device = "GPU"
# get_devices() to let Blender detects GPU device
bpy.context.preferences.addons["cycles"].preferences.get_devices()
print(bpy.context.preferences.addons["cycles"].preferences.compute_device_type)
for scene in bpy.data.scenes:
scene.cycles.device = 'GPU'
for d in bpy.context.preferences.addons["cycles"].preferences.devices:
d["use"] = 1 # Using all devices, include GPU and CPU
print(d["name"], d["use"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment