Runtime Overview¤
Overview¤
A typical runtime consists of the following parts:
Compiled¤
The Compiled class is responsible for initializing and managing a device.
Compiled
¤
Allocator¤
The Allocator class manages memory on the device and caches allocated buffers for reuse.
Allocator
¤
Bases: Generic[DeviceType]
Methods:
-
_alloc– -
_copyin– -
_copyout– -
_encode_decode– -
_free– -
_map– -
_offset– -
_unmap– -
alloc– -
do_free– -
free– -
free_cache– -
map–
Attributes:
Program¤
The Program class is created for each loaded program. It is responsible for executing the program on the device. As an example, here is a CPUProgram implementation which loads program and runs it.
CPUProgram
¤
CPUProgram(dev: CPUDevice, obj: TinyELF)
Bases: Program['CPUDevice']
Methods:
Attributes:
Source code in tinygrad/runtime/ops_cpu.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
addr
instance-attribute
¤
addr = ctypes.windll.kernel32.VirtualAlloc(
ctypes.c_void_p(0),
ctypes.c_size_t(len(obj.lib)),
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE,
)
fxn
instance-attribute
¤
mem
instance-attribute
¤
mem = mmap.mmap(
-1,
len(obj.lib),
mmap.MAP_ANON
| mmap.MAP_PRIVATE
| (MAP_JIT if OSX else 0),
mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC,
)
__call__
¤
__call__(
*bufs: int,
global_size: tuple[int, int, int] = (1, 1, 1),
local_size: tuple[int, int, int] = (1, 1, 1),
vals: tuple[int | None, ...] = (),
wait: bool = False,
timeout: int | None = None
) -> float | None
Source code in tinygrad/runtime/ops_cpu.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
__del__
¤
__del__()
Source code in tinygrad/runtime/ops_cpu.py
75 76 77 78 | |
_load
¤
_load(lib, base=0)
Source code in tinygrad/runtime/ops_cpu.py
21 | |
Compiler¤
The Compiler class compiles the output from the Renderer and produces it in a device-specific format.
Compiler
¤
Compiler(cachekey: str | None = None)
Methods:
-
compile– -
compile_cached– -
compile_server– -
disassemble– -
server–
Attributes:
-
cachekey–
Source code in tinygrad/device.py
369 | |
compile
¤
Source code in tinygrad/device.py
370 | |
compile_cached
¤
Source code in tinygrad/device.py
371 372 373 374 375 376 | |
compile_server
¤
Source code in tinygrad/device.py
381 382 383 384 | |
disassemble
¤
disassemble(lib: bytes)
Source code in tinygrad/device.py
377 | |
server
¤
Source code in tinygrad/device.py
378 379 380 | |