mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
* Make `dev` a property of `Allocator` (this is a prereq refactor for #10285) At least `BufferXfer.copy` accesses it assuming it's always present, currently most devices just add this property on their own repeating the same code over and over again. This is also a bit footguny, see `RemoteAllocator` that named this property `device` instead of `dev`, i could obviously just change that in one place but doing it globally seems like a better solution (and it reduces code duplication too). `MallocAllocator` is a bit special, but passing `None` works just fine. * typing * ignore type instead of cast
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
from tinygrad.device import Compiled, Compiler, Renderer, Allocator
|
|
from tinygrad.ops import Ops
|
|
from tinygrad.engine.jit import MultiGraphRunner
|
|
|
|
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
|
|
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']):
|
|
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
|
|
|
|
class NullDevice(Compiled):
|
|
def __init__(self, device:str): super().__init__(device, NullAllocator(self), NullRenderer(), Compiler(), NullProgram, NullGraph)
|