From 0e06b5cbb60d73647fd8bc8e7fecf12ddda3b4e7 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 15 Oct 2025 09:11:57 +0800 Subject: [PATCH] support emulate in the NullDevice --- tinygrad/runtime/ops_null.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tinygrad/runtime/ops_null.py b/tinygrad/runtime/ops_null.py index c8f5a6b59f..cd9779ebb1 100644 --- a/tinygrad/runtime/ops_null.py +++ b/tinygrad/runtime/ops_null.py @@ -1,9 +1,10 @@ import functools +from typing import cast from tinygrad.device import Compiled, Compiler, Allocator from tinygrad.engine.jit import MultiGraphRunner -from tinygrad.renderer.cstyle import CStyleLanguage +from tinygrad.renderer.cstyle import Renderer, CStyleLanguage, AMDRenderer from tinygrad.uop.ops import Ops -from tinygrad.helpers import cpu_profile +from tinygrad.helpers import cpu_profile, EMULATE class NullRenderer(CStyleLanguage): device = "NULL" @@ -29,5 +30,10 @@ class NullGraph(MultiGraphRunner): def __call__(self, input_rawbuffers, var_vals, wait=False) -> float|None: return 1e-3 class NullDevice(Compiled): - def __init__(self, device:str): super().__init__(device, NullAllocator(self), [(NullRenderer, Compiler)], functools.partial(NullProgram, device), - NullGraph) + def __init__(self, device:str): + renderer:functools.partial|type[Renderer] + match cast(str, EMULATE.value): + case "AMD": renderer = functools.partial(AMDRenderer, "gfx1100") + case "": renderer = NullRenderer + case _: raise RuntimeError(f"can't EMULATE device: {EMULATE.value}") + super().__init__(device, NullAllocator(self), [(renderer, Compiler)], functools.partial(NullProgram, device), NullGraph)