From 459d0cd14fa05ce4e7b811b29365caba9973e575 Mon Sep 17 00:00:00 2001 From: Ignacio Sica Date: Thu, 13 Mar 2025 13:06:27 -0300 Subject: [PATCH] add arch to AMDRenderer and HIPRenderer (#9431) --- tinygrad/renderer/cstyle.py | 4 ++++ tinygrad/runtime/ops_amd.py | 2 +- tinygrad/runtime/ops_hip.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tinygrad/renderer/cstyle.py b/tinygrad/renderer/cstyle.py index 1a805fbbca..a8c7a95205 100644 --- a/tinygrad/renderer/cstyle.py +++ b/tinygrad/renderer/cstyle.py @@ -402,6 +402,10 @@ class AMDRenderer(CStyleLanguage): opts=("l0","l0","l0","l0","l1","u1","u1","u1"), swizzle=(((4,9,10,11,0),(1,2,3,5,6,7,8)), ((0,1,2,3,4),(9,10,11,5,6,7,8)))) for di,do in [(dtypes.half,dtypes.float),(dtypes.half,dtypes.half)]] + def __init__(self, arch:str): # gfx942 => MI300, gfx1100 => RX 7900 + self.tensor_cores, self.arch = AMDRenderer.tensor_cores, arch + def __reduce__(self): return self.__class__, (self.arch,) + # language options ockl = [(f"__ockl_get_{name}", "unsigned int", "size_t", "const") for name in ["local_id", "group_id", "local_size"]] ocml = [(f"__ocml_{name}_f{n}", f"{dt}, {dt}" if "fmax" == name else dt, dt, atr) diff --git a/tinygrad/runtime/ops_amd.py b/tinygrad/runtime/ops_amd.py index c01b5147d4..cb1856554a 100644 --- a/tinygrad/runtime/ops_amd.py +++ b/tinygrad/runtime/ops_amd.py @@ -704,7 +704,7 @@ class AMDDevice(HCQCompiled): self.sdma_queue = self.create_queue(kfd.KFD_IOC_QUEUE_TYPE_SDMA, 0x800000) - super().__init__(device, AMDAllocator(self), AMDRenderer(), AMDCompiler(self.arch), functools.partial(AMDProgram, self), + super().__init__(device, AMDAllocator(self), AMDRenderer(self.arch), AMDCompiler(self.arch), functools.partial(AMDProgram, self), AMDSignal, AMDComputeQueue, AMDCopyQueue) # Scratch setup diff --git a/tinygrad/runtime/ops_hip.py b/tinygrad/runtime/ops_hip.py index da957c3d95..412ddc0925 100644 --- a/tinygrad/runtime/ops_hip.py +++ b/tinygrad/runtime/ops_hip.py @@ -14,7 +14,7 @@ class HIPDevice(Compiled): self.device_id = int(device.split(":")[1]) if ":" in device else 0 self.arch = init_c_var(hip.hipDeviceProp_t(), lambda x: check(hip.hipGetDeviceProperties(x, self.device_id))).gcnArchName.decode() self.time_event_st, self.time_event_en = [init_c_var(hip.hipEvent_t(), lambda x: hip.hipEventCreate(ctypes.byref(x), 0)) for _ in range(2)] - super().__init__(device, HIPAllocator(self), HIPRenderer(), AMDCompiler(self.arch), functools.partial(HIPProgram, self)) + super().__init__(device, HIPAllocator(self), HIPRenderer(self.arch), AMDCompiler(self.arch), functools.partial(HIPProgram, self)) def synchronize(self): check(hip.hipSetDevice(self.device_id)) check(hip.hipDeviceSynchronize())