tinygrad directory layout
This explains the flow of a big graph down to programs.
Directories are listed in order of how they are processed.
tinygrad/kernelize
Group UOps into kernels.
get_kernelize_map
Function to transform the Tensor UOp graph into a version with Ops.KERNEL
Parameters:
-
sink
(UOp
)
–
The Ops.SINK rooting the Tensor graph.
Returns:
-
dict[UOp, UOp]
–
Map transforming each UOp in the sink to the Ops.KERNEL graph.
tinygrad/opt
Transforms the ast into an optimized ast. This is where BEAM search and heuristics live.
get_optimized_ast
Optimize an AST based on heuristics or BEAM search.
Parameters:
-
ast
(UOp
)
–
-
renderer
(Renderer
)
–
The renderer used to generate the code
Returns:
-
UOp
–
The Ops.SINK rooted AST transformed to apply the opts and with a KernelInfo in the arg.
tinygrad/codegen
Transform the optimized ast into a linearized list of UOps.
full_rewrite
Function to transform the Kernel UOp graph into a linearized program.
Parameters:
-
sink
(UOp
)
–
The Ops.SINK rooting the Kernel graph.
-
opts
(Renderer | None
, default:
None
)
–
The Renderer (can change how things are processed, fix this).
Returns:
tinygrad/renderer
Transform the linearized list of UOps into a program, represented as a string.
tinygrad/engine
Abstracted high level interface to the runtimes.
get_program
get_program(ast: UOp, renderer: Renderer) -> ProgramSpec
Transform an AST into a ProgramSpec. May trigger BEAM search.
Parameters:
-
ast
(UOp
)
–
-
renderer
(Renderer
)
–
The renderer used to generate the code
Returns:
-
ProgramSpec
–
The ProgramSpec of the program.