2024-03-18 01:12:16 +08:00
|
|
|
import ctypes
|
2024-05-11 02:22:31 +08:00
|
|
|
from tinygrad.device import Compiled, MallocAllocator
|
2024-05-11 12:40:02 +08:00
|
|
|
from tinygrad.renderer.cstyle import HIPRenderer
|
2024-03-18 01:12:16 +08:00
|
|
|
from tinygrad.runtime.ops_hsa import HSACompiler
|
|
|
|
|
|
|
|
rhip = ctypes.CDLL("/usr/local/lib/libremu.so")
|
|
|
|
class RHIPProgram:
|
|
|
|
def __init__(self, name:str, lib:bytes):
|
|
|
|
self.name, self.lib = name, lib
|
|
|
|
def __call__(self, *args, global_size, local_size, vals=(), wait=False):
|
|
|
|
args = (*args, *vals)
|
|
|
|
rhip.hipModuleLaunchKernel(self.lib, len(self.lib), *global_size, *local_size, 0, None, None,
|
|
|
|
len(args), (ctypes.c_void_p * len(args))(*[ctypes.cast(x, ctypes.c_void_p) for x in args]))
|
|
|
|
|
|
|
|
class RHIPDevice(Compiled):
|
|
|
|
def __init__(self, device:str=""):
|
|
|
|
self.device = int(device.split(":")[1]) if ":" in device else 0
|
2024-05-11 12:40:02 +08:00
|
|
|
super().__init__(device, MallocAllocator, HIPRenderer(), HSACompiler("gfx1100"), RHIPProgram)
|