From 44d84228ff57c247e5ec86fb78e7501a06c26748 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Thu, 13 Nov 2025 20:05:54 -0800 Subject: [PATCH] move comgr_3 logic back to the old place (#13266) * move comgr_3 logic back to the old place * explicit --- .github/workflows/autogen.yml | 2 +- tinygrad/runtime/autogen/__init__.py | 4 +--- tinygrad/runtime/support/compiler_amd.py | 7 +++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/autogen.yml b/.github/workflows/autogen.yml index 98947c2a6e..6f58db8f5b 100644 --- a/.github/workflows/autogen.yml +++ b/.github/workflows/autogen.yml @@ -153,5 +153,5 @@ jobs: - name: Verify comgr (3) autogen run: | mv tinygrad/runtime/autogen/comgr_3.py /tmp/comgr_3.py.bak - python3 -c "from tinygrad.runtime.autogen import comgr" + python3 -c "from tinygrad.runtime.autogen import comgr_3" diff /tmp/comgr_3.py.bak tinygrad/runtime/autogen/comgr_3.py diff --git a/tinygrad/runtime/autogen/__init__.py b/tinygrad/runtime/autogen/__init__.py index b6c574b6bb..913118bb28 100644 --- a/tinygrad/runtime/autogen/__init__.py +++ b/tinygrad/runtime/autogen/__init__.py @@ -81,9 +81,7 @@ def __getattr__(nm): "/opt/rocm/include/hip/hiprtc.h", "/opt/rocm/include/hip/hip_runtime_api.h", "/opt/rocm/include/hip/driver_types.h"], args=["-D__HIP_PLATFORM_AMD__", "-I/opt/rocm/include", "-x", "c++"]) case "comgr" | "comgr_3": - try: use_3 = nm == "comgr_3" or int(system("dpkg-query -f '${version}' -W comgr")[1]) >= 3 - except FileNotFoundError: use_3 = nm == "comgr_3" - return load("comgr_3" if use_3 else "comgr", [ + return load("comgr_3" if nm == "comgr_3" else "comgr", [ "os.getenv('ROCM_PATH', '/opt/rocm')+'/lib/libamd_comgr.so'", "'/usr/local/lib/libamd_comgr.dylib'", "'/opt/homebrew/lib/libamd_comgr.dylib'" ], ["/opt/rocm/include/amd_comgr/amd_comgr.h"], args=["-D__HIP_PLATFORM_AMD__", "-I/opt/rocm/include", "-x", "c++"]) case "hsa": return load("hsa", ["os.getenv('ROCM_PATH', '/opt/rocm')+'/lib/libhsa-runtime64.so'", "find_library('hsa-runtime64')"], [ diff --git a/tinygrad/runtime/support/compiler_amd.py b/tinygrad/runtime/support/compiler_amd.py index b13a8279f5..ec7e004031 100644 --- a/tinygrad/runtime/support/compiler_amd.py +++ b/tinygrad/runtime/support/compiler_amd.py @@ -3,8 +3,11 @@ from tinygrad.helpers import system from tinygrad.runtime.autogen import comgr try: comgr.amd_comgr_get_version(ctypes.byref(major:=ctypes.c_uint64()), ctypes.byref(minor:=ctypes.c_uint64())) - assert comgr.AMD_COMGR_LANGUAGE_HIP == 3 if major.value >= 3 else 4 -except AttributeError: assert comgr.AMD_COMGR_LANGUAGE_HIP == 3 # if rocm is not installed, use old values + if major.value >= 3: + # in comgr 3 the values of enums in headers were changed: https://github.com/ROCm/llvm-project/issues/272 + import tinygrad.runtime.autogen.comgr_3 as comgr # type: ignore[no-redef] + assert comgr.AMD_COMGR_LANGUAGE_HIP == 3 +except AttributeError: pass # ignore if ROCm isn't installed from tinygrad.device import Compiler, CompileError from tinygrad.runtime.support.compiler_cpu import LLVMCompiler from tinygrad.helpers import OSX, to_char_p_p