Runtime Overview¤
Overview¤
A typical runtime consists of the following parts:
Compiled¤
The Compiled
class is responsible for initializing and managing a device.
Compiled
¤
Compiled(
device: str,
allocator: Allocator,
renderer: Optional[Renderer],
compiler: Optional[Compiler],
runtime,
graph=None,
)
Methods:
-
synchronize
–Synchronize all pending operations on the device.
synchronize
¤
synchronize()
Synchronize all pending operations on the device.
This method ensures that all previously queued operations on the device have been completed before proceeding.
Allocator¤
The Allocator
class is responsible for managing memory on the device. There is also a version called the LRUAllocator
, which caches allocated buffers to optimize performance.
Allocator
¤
Methods:
LRUAllocator
¤
LRUAllocator()
Bases: Allocator
The LRU Allocator is responsible for caching buffers. It ensures that buffers are not freed until it is absolutely necessary, optimizing performance.
Methods:
-
alloc
– -
free
– -
free_cache
–
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
¤
Methods:
-
__call__
–
Attributes:
-
fxn
– -
helper_handle
– -
mem
–
Source code in tinygrad/device.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
helper_handle
class-attribute
instance-attribute
¤
helper_handle = CDLL(
find_library("System") if OSX else "libgcc_s.so.1"
)
mem
instance-attribute
¤
mem = mmap(
-1,
len(lib),
MAP_ANON | MAP_PRIVATE | MAP_JIT if OSX else 0,
PROT_READ | PROT_WRITE | PROT_EXEC,
)
__call__
¤
__call__(*bufs, vals=(), wait=False)
Source code in tinygrad/device.py
242 243 244 245 246 247 248 249 250 |
|
Compiler¤
The Compiler
class compiles the output from the Renderer
and produces it in a device-specific format.
Compiler
¤
Methods:
-
compile
– -
compile_cached
– -
disassemble
–
Attributes:
-
cachekey
–
Source code in tinygrad/device.py
257 |
|
compile
¤
Source code in tinygrad/device.py
258 |
|
compile_cached
¤
Source code in tinygrad/device.py
259 260 261 262 263 264 |
|