27 lines
1.1 KiB
Python
Raw Normal View History

2025-04-18 20:38:55 +09:00
from tinygrad.device import Compiled, Compiler, Renderer, Allocator
from tinygrad.uop.ops import Ops
from tinygrad.engine.jit import MultiGraphRunner
2025-04-18 20:38:55 +09:00
class NullRenderer(Renderer):
device = "NULL"
code_for_op = {k:lambda:None for k in [Ops.EXP2, Ops.LOG2, Ops.SIN, Ops.SQRT]}
has_local = False
2025-04-18 20:38:55 +09:00
def render(self, uops:list) -> str: return ""
class NullProgram:
def __init__(self, name:str, lib:bytes): pass
def __call__(self, *bufs, global_size:tuple[int,int,int]=(1,1,1), local_size:tuple[int,int,int]=(1,1,1), vals:tuple[int, ...]=(), wait=False):
return 1e-4
class NullAllocator(Allocator['NullDevice']):
2025-04-18 20:38:55 +09:00
def _alloc(self, size, options): pass
def _copyin(self, dest, src:memoryview): pass
def _copyout(self, dest:memoryview, src): pass
def _transfer(self, dest, src, sz:int, src_dev, dest_dev): pass
class NullGraph(MultiGraphRunner):
def __call__(self, input_rawbuffers, var_vals, wait=False) -> float|None: return 1e-3
2025-04-18 20:38:55 +09:00
class NullDevice(Compiled):
def __init__(self, device:str): super().__init__(device, NullAllocator(self), NullRenderer(), Compiler(), NullProgram, NullGraph)