Created
March 3, 2023 20:48
-
-
Save redthing1/68ea855848a47249610608cffe642ee1 to your computer and use it in GitHub Desktop.
blender cycles CUDA render
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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