support emulate in the NullDevice

This commit is contained in:
George Hotz
2025-10-15 09:11:57 +08:00
parent 3a4a3e09ea
commit 0e06b5cbb6

View File

@@ -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)