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
¤
Allocator(
dev: DeviceType,
supports_copy_from_disk: bool = True,
supports_transfer: bool = True,
)
Bases: Generic[DeviceType]
Methods:
-
_alloc– -
_copyin– -
_copyout– -
_free– -
_map– -
_offset– -
_unmap– -
alloc– -
do_free– -
free– -
free_cache– -
map–
Attributes:
-
cache(dict[tuple[int, BufferSpec | None], list[BufferStorage]]) – -
default_buffer_spec(BufferSpec) – -
dev(DeviceType) – -
lru–
cache
instance-attribute
¤
cache: dict[
tuple[int, BufferSpec | None], list[BufferStorage]
] = defaultdict(list)
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
¤
fxn: Any = dev.remote.rpc(
RemoteCmd.LOAD_PROG, len(obj.lib), payload=obj.lib
)[0]
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
337 | |
compile
¤
compile(src: str) -> bytes
Source code in tinygrad/device.py
338 | |
compile_cached
¤
compile_cached(src: str) -> bytes
Source code in tinygrad/device.py
339 340 341 342 343 344 | |
compile_server
¤
compile_server(src: str, proc: Popen) -> bytes
Source code in tinygrad/device.py
349 350 351 352 | |
disassemble
¤
disassemble(lib: bytes)
Source code in tinygrad/device.py
345 | |
server
¤
server(cmd: str, arch: str, *args) -> Popen
Source code in tinygrad/device.py
346 347 348 | |