Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD support #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions extras/enable_gpu.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# This code is derived from https://github.com/DLR-RM/BlenderProc/blob/main/blenderproc/python/utility/Initializer.py under a GPL-3.0 license.
# This code is in part derived from https://github.com/DLR-RM/BlenderProc/blob/main/blenderproc/python/utility/Initializer.py under a GPL-3.0 license.

import bpy
import logging

logger = logging.getLogger(__name__)

def enable_gpu(engine_name = 'CYCLES'):
compute_device_type = None
prefs = bpy.context.preferences.addons['cycles'].preferences
# Use cycles
def enable_gpu(engine_name='CYCLES', compute_device_type=None):

bpy.context.scene.render.engine = engine_name
bpy.context.scene.cycles.device = 'GPU'

preferences = bpy.context.preferences.addons['cycles'].preferences
for device_type in preferences.get_device_types(bpy.context):
preferences.get_devices_for_type(device_type[0])

for gpu_type in ['OPTIX', 'CUDA']:#, 'METAL']:
for gpu_type in ['OPTIX', 'CUDA', 'HIP']:#, 'METAL']:
found = False
for device in preferences.devices:
if device.type == gpu_type and (compute_device_type is None or compute_device_type == gpu_type):
bpy.context.preferences.addons['cycles'].preferences.compute_device_type = gpu_type
preferences.compute_device_type = gpu_type
logger.info('Device {} of type {} found and used.'.format(device.name, device.type))
found = True
break
if found:
break

# make sure that all visible GPUs are used
for device in prefs.devices:
for device in preferences.devices:
device.use = True
return prefs.devices
return preferences.devices