Module Ocannl_tensor.Row

The row type, shape inference related types and constraint solving.

type axis_padding = Ir.Ops.axis_padding
val equal_axis_padding : axis_padding -> axis_padding -> Base.bool
val sexp_of_axis_padding : axis_padding -> Sexplib0.Sexp.t
val axis_padding_of_sexp : Sexplib0.Sexp.t -> axis_padding
type kind = [
  1. | `Batch
  2. | `Input
  3. | `Output
]
val equal_kind : kind -> kind -> Base.bool
val compare_kind : kind -> kind -> Base.int
val sexp_of_kind : kind -> Sexplib0.Sexp.t
val kind_of_sexp : Sexplib0.Sexp.t -> kind
val __kind_of_sexp__ : Sexplib0.Sexp.t -> kind
val hash_fold_kind : Ppx_hash_lib.Std.Hash.state -> kind -> Ppx_hash_lib.Std.Hash.state
val hash_kind : kind -> Ppx_hash_lib.Std.Hash.hash_value
val batch : kind
val input : kind
val output : kind
val is_batch : kind -> Base.bool
val is_input : kind -> Base.bool
val is_output : kind -> Base.bool
val batch_val : kind -> Base.unit Base.option
val input_val : kind -> Base.unit Base.option
val output_val : kind -> Base.unit Base.option
module Variants_of_kind : sig ... end
type dim_var
val equal_dim_var : dim_var -> dim_var -> Base.bool
val hash_fold_dim_var : Ppx_hash_lib.Std.Hash.state -> dim_var -> Ppx_hash_lib.Std.Hash.state
val hash_dim_var : dim_var -> Ppx_hash_lib.Std.Hash.hash_value
val compare_dim_var : dim_var -> dim_var -> Base.int
val sexp_of_dim_var : dim_var -> Sexplib0.Sexp.t
val dim_var_of_sexp : Sexplib0.Sexp.t -> dim_var
type proj_id
val equal_proj_id : proj_id -> proj_id -> Base.bool
val hash_fold_proj_id : Ppx_hash_lib.Std.Hash.state -> proj_id -> Ppx_hash_lib.Std.Hash.state
val hash_proj_id : proj_id -> Ppx_hash_lib.Std.Hash.hash_value
val compare_proj_id : proj_id -> proj_id -> Base.int
val sexp_of_proj_id : proj_id -> Sexplib0.Sexp.t
val proj_id_of_sexp : Sexplib0.Sexp.t -> proj_id
type dim_cmp
type dim_var_set = (dim_var, dim_cmp) Base.Set.t
val equal_dim_var_set : dim_var_set -> dim_var_set -> Base.bool
val sexp_of_dim_var_set : dim_var_set -> Sexplib0.Sexp.t
val dim_var_set_of_sexp : Sexplib0.Sexp.t -> dim_var_set
type 'a dim_map = (dim_var, 'a, dim_cmp) Base.Map.t
val equal_dim_map : ('a -> 'a -> Base.bool) -> 'a dim_map -> 'a dim_map -> Base.bool
val sexp_of_dim_map : ('a -> Sexplib0.Sexp.t) -> 'a dim_map -> Sexplib0.Sexp.t
val dim_map_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a dim_map
type proj_cmp
type proj_var_set = (proj_id, proj_cmp) Base.Set.t
val equal_proj_var_set : proj_var_set -> proj_var_set -> Base.bool
val sexp_of_proj_var_set : proj_var_set -> Sexplib0.Sexp.t
val proj_var_set_of_sexp : Sexplib0.Sexp.t -> proj_var_set
type 'a proj_map = (proj_id, 'a, proj_cmp) Base.Map.t
val equal_proj_map : ('a -> 'a -> Base.bool) -> 'a proj_map -> 'a proj_map -> Base.bool
val sexp_of_proj_map : ('a -> Sexplib0.Sexp.t) -> 'a proj_map -> Sexplib0.Sexp.t
val proj_map_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a proj_map
val get_var : ?name:Base.string -> Base.unit -> dim_var
val dim_var_set_empty : dim_var_set
val dim_map_empty : 'a dim_map
val proj_var_set_empty : proj_var_set
val proj_map_empty : 'a proj_map
val bcast_if_1 : Base.string

The reserved basis tag of the claim-free broadcast top. An axis tagged bcast_if_1 broadcasts to any size while it remains size 1 (1_(bcast_if_1) is the top of the broadcast order), and is an ordinary inert atom at sizes > 1. Scalars and rank-broadening fill carry it; a user may also write it deliberately as an explicit stretch-when-1 affordance.

val default_basis : Base.string

The basis tag the frontend supplies for any axis the user writes without naming a basis. It is an ordinary atom, incompatible with every other named basis (including bcast_if_1).

val is_reserved_basis : Base.string -> Base.bool

Whether a basis tag is one of the reserved (claim-free) tags default_basis / bcast_if_1, i.e. carries no user-meaningful naming claim.

type solved_dim = {
  1. d : Base.int;
  2. basis : Base.string;
  3. proj_id : proj_id Base.option;
}

A single axis in a shape. basis is the (total) semantic annotation on the dimension (e.g. "rgb" on a size-3 axis); two dimensions that must agree in size must also agree on basis. Unannotated user axes carry default_basis; the broadcast top carries bcast_if_1. proj_id is used for projection inference, and abused for provenance tracking during shape inference.

val equal_solved_dim : solved_dim -> solved_dim -> Base.bool
val hash_fold_solved_dim : Ppx_hash_lib.Std.Hash.state -> solved_dim -> Ppx_hash_lib.Std.Hash.state
val hash_solved_dim : solved_dim -> Ppx_hash_lib.Std.Hash.hash_value
val compare_solved_dim : solved_dim -> solved_dim -> Base.int
val sexp_of_solved_dim : solved_dim -> Sexplib0.Sexp.t
val solved_dim_of_sexp : Sexplib0.Sexp.t -> solved_dim
type convolution = {
  1. dilation : Base.int;
  2. kernel : dim;
  3. use_padding : Base.bool;
}

Convolution parameters. The offset is implicit, automatically derived. If use_padding is true, the offset is the left part of the dimensionality-preserving padding, (effective_kernel_span - 1) / 2, otherwise it is 0.

and dim =
  1. | Var of dim_var
  2. | Dim of solved_dim
  3. | Sym of sym_dim
    (*

    A symbolic dimension: a launch-time-bound extent (gh-490). During shape inference it is a rigid constant -- equal only to a Sym with the same static symbol; it never unifies with a concrete Dim (but the broadcast top 1_(bcast_if_1) broadcasts to it). It is materialized at its declared maximum extent (static_range) for Tnode dims and projections.

    *)
  4. | Affine of {
    1. stride : Base.int;
    2. over : dim;
    3. conv : convolution Base.option;
    4. stride_offset : Base.int;
    }
    (*

    An affine transformation of a dimension. When conv is None, this is a simple strided dimension. When conv is Some, this includes convolution parameters. Invariants: stride > 0, dilation > 0 (when present), 0 <= stride_offset, stride_offset < stride on an axis without a window, and stride_offset = 0 on an unpadded window; a padded window takes any offset, a tap moved past its margins reading the padding value. Shape refuses an einsum spec that breaks them (gh-ocannl-1618, gh-ocannl-1657).

    *)
  5. | Concat of dim Base.list
    (*

    Concatenation of multiple dimensions into a single axis.

    *)
and sym_dim = {
  1. sym : Ir.Indexing.static_symbol;
  2. sym_basis : Base.string;
  3. sym_proj_id : proj_id Base.option;
}
val equal_convolution : convolution -> convolution -> Base.bool
val equal_dim : dim -> dim -> Base.bool
val equal_sym_dim : sym_dim -> sym_dim -> Base.bool
val hash_fold_convolution : Ppx_hash_lib.Std.Hash.state -> convolution -> Ppx_hash_lib.Std.Hash.state
val hash_convolution : convolution -> Ppx_hash_lib.Std.Hash.hash_value
val hash_fold_dim : Ppx_hash_lib.Std.Hash.state -> dim -> Ppx_hash_lib.Std.Hash.state
val hash_dim : dim -> Ppx_hash_lib.Std.Hash.hash_value
val hash_fold_sym_dim : Ppx_hash_lib.Std.Hash.state -> sym_dim -> Ppx_hash_lib.Std.Hash.state
val hash_sym_dim : sym_dim -> Ppx_hash_lib.Std.Hash.hash_value
val compare_convolution : convolution -> convolution -> Base.int
val compare_dim : dim -> dim -> Base.int
val compare_sym_dim : sym_dim -> sym_dim -> Base.int
val sexp_of_convolution : convolution -> Sexplib0.Sexp.t
val sexp_of_dim : dim -> Sexplib0.Sexp.t
val sexp_of_sym_dim : sym_dim -> Sexplib0.Sexp.t
val convolution_of_sexp : Sexplib0.Sexp.t -> convolution
val dim_of_sexp : Sexplib0.Sexp.t -> dim
val sym_dim_of_sexp : Sexplib0.Sexp.t -> sym_dim
val get_dim : d:Base.int -> basis:Base.string -> ?proj_id:Base.int -> Base.unit -> dim

Mint a dimension with an explicit (required) basis tag.

val get_bcast_dim : d:Base.int -> ?proj_id:Base.int -> Base.unit -> dim

Mint the claim-free broadcast top d_(bcast_if_1) (at d = 1 the top of the broadcast order; at sizes > 1 an inert atom). Use at scalar / rank-broadening / GLB-demotion sites.

val get_default_dim : d:Base.int -> ?proj_id:Base.int -> Base.unit -> dim

Mint an unannotated user/derived atom d_(default).

val get_sym_dim : ?basis:Base.string -> ?proj_id:Base.int -> Ir.Indexing.static_symbol -> dim

Mint a symbolic dimension from a static-indexing symbol. The symbol must have a declared static_range (raises Utils.User_error otherwise): the range is the maximum extent, used to size allocations and projections until launch-time extent binding lands.

Session bookkeeping (gh-ocannl-1301)

val mutation_serial : Base.unit -> Base.int

Counts writes a failed construction can leave behind in the inference session; see Tensor.rewind_to_last_closure. Only note_mutation advances it.

val note_mutation : Base.unit -> Base.unit
val is_used_as_extent : Ir.Indexing.static_symbol -> Base.bool

Whether the symbol's extent role is committed or claimed since the last closure.

val is_used_as_slice : Ir.Indexing.static_symbol -> Base.bool
val claim_symbol_role : Ir.Indexing.static_symbol -> [ `Extent | `Slice ] -> Base.unit

Records a role claim; it reaches the symbol's flag at the next successful closure.

val commit_symbol_roles : commit:(Ir.Indexing.static_symbol -> [ `Extent | `Slice ] -> Base.unit) -> Base.unit

Hands every pending claim to commit -- Shape's Ir.Indexing.commit_role -- and empties the pending set.

val drop_symbol_roles : Base.unit -> Base.unit
val reset_transient : Base.unit -> Base.unit

Clears the solver's transient work state between solver calls.

type globals

The solver's module-level inference state -- the pending role claims, the safe-to-guess, use-site-resolution and concatenation-component sets, parameter-output checks, the rank graph and the template cache -- as persistent values (gh-ocannl-903).

val capture_globals : Base.unit -> globals

A pointer capture, O(1): what a checkpoint records.

val restore_globals : globals -> Base.unit

Puts a capture back, as part of a rewind.

val globals_differences : globals -> globals -> Base.string Base.list

The components that differ between two captures (physically), by name: a diagnostic.

val retire_closed_variables : Base.unit -> Base.unit

Empties the per-variable tables globals holds, all but the pending role claims, which commit_symbol_roles drains: the marks, the rank graph and the template cache (gh-ocannl-1859). Called by a successful closure, past every reader of its environment, and by a session reset: a closure leaves no open variable, and a scheme carries its own marks (marks_since), so what these tables hold about a closed variable is never asked for again. A session's solver state therefore grows with its open work, not with the graphs it has built. The setting debug_check_retired_solver_vars refuses a read of a retired variable, which an emptied table would answer with a silent "no".

val solver_census : Base.unit -> (Base.string * Base.int) Base.list

Each table of globals, by name, with its current size: a diagnostic (gh-ocannl-1859).

val rank_search_visits : Base.unit -> Base.int

The rank-cycle check's work counter since the last reset, process-wide (gh-ocannl-1802): the variables whose potentials it moved (gh-ocannl-1891), and under with_unbounded_rank_search the states the walk visited too.

val reset_rank_search_visits : Base.unit -> Base.unit

Runs the function with every new rank edge also walked from its target, as the check did before gh-ocannl-1802 and gh-ocannl-1891, and raises if the walk and the potentials disagree on whether the edge closes a positive cycle: a test's reference.

val row_visit_emissions : Base.unit -> Base.int

The inequalities the row solutions' visits of the entries bounded by them emitted since the last reset (gh-ocannl-1977): their work counter, process-wide.

val reset_row_visit_emissions : Base.unit -> Base.unit
val with_transitive_row_emissions : (Base.unit -> 'a) -> 'a

Restores the original row-visit emissions: the entry's GLB to the value, its other results to the value, and the value to its operands even for a bare variable (gh-ocannl-1977, gh-ocannl-2182). The store sweep and scheme_payoff use this reference, which stores the transitive closure of the row bounds.

val dim_cycle_visits : Base.unit -> Base.int

The variables the dimension-cycle search of Dim_ineq visited since the last reset (gh-ocannl-1891): its work counter, process-wide.

val reset_dim_cycle_visits : Base.unit -> Base.unit

Runs the function with the dimension-cycle search walking every path and repeating a recorded edge's search, as it did before gh-ocannl-1891: a test's reference, exponential in the residual connections of a body traced on unsized arguments.

val subst_visits : Base.unit -> Base.int

The environment entries solutions visited to substitute themselves since the last reset (gh-ocannl-1904): substitution's work counter, process-wide.

val reset_subst_visits : Base.unit -> Base.unit
val with_whole_env_substitution : (Base.unit -> 'a) -> 'a

Runs the function with every solution visiting the whole environment, as it did before gh-ocannl-1904 indexed the entries a solution can change: a test's reference, which leaves the same environments and constraints.

val with_substitution_cross_check : (Base.unit -> 'a) -> 'a

Runs the function with every solution cross-checked, as under the shape_substitution_cross_check setting: substituted both through the index and into the whole environment, failing (Failure, not a Shape_error) unless the two leave the same environment and emit the same constraints.

val substitution_cross_checked : Base.unit -> Base.bool

Whether solutions are cross-checked now: by the setting or with_substitution_cross_check.

val sym_dim_extent_exn : sym_dim -> Base.int

The maximum extent of a symbolic dimension: the declared range of its static symbol.

val dim_to_int_exn : dim -> Base.int
val vars_of_dim : dim -> dim_var_set
type print_style =
  1. | Only_bases
  2. | Axis_size
  3. | Axis_number_and_size
  4. | Projection_and_size
val equal_print_style : print_style -> print_style -> Base.bool
val compare_print_style : print_style -> print_style -> Base.int
val sexp_of_print_style : print_style -> Sexplib0.Sexp.t
val print_style_of_sexp : Sexplib0.Sexp.t -> print_style
val solved_dim_to_string : print_style -> solved_dim -> Base.string
val dim_to_string : ?var_to_string:(dim_var -> Base.string) -> print_style -> dim -> Base.string

var_to_string renders the dimension variables, nested ones included (default: $<id>).

type provenance
val sexp_of_provenance : provenance -> Sexplib0.Sexp.t
val provenance_of_sexp : Sexplib0.Sexp.t -> provenance
val compare_provenance : provenance -> provenance -> Base.int
val equal_provenance : provenance -> provenance -> Base.bool
val hash_fold_provenance : Ppx_hash_lib.Std.Hash.state -> provenance -> Ppx_hash_lib.Std.Hash.state
val hash_provenance : provenance -> Ppx_hash_lib.Std.Hash.hash_value
val provenance : sh_id:Base.int -> kind:kind -> provenance
val empty_provenance : provenance
val merge_provenance : provenance -> provenance -> provenance
type row_var
val sexp_of_row_var : row_var -> Sexplib0.Sexp.t
val row_var_of_sexp : Sexplib0.Sexp.t -> row_var
val compare_row_var : row_var -> row_var -> Base.int
val equal_row_var : row_var -> row_var -> Base.bool
val hash_fold_row_var : Ppx_hash_lib.Std.Hash.state -> row_var -> Ppx_hash_lib.Std.Hash.state
val hash_row_var : row_var -> Ppx_hash_lib.Std.Hash.hash_value
val get_row_var : Base.unit -> row_var
type bcast =
  1. | Row_var of row_var
    (*

    The row can be inferred to have more axes (between t.beg_dims and t.dims).

    *)
  2. | Broadcastable
    (*

    The shape does not have more axes of this kind, but is "polymorphic".

    *)

A bcast specifies how axes of a single kind in a shape (i.e. the row) can adapt to other shapes.

val equal_bcast : bcast -> bcast -> Base.bool
val hash_fold_bcast : Ppx_hash_lib.Std.Hash.state -> bcast -> Ppx_hash_lib.Std.Hash.state
val hash_bcast : bcast -> Ppx_hash_lib.Std.Hash.hash_value
val compare_bcast : bcast -> bcast -> Base.int
val sexp_of_bcast : bcast -> Sexplib0.Sexp.t
val bcast_of_sexp : Sexplib0.Sexp.t -> bcast
val row_var : row_var -> bcast
val broadcastable : bcast
val is_row_var : bcast -> Base.bool
val is_broadcastable : bcast -> Base.bool
val row_var_val : bcast -> row_var Base.option
val broadcastable_val : bcast -> Base.unit Base.option
module Variants_of_bcast : sig ... end
type t = {
  1. beg_dims : dim Base.list;
    (*

    The outer-left anchored flank; the first dimensions of the row. May be non-empty for both closed and open rows.

    *)
  2. dims : dim Base.list;
    (*

    The outer-right anchored flank; the last dimensions of the row. May be non-empty for both closed and open rows.

    *)
  3. bcast : bcast;
    (*

    Row_var v absorbs only the middle gap between beg_dims and dims; Broadcastable means no rank-broadening slack between the two anchored flanks.

    *)
  4. prov : provenance;
}
include Ppx_compare_lib.Equal.S with type t := t
val equal : t Base__Ppx_compare_lib.equal
include Ppx_hash_lib.Hashable.S with type t := t
val hash_fold_t : t Base__Ppx_hash_lib.hash_fold
val hash : t -> Base__Ppx_hash_lib.Std.Hash.hash_value
include Ppx_compare_lib.Comparable.S with type t := t
val compare : t Base__Ppx_compare_lib.compare
include Sexplib0.Sexpable.S with type t := t
val t_of_sexp : Sexplib0__.Sexp.t -> t
val sexp_of_t : t -> Sexplib0__.Sexp.t
val dims_basis_assoc : t -> (Base.string * dim) Base.list
val get_row_for_var : provenance -> row_var -> t
val row_shapes : t -> Base.int Base.list
type environment
val sexp_of_environment : environment -> Sexplib0.Sexp.t
type fixed_index_site = {
  1. spec : Base.string;
  2. kind : kind;
}

A fixed-index axis of an einsum spec, the only source of an At_least_dim bound.

val sexp_of_fixed_index_site : fixed_index_site -> Sexplib0.Sexp.t
val compare_fixed_index_site : fixed_index_site -> fixed_index_site -> Base.int
type dim_constraint =
  1. | Unconstrained_dim
  2. | At_least_dim of {
    1. d_min : Base.int;
    2. sites : fixed_index_site Base.list;
    }
    (*

    sites: the fixed-index axes the bound came from, carried on the bound (uncapped) for diagnostics; equality, comparison, hashing and the sexp ignore them (gh-ocannl-2044).

    *)
val equal_dim_constraint : dim_constraint -> dim_constraint -> Base.bool
val hash_fold_dim_constraint : Ppx_hash_lib.Std.Hash.state -> dim_constraint -> Ppx_hash_lib.Std.Hash.state
val hash_dim_constraint : dim_constraint -> Ppx_hash_lib.Std.Hash.hash_value
val compare_dim_constraint : dim_constraint -> dim_constraint -> Base.int
val sexp_of_dim_constraint : dim_constraint -> Sexplib0.Sexp.t
val unconstrained_dim : dim_constraint
val at_least_dim : d_min:Base.int -> sites:fixed_index_site Base.list -> dim_constraint
val is_unconstrained_dim : dim_constraint -> Base.bool
val is_at_least_dim : dim_constraint -> Base.bool
val unconstrained_dim_val : dim_constraint -> Base.unit Base.option
val at_least_dim_val : dim_constraint -> ([ `d_min of Base.int ] * [ `sites of fixed_index_site Base.list ]) Base.option
module Variants_of_dim_constraint : sig ... end
type total_elems =
  1. | Num_elems of Base.int
  2. | Range_elems of {
    1. lo : Base.int;
    2. hi : Base.int;
    }
    (*

    The total is any value in the inclusive range lo..hi. Arises only from substituting the solved variable of a round-up Strided_var (the leftover slack window); when the total is otherwise unconstrained, late stages prefer hi.

    *)
  3. | Strided_var of {
    1. coeff : Base.int Utils.safe_lazy;
    2. var : dim_var;
    3. denom : Base.int;
    4. round_up : Base.bool;
    }
    (*

    The total number of elements is (coefficient * variable) / denominator. When round_up, the variable is instead the ceiling of the division: solving for the variable from a known total n gives var = ceil(n * denom / coeff), i.e. the constraint tolerates a final partial block (coeff * (var - 1) < n * denom <= coeff * var). Minted only by the Uint4x32_to_prec constraint, where the last 128-bit random block may be consumed partially.

    *)
val equal_total_elems : total_elems -> total_elems -> Base.bool
val hash_fold_total_elems : Ppx_hash_lib.Std.Hash.state -> total_elems -> Ppx_hash_lib.Std.Hash.state
val hash_total_elems : total_elems -> Ppx_hash_lib.Std.Hash.hash_value
val compare_total_elems : total_elems -> total_elems -> Base.int
val sexp_of_total_elems : total_elems -> Sexplib0.Sexp.t
type row_constraint =
  1. | Unconstrained
  2. | Total_elems of {
    1. numerator : total_elems;
    2. divided_by : dim_var Base.list;
    3. keep_axis : Base.bool;
    }
    (*

    The rows, inclusive of the further row spec, have this many elements. The total is numerator / (product of divided_by variables). divided_by has multiset semantics - the same variable can appear multiple times. keep_axis means the constraint comes from a data terminal that prefers, when the constrained rows receive no other shape information, keeping a single dim-1 axis over closing the leftover row variable to the empty row ("identity reshape"); it is reset once the constraint is reduced by consuming axes or variables.

    *)
  3. | Exact of dim Base.list
    (*

    The concatenated rows have these axes.

    *)
val equal_row_constraint : row_constraint -> row_constraint -> Base.bool
val hash_fold_row_constraint : Ppx_hash_lib.Std.Hash.state -> row_constraint -> Ppx_hash_lib.Std.Hash.state
val hash_row_constraint : row_constraint -> Ppx_hash_lib.Std.Hash.hash_value
val compare_row_constraint : row_constraint -> row_constraint -> Base.int
val sexp_of_row_constraint : row_constraint -> Sexplib0.Sexp.t
type constraint_origin = {
  1. lhs_name : Base.string;
  2. lhs_kind : kind;
  3. rhs_name : Base.string;
  4. rhs_kind : kind;
  5. operation : Base.string Base.option;
}
val sexp_of_constraint_origin : constraint_origin -> Sexplib0.Sexp.t
type dim_entry =
  1. | Solved_dim of dim
  2. | Bounds_dim of {
    1. is_in_param : Base.bool;
    2. has_uniq_constr_unless : dim_var_set Base.option;
      (*

      If set, the variable should not be guessed 1 unless a variable from the set is also prevented from being guessed 1.

      *)
    3. res : dim_var Base.list;
    4. opnd : dim_var Base.list;
    5. glb : dim Base.option;
    6. constr : dim_constraint;
    7. origin : constraint_origin Base.list;
    }

An entry implements inequalities res ⊑ v ⊑ opnd and/or an equality v = solved. res and opnd must be sorted using the @@deriving compare comparison.

val sexp_of_dim_entry : dim_entry -> Sexplib0.Sexp.t
type row_entry =
  1. | Solved_row of t
  2. | Bounds_row of {
    1. is_in_param : Base.bool;
    2. res : row_var Base.list;
    3. opnd : row_var Base.list;
    4. glb : t Base.option;
    5. constr : row_constraint;
    6. origin : constraint_origin Base.list;
    }
val sexp_of_row_entry : row_entry -> Sexplib0.Sexp.t
type constraint_ =
  1. | Dim_eq of {
    1. d1 : dim;
    2. d2 : dim;
    3. origin : constraint_origin Base.list;
    }
  2. | Dim_size of {
    1. dim : dim;
    2. size : Base.int;
    3. origin : constraint_origin Base.list;
    }
    (*

    A numeric size without a basis claim. Stage1 checks solved axes and defers open ones; closure sizes an axis still open using its matching use-site basis, or default.

    *)
  3. | Row_eq of {
    1. r1 : t;
    2. r2 : t;
    3. origin : constraint_origin Base.list;
    }
  4. | Dim_ineq of {
    1. res : dim;
    2. opnd : dim;
    3. from_ : Base.Sexp.t;
    4. origin : constraint_origin Base.list;
    }
  5. | Row_ineq of {
    1. res : t;
    2. opnd : t;
    3. origin : constraint_origin Base.list;
    }
  6. | Dim_constr of {
    1. d : dim;
    2. constr : dim_constraint;
    3. origin : constraint_origin Base.list;
    }
  7. | Rows_constr of {
    1. r : t Base.list;
    2. constr : row_constraint;
    3. origin : constraint_origin Base.list;
    }
    (*

    The constraint applies to the concatenation of the rows. Note: broadcasting does not affect the constraint (i.e. there is no "subtyping", it resembles Row_eq).

    *)
  8. | Terminal_dim of Base.bool * dim * constraint_origin Base.list
    (*

    A terminal dimension with is_param flag indicating if it's a parameter requiring gradient.

    *)
  9. | Terminal_row of Base.bool * t * constraint_origin Base.list
    (*

    A row of the shape of a terminal tensor (i.e. a tensor that does not have sub-tensors). The bool flag indicates if it's a parameter requiring gradient.

    *)
  10. | Shape_row of t * constraint_origin Base.list
    (*

    A row of a shape of interest. The bool flag indicates if it's a parameter requiring gradient.

    *)
val compare_constraint_ : constraint_ -> constraint_ -> Base.int
val equal_constraint_ : constraint_ -> constraint_ -> Base.bool
val sexp_of_constraint_ : constraint_ -> Sexplib0.Sexp.t
val dim_eq : d1:dim -> d2:dim -> origin:constraint_origin Base.list -> constraint_
val dim_size : dim:dim -> size:Base.int -> origin:constraint_origin Base.list -> constraint_
val row_eq : r1:t -> r2:t -> origin:constraint_origin Base.list -> constraint_
val dim_ineq : res:dim -> opnd:dim -> from_:Base.Sexp.t -> origin:constraint_origin Base.list -> constraint_
val row_ineq : res:t -> opnd:t -> origin:constraint_origin Base.list -> constraint_
val dim_constr : d:dim -> constr:dim_constraint -> origin:constraint_origin Base.list -> constraint_
val rows_constr : r:t Base.list -> constr:row_constraint -> origin:constraint_origin Base.list -> constraint_
val terminal_dim : Base.bool -> dim -> constraint_origin Base.list -> constraint_
val terminal_row : Base.bool -> t -> constraint_origin Base.list -> constraint_
val shape_row : t -> constraint_origin Base.list -> constraint_
val is_dim_eq : constraint_ -> Base.bool
val is_dim_size : constraint_ -> Base.bool
val is_row_eq : constraint_ -> Base.bool
val is_dim_ineq : constraint_ -> Base.bool
val is_row_ineq : constraint_ -> Base.bool
val is_dim_constr : constraint_ -> Base.bool
val is_rows_constr : constraint_ -> Base.bool
val is_terminal_dim : constraint_ -> Base.bool
val is_terminal_row : constraint_ -> Base.bool
val is_shape_row : constraint_ -> Base.bool
val dim_eq_val : constraint_ -> ([ `d1 of dim ] * [ `d2 of dim ] * [ `origin of constraint_origin Base.list ]) Base.option
val dim_size_val : constraint_ -> ([ `dim of dim ] * [ `size of Base.int ] * [ `origin of constraint_origin Base.list ]) Base.option
val row_eq_val : constraint_ -> ([ `r1 of t ] * [ `r2 of t ] * [ `origin of constraint_origin Base.list ]) Base.option
val dim_ineq_val : constraint_ -> ([ `res of dim ] * [ `opnd of dim ] * [ `from_ of Base.Sexp.t ] * [ `origin of constraint_origin Base.list ]) Base.option
val row_ineq_val : constraint_ -> ([ `res of t ] * [ `opnd of t ] * [ `origin of constraint_origin Base.list ]) Base.option
val dim_constr_val : constraint_ -> ([ `d of dim ] * [ `constr of dim_constraint ] * [ `origin of constraint_origin Base.list ]) Base.option
val rows_constr_val : constraint_ -> ([ `r of t Base.list ] * [ `constr of row_constraint ] * [ `origin of constraint_origin Base.list ]) Base.option
val terminal_dim_val : constraint_ -> (Base.bool * dim * constraint_origin Base.list) Base.option
val terminal_row_val : constraint_ -> (Base.bool * t * constraint_origin Base.list) Base.option
val shape_row_val : constraint_ -> (t * constraint_origin Base.list) Base.option
module Variants_of_constraint_ : sig ... end
type error_trace = ..
type error_trace +=
  1. | Row_mismatch of t Base.list
  2. | Dim_mismatch of dim Base.list
  3. | Index_mismatch of Ir.Indexing.axis_index Base.list
  4. | Rows_constr_failed of {
    1. constr : row_constraint;
    }
  5. | Constraint_failed of constraint_
val sexp_of_error_trace : error_trace -> Base.Sexp.t
exception Shape_error of Base.string * error_trace Base.list
val with_origin_focus : (constraint_origin -> Base.bool) -> (Base.unit -> 'a) -> 'a

with_origin_focus focus f runs f with focus as the innermost relevance predicate on constraint origins (gh-ocannl-1903): where the solver merges two origin lists, the origins that focus accepts come first -- those of an enclosing focus next, then the rest, each group in arrival order -- and the max_shape_error_origins cap keeps the first ones. Shape focuses a shape-scheme trace and application on the scheme's own tensors.

type stage =
  1. | Stage1
  2. | Stage2
  3. | Stage3
  4. | Stage4
  5. | Stage5
  6. | Stage6a
  7. | Stage6b
  8. | Stage7

Removed duplicate helper functions

Stage 6 is two stages: in Stage6a rows that resolve at their use sites take their bounds and no operation result closes; in Stage6b the results close. A closing runs both, in order.

val sexp_of_stage : stage -> Sexplib0.Sexp.t
val stage_of_sexp : Sexplib0.Sexp.t -> stage
val equal_stage : stage -> stage -> Base.bool
val compare_stage : stage -> stage -> Base.int
val add_safe_to_guess : row_var -> Base.unit

Mark a row variable as allowed to be empty even if it's in a parameter.

val register_parameter_output : t -> constraint_origin Base.list -> Base.unit

Require an inferred parameter output to have axes; an explicit scalar rank stays valid.

val check_parameter_outputs : environment -> Base.unit

Validate registered parameter outputs after the closing stages.

val add_used_in_spec_or_compose : row_var -> Base.unit

Mark a row variable as used in an einsum spec or compose shape update. Meant specifically for input rows, to indicate that the variable should not be guessed empty when it ends up in a parameter.

val add_used_in_pointwise : row_var -> Base.unit

Mark a row variable as used in a pointwise shape update. Meant specifically for input rows, to indicate that the variable can be guessed empty when it ends up in a parameter.

val add_concat_component : dim_var -> Base.unit

Mark a dimension variable as naming a component of a concatenated einsum axis: closure refuses to guess it to dimension 1 (gh-ocannl-1656), including through aliases.

val add_resolve_at_use : row_var -> Base.unit

Mark a row variable as resolved by its use sites: at the final solver stages it may close to the GLB of its use sites' rows, acquiring axes its own arguments do not have. Unmarked variables close to an empty remainder instead — a use site broadcasts an operation result in but cannot silently widen it beyond its arguments' shapes (gh-ocannl-544). Registered automatically for terminal rows (leaf tensors and parameters) and for parameter-initialization cones; requested explicitly by the stretch operation.

val is_resolve_at_use : row_var -> Base.bool
val add_resolve_at_use_dim : dim_var -> Base.unit

The dim-level counterpart of add_resolve_at_use: a marked dimension variable may close to the GLB of its use sites; unmarked, unconstrained ones are guessed minimal (dim-1) instead. At_least_dim-constrained variables keep GLB closing regardless — direct indexing is a dim-carrying use.

val is_resolve_at_use_dim : dim_var -> Base.bool
val subst_row : environment -> t -> t
val unify_row : stage:stage -> constraint_origin Base.list -> (t * t) -> environment -> constraint_ Base.list * environment
val empty_env : environment
val get_dim_val : environment -> dim_var -> Base.int Base.option
val get_dim_from_env : environment -> dim_var -> dim Base.option

The variable's solution of any form (a concrete Dim, a symbolic Sym, ...), or None while it is unsolved (absent or only bounded). get_dim_val is its concrete-size projection.

val get_row_from_env : environment -> row_var -> t Base.option
val find_dim_entry : environment -> dim_var -> dim_entry Base.option

A dimension variable's entry: solved, or its bounds.

val find_row_entry : environment -> row_var -> row_entry Base.option

A row variable's entry: solved, or its bounds.

val unsolved_constraints : environment -> constraint_ Base.list
val add_zero_permissions : ?discardable_vars:dim_var_set -> ?emptiable_vars:dim_var_set -> ?non_zero_vars:dim_var_set -> environment -> environment

Register zero permissions in env, holding discardable_vars ⊆ emptiable_vars and refusing any non_zero_vars member already solved to 0 (gh-ocannl-2418).

val solve_inequalities : stage:stage -> ?discardable_vars:dim_var_set -> ?emptiable_vars:dim_var_set -> ?non_zero_vars:dim_var_set -> constraint_ Base.list -> environment -> constraint_ Base.list * environment

discardable_vars are safe for closure to guess dimension = 0 (and may be empty), used by Block specs where the component does not participate in projections. emptiable_vars may be bound to a stated or forced 0 by constraints and concatenation arithmetic, without licensing closure to guess them to 0 (gh-ocannl-2418). Every discardable variable is emptiable (discardable_vars is unioned into emptiable_vars on entry). non_zero_vars are variables appearing both as a concatenation component and as a required standalone or affine axis of a spec, overriding emptiable_vars / discardable_vars across shared captures and aliases. Concatenation arithmetic sizes no other component to 0 (gh-ocannl-2316).

val solve_closing_stages : stages:stage Base.list -> ?discardable_vars:dim_var_set -> constraint_ Base.list -> environment -> constraint_ Base.list * environment

solve_inequalities over stages in order, as one search over the stage-6 balanced-flank trials' overlaps (gh-ocannl-2154): the first run is the plain fold, so a store it accepts returns unchanged; when a run is refused, the last trial on its path short of its principal overlap is replayed one overlap larger, the earlier ones pinned, up to a bound. When no choice is left the first run's error is raised. Only a Shape_error rejects a run.

val trial_replays : Base.unit -> Base.int

The replays solve_closing_stages ran since the last reset: a work counter, process-wide.

val reset_trial_replays : Base.unit -> Base.unit
val row_to_bases : environment -> t -> Base.string Base.array
type proj
val compare_proj : proj -> proj -> Base.int
val equal_proj : proj -> proj -> Base.bool
val sexp_of_proj : proj -> Sexplib0.Sexp.t
val proj_of_sexp : Sexplib0.Sexp.t -> proj
type committed_padding = {
  1. padding : axis_padding;
  2. operand : Base.string;
    (*

    The operand's id and name, for the refusal.

    *)
  3. at_creation : Base.bool;
    (*

    The operand keeps an array it was given, so its layout committed at creation rather than at its first compilation or host access (Ir.Tnode.layout_at_creation).

    *)
}

The padding of an operand axis whose buffer layout is already committed (gh-ocannl-2041).

val sexp_of_committed_padding : committed_padding -> Sexplib0.Sexp.t
type proj_env
val sexp_of_proj_env : proj_env -> Sexplib0.Sexp.t
val fresh_row_proj : t -> t
val equal_modulo_proj : t -> t -> Base.bool

Row equality ignoring projection ids: they are scratch metadata each projection derivation re-mints (fresh_row_proj), not part of a row's committed content.

val populate_dim_proj_in_solved : environment -> environment
type proj_equation =
  1. | Proj_eq of proj * proj
    (*

    Two projections are the same, e.g. two axes share the same iterator.

    *)
  2. | Iterated of proj
    (*

    The projection needs to be an iterator even if an axis is not matched with another axis, e.g. for broadcasted-to axes of a tensor assigned a constant.

    *)
val compare_proj_equation : proj_equation -> proj_equation -> Base.int
val equal_proj_equation : proj_equation -> proj_equation -> Base.bool
val sexp_of_proj_equation : proj_equation -> Sexplib0.Sexp.t
val proj_equation_of_sexp : Sexplib0.Sexp.t -> proj_equation
val unsized_kernel_error : ?spec:Base.string -> use_padding:Base.bool -> dim_var -> dim -> Base.exn

The refusal of a window kernel nothing sized: what construction raises for one the spec and captures already condemn (gh-ocannl-1983), and projection derivation for the rest. spec names the einsum spec in the message.

val get_proj_equations : ?spec:Base.string -> constraint_ Base.list -> Ir.Indexing.axis_index dim_map -> environment -> proj_equation Base.list

spec is the step's einsum spec, for the refusal of a window kernel nothing sized.

val solve_proj_equations : ?clamp_padded:Base.bool -> proj_equation Base.list -> resolved_padding:(proj_id, committed_padding) Base.List.Assoc.t -> inferred_padding:(proj_id, axis_padding) Base.List.Assoc.t -> proj_env

resolved_padding is used for verification only: a padded window demanding more margins than a committed entry has is refused, naming that entry's operand. inferred_padding is updated in proj_env even if resolved_padding is present.

clamp_padded (default false, gh-504): the operation's accumulation identity is non-finite (max/tropical family), so its padded (=-mode) window projections register no margin demand (and skip the exceeds-resolved check): they lower with clamped window bounds — the assignments lowering guards the accumulation to the operand's valid range, an out-of-range position contributing the accumulation identity, which is the same as not visiting it.

val get_proj_index : proj_env -> proj -> Ir.Indexing.axis_index
val get_dim_index : proj_env -> dim -> Ir.Indexing.axis_index
val get_product_proj : proj_env -> dim -> (proj_id * Base.int) Base.option
val get_dim_padding : proj_env -> dim -> axis_padding Base.option

resolved_padding from proj_env is ignored (it is meant for verification only).

val proj_to_iterator_exn : proj_env -> proj_id -> Ir.Indexing.symbol

proj_to_iterator_exn proj_env p returns the iterator for p in proj_env. Raises Invalid_argument if p is not an iterator. Note that symbols go through substitution when lowering, so these iterators are not the same as the ones in the generated code.

val product_dim_iterators : proj_env -> (proj_id * Base.int * Ir.Indexing.symbol) Base.list

Iterated projections, including concat components with dim 1.

Shape-scheme support (gh-ocannl-404)

What Shape.Scheme needs to carry a trace's constraints past its rewind and rename them per application. Dimension and row variables share one counter, monotonic within the session's range and within the reserved range of with_reserved_vars.

val with_reserved_vars : (Base.unit -> 'a) -> 'a

Runs the function with row and dimension variables minted from a reserved range (an id-neutral window, gh-ocannl-1751): every variable it mints must be discarded with it.

val var_mark : Base.unit -> Base.int

The id of the most recently minted variable: a variable with a larger id was minted since.

val dim_var_id : dim_var -> Base.int
val row_var_id : row_var -> Base.int
val discardable_vars : environment -> dim_var_set
val emptiable_vars : environment -> dim_var_set
val non_zero_vars : environment -> dim_var_set
type renaming = {
  1. rn_dim : dim_var -> dim_var;
  2. rn_row : row_var -> row_var;
}
val rename_dim : renaming -> dim -> dim
val rename_row : renaming -> t -> t
val rename_constraint : renaming -> constraint_ -> constraint_

Every variable position of every constructor; static symbols stay rigid.

val constraint_vars : constraint_ -> dim_var Base.list * row_var Base.list
val row_vars : t -> dim_var Base.list * row_var Base.list
val add_constraint_origin : constraint_origin -> constraint_ -> constraint_

Prepends a provenance entry.

val map_draw_coefficients : f:(Base.int Utils.safe_lazy -> Base.int Utils.safe_lazy) -> constraint_ -> constraint_

Maps the coefficient of a packed conversion's draw: a round-up Strided_var total, which only Uint4x32_to_prec mints, whose coefficient is a lazy over its result node's precision.

val map_env_draw_coefficients : f:(Base.int Utils.safe_lazy -> Base.int Utils.safe_lazy) -> environment -> environment

map_draw_coefficients over the row constraints the environment's bounds hold.

val has_lazy_coefficient : constraint_ -> Base.bool

Whether the constraint holds a lazy Strided_var coefficient that is not a draw's: of unknown provenance. The product ties of capture references are constants.

type marks

The additions to the per-variable policy sets, parameter-output checks and symbol-role claims since a capture_globals.

val marks_since : ?parameter_is_used:(t -> Base.bool) -> globals -> marks
val add_marks : renaming -> marks -> Base.unit

Re-adds the marks through the sets' writers, renaming the variables.