Module Tolk_uop

Hash-consed DAG IR for the tolk compiler.

This module aggregates the uop layer: a single hash-consed node type (Uop.t) that flows through every stage of the pipeline — tensor graph, kernel AST, and linearized program — together with its operation tags, pattern DSL, stage specifications, and symbolic simplifier.

Structurally equal nodes are physically identical. Stage membership is not encoded in the type system; it is enforced by Spec validators at pass boundaries.

Usage

Open this module to bring every submodule into scope:

  open Tolk_uop

  let x = Uop.const_int 5
  let sum = Uop.alu_binary ~op:Ops.Add ~lhs:x ~rhs:(Uop.const_int 7)

  let pat =
    Upat.op ~src:[Upat.var "x"; Upat.const_int 0] Ops.Add

Modules

Core

  • Uop — the hash-consed node type, its smart constructors, view accessors, traversal, and rewrite engine.
  • Ops — the flat enumeration of operation tags. Declaration order is part of the public contract (drives commutative canonicalisation and toposort stability).
  • Render — tinygrad-shaped graph listings for debugging and golden tests.

Primitives

  • Dtype — value and pointer data types, promotion lattice, and float/integer truncation.
  • Const — typed compile-time constants.
  • Axis_type — classification of kernel loop axes (global, local, reduce, unroll, …) used during scheduling.

Patterns and rewriting

  • Upat — pattern DSL and matcher for writing rewrite rules over Uop.t.
  • Validate — deterministic memory-access validation used by Spec.
  • Spec — stage specifications used to validate that a DAG is well-formed at a given pipeline stage.
  • Symbolic — algebraic simplification rules wired into Uop.simplify.
module Ops : sig ... end

UOp operation tags.

module Axis_type : sig ... end

Kernel loop axis classification.

module Dtype : sig ... end

Data types for tensor computations.

module Const : sig ... end

Typed compile-time constants.

module Uop : sig ... end

Unified hash-consed DAG IR.

module Render : sig ... end

Tinygrad-shaped UOp graph rendering.

module Upat : sig ... end

Pattern DSL for matching and rewriting Uop nodes.

module Validate : sig ... end

Memory access validation for UOp specs.

module Spec : sig ... end

Structural validators for Uop DAGs.

module Symbolic : sig ... end

Symbolic simplification of the Uop IR.

module Divandmod : sig ... end

Integer division and modulo simplification.