From 64c1d32fe254afe10c5978184b5c0f18dfa2a642 Mon Sep 17 00:00:00 2001 From: pvl-bot <136786582+pvl-bot@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:13:40 -0400 Subject: [PATCH] Add HIP support to enable_gpu --- extras/enable_gpu.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/extras/enable_gpu.py b/extras/enable_gpu.py index 724fe1b..8cb4cec 100644 --- a/extras/enable_gpu.py +++ b/extras/enable_gpu.py @@ -1,14 +1,12 @@ -# 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' @@ -16,11 +14,11 @@ def enable_gpu(engine_name = 'CYCLES'): 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 @@ -28,6 +26,6 @@ def enable_gpu(engine_name = 'CYCLES'): 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