diff --git a/installer.py b/installer.py index ef6ce44ba..aca36056b 100644 --- a/installer.py +++ b/installer.py @@ -549,6 +549,7 @@ def install_rocm_zluda(): log.warning("ZLUDA support: experimental") error = None from modules import zluda_installer + zluda_installer.set_default_agent(device) try: if args.reinstall_zluda: zluda_installer.uninstall() diff --git a/modules/devices.py b/modules/devices.py index 490d2a54d..49864e66b 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -4,6 +4,7 @@ import time import contextlib from functools import wraps import torch +from modules import rocm from modules.errors import log, display, install as install_traceback from installer import install @@ -283,16 +284,14 @@ def test_bf16(): if sys.platform == "darwin" or backend == 'openvino' or backend == 'directml': # override bf16_ok = False return bf16_ok - elif backend == 'zluda': - device_name = torch.cuda.get_device_name(device) - if device_name.startswith("AMD Radeon RX "): # only force AMD - device_name = device_name.replace("AMD Radeon RX ", "").split(" ", maxsplit=1)[0] - if len(device_name) == 4 and device_name[0] in {"5", "6"}: # RDNA 1 and 2 - bf16_ok = False - return bf16_ok - elif backend == 'rocm': - gcn_arch = getattr(torch.cuda.get_device_properties(device), "gcnArchName", "gfx0000")[3:7] - if len(gcn_arch) == 4 and gcn_arch[0:2] == "10": # RDNA 1 and 2 + elif backend == 'rocm' or backend == 'zluda': + gcn_arch = None + if backend == 'rocm': + gcn_arch = rocm.Agent.parse_gfx_version(getattr(torch.cuda.get_device_properties(device), "gcnArchName", "gfx0000")) + else: + from modules.zluda_installer import default_agent + gcn_arch = 0x0 if default_agent is None else default_agent.gfx_version + if gcn_arch < 0x1100: # all cards before RDNA 3 bf16_ok = False return bf16_ok try: diff --git a/modules/zluda_installer.py b/modules/zluda_installer.py index 506652edf..84c130e8d 100644 --- a/modules/zluda_installer.py +++ b/modules/zluda_installer.py @@ -4,7 +4,7 @@ import ctypes import shutil import zipfile import urllib.request -from typing import Optional +from typing import Optional, Union from modules import rocm @@ -15,12 +15,18 @@ DLL_MAPPING = { } HIPSDK_TARGETS = ['rocblas.dll', 'rocsolver.dll', f'hiprtc{"".join([v.zfill(2) for v in rocm.version.split(".")])}.dll'] ZLUDA_TARGETS = ('nvcuda.dll', 'nvml.dll',) +default_agent: Union[rocm.Agent, None] = None def get_path() -> str: return os.path.abspath(os.environ.get('ZLUDA', '.zluda')) +def set_default_agent(agent: rocm.Agent): + global default_agent # pylint: disable=global-statement + default_agent = agent + + def install(zluda_path: os.PathLike) -> None: if os.path.exists(zluda_path): return