Module Ir.Indexing

Symbols and projections used to lower tensor indexing.

type symbol =
  1. | Symbol of Base.int
val compare_symbol : symbol -> symbol -> Base.int
val equal_symbol : symbol -> symbol -> Base.bool
val sexp_of_symbol : symbol -> Sexplib0.Sexp.t
val symbol_of_sexp : Sexplib0.Sexp.t -> symbol
val hash_fold_symbol : Ppx_hash_lib.Std.Hash.state -> symbol -> Ppx_hash_lib.Std.Hash.state
val hash_symbol : symbol -> Ppx_hash_lib.Std.Hash.hash_value
val symbol : Base.int -> symbol
val is_symbol : symbol -> Base.bool
val symbol_val : symbol -> Base.int Base.option
module Variants_of_symbol : sig ... end
module Symbol : sig ... end
val get_symbol : Base.unit -> symbol
val discarding_symbols : (Base.unit -> 'a) -> 'a

discarding_symbols f runs f and then rewinds the symbol counter to where it was: for dry runs whose minted symbols are all discarded (a schedule probe), so they shift no later minted name. Sound only when no symbol f mints outlives it.

val symbol_ident : symbol -> Base.string
type 'a environment = 'a Base.Map.M(Symbol).t
val sexp_of_environment : ('a -> Sexplib0.Sexp.t) -> 'a environment -> Sexplib0.Sexp.t
val environment_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a environment
type static_symbol = private {
  1. static_symbol : symbol;
  2. mutable static_range : Base.int Base.option;
  3. mutable used_as_extent : Base.bool;
  4. mutable used_as_slice : Base.bool;
}

Private (gh-ocannl-1624): read and matched freely, built by make_static_symbol or get_static_symbol, and written only through the setters below. The roles (used_as_extent, used_as_slice) are shape-inference state of a caller-retained symbol: after its birth a role is written only by commit_role, which takes shape_writer. The declared range is not inference state; set_static_range writes it.

val compare_static_symbol : static_symbol -> static_symbol -> Base.int
val equal_static_symbol : static_symbol -> static_symbol -> Base.bool
val sexp_of_static_symbol : static_symbol -> Sexplib0.Sexp.t
val static_symbol_of_sexp : Sexplib0.Sexp.t -> static_symbol
val hash_fold_static_symbol : Ppx_hash_lib.Std.Hash.state -> static_symbol -> Ppx_hash_lib.Std.Hash.state
val hash_static_symbol : static_symbol -> Ppx_hash_lib.Std.Hash.hash_value
val make_static_symbol : ?static_range:Base.int -> ?used_as:[ `Extent | `Slice ] -> symbol -> static_symbol

A static symbol over symbol, holding the role used_as from birth (default: none). A role given at birth is not a write to a symbol anything else holds yet, so it needs no writer -- hand-built IR uses it for a symbolic extent no shape inference claimed.

val set_static_range : static_symbol -> Base.int Base.option -> Base.unit

Re-declares the symbol's range. The analysis caches key on it, so a changed range misses.

type 'a bindings =
  1. | Empty
  2. | Bind of static_symbol * (Base.int -> 'a) bindings
val sexp_of_bindings : ('a -> Sexplib0.Sexp.t) -> 'a bindings -> Sexplib0.Sexp.t
val bound_symbols : 'a bindings -> static_symbol Base.list
type ('r, 'idcs, 'p1, 'p2) variadic =
  1. | Result of 'r
  2. | Param_idx of Base.int Base.ref * (Base.int -> 'r, Base.int -> 'idcs, 'p1, 'p2) variadic
  3. | Param_1 of 'p1 Base.option Base.ref * ('p1 -> 'r, 'idcs, 'p1, 'p2) variadic
  4. | Param_2 of 'p2 Base.option Base.ref * ('p2 -> 'r, 'idcs, 'p1, 'p2) variadic
  5. | Param_2f : ('p2f -> 'p2) * 'p2f Base.option Base.ref * ('p2 -> 'r, 'idcs, 'p1, 'p2) variadic -> ('r, 'idcs, 'p1, 'p2) variadic
type unit_bindings = (Base.unit -> Base.unit) bindings
val sexp_of_unit_bindings : unit_bindings -> Sexplib0.Sexp.t
type lowered_bindings = (static_symbol, Base.int Base.ref) Base.List.Assoc.t
val sexp_of_lowered_bindings : lowered_bindings -> Sexplib0.Sexp.t
val apply : ('r, 'idcs, 'p1, 'p2) variadic -> 'r
val lowered_bindings : 'a bindings -> ('b, 'a, 'p1, 'p2) variadic -> lowered_bindings
val find_exn : lowered_bindings -> static_symbol -> Base.int Base.ref
val get_static_symbol : ?static_range:Base.int -> (Base.int -> 'a) bindings -> static_symbol * 'a bindings
val fresh_launch_param : Base.unit -> Base.int Base.ref

A launch parameter's cell as backend linking mints it: UNASSIGNED (gh-ocannl-940), holding a value outside every legal one, which validate_bound_value refuses naming the parameter. A caller assigns it through find_exn bindings sym := v; a caller that means 0 writes 0.

val launch_param_assigned : Base.int Base.ref -> Base.bool

Whether the cell holds a value someone assigned, rather than the one fresh_launch_param left there.

val validate_bound_value : ?width64:Base.bool -> static_symbol -> Base.int -> Base.unit

Bind-time validation of one launch-parameter value: refuses an unassigned one (gh-ocannl-940), a negative one, one outside the declared range (below range for an index, up to range inclusive for a symbolic extent) and, unless width64, one past the int32 index width.

val validate_lowered_bindings : ?width64:Base.bool -> lowered_bindings -> Base.unit

validate_bound_value over every parameter, reporting all the unassigned ones in one message first.

val set_launch_value : ?width64:Base.bool -> caller:Base.string -> lowered_bindings -> static_symbol -> Base.int -> Base.unit

set_launch_value ~caller bs sym v validates v (validate_bound_value) and writes it into sym's cell of bs; a symbol bs does not bind is refused, naming caller.

val resolve_launch_values : caller:Base.string -> hint:Base.string -> ranged:(static_symbol -> Base.string Base.option) -> (static_symbol * Base.int) Base.list -> static_symbol Base.list -> lowered_bindings

The launch values of a routine that a library entry point compiles and runs on the caller's behalf (gh-ocannl-1629): a fresh cell per symbol, the caller's values written into it (a symbol it does not bind, or given twice, is refused; the values themselves are validated by the run, once lowering has committed the role -- index or extent -- each is validated against), then every parameter left unassigned set to 0 -- unless ranged names its kind (a batch-slice index, a ranged static index, a symbolic extent), which is refused instead, naming each one and its kind and ending with hint: 0 is its first slice or empty extent, the silent default gh-ocannl-940 refuses. Hand the result to copy_launch_values once the routine is linked.

val copy_launch_values : from:lowered_bindings -> lowered_bindings -> Base.unit

copy_launch_values ~from bs writes into each cell of bs the value from holds for the same symbol; every symbol of bs must be bound by from.

val dims_to_string : ?with_axis_numbers:Base.bool -> Base.int Base.array -> Base.string
type affine_index = private {
  1. symbols : (Base.int * symbol) Base.list;
  2. offset : Base.int;
}
val compare_affine_index : affine_index -> affine_index -> Base.int
val equal_affine_index : affine_index -> affine_index -> Base.bool
val sexp_of_affine_index : affine_index -> Sexplib0.Sexp.t
type axis_index =
  1. | Fixed_idx of Base.int
  2. | Iterator of symbol
  3. | Affine of affine_index
  4. | Sub_axis
  5. | Concat of symbol Base.list
val compare_axis_index : axis_index -> axis_index -> Base.int
val equal_axis_index : axis_index -> axis_index -> Base.bool
val sexp_of_axis_index : axis_index -> Sexplib0.Sexp.t
val axis_index_of_sexp : Sexplib0.Sexp.t -> axis_index
val affine : symbols:(Base.int * symbol) Base.list -> offset:Base.int -> axis_index

Coalesce repeated symbols, remove zero terms, and use Fixed_idx or Iterator whenever possible. The private payload prevents bypassing this normalization.

val axis_index_mentions_symbol : symbol -> axis_index -> Base.bool
val axis_index_mentions_any : symbol Base.list -> axis_index -> Base.bool
type str_osym_map = (Base.string, symbol Base.option, Base.String.comparator_witness) Base.Map.t
type projections_debug = {
  1. spec : Base.string;
  2. derived_for : Base.Sexp.t;
  3. trace : (Base.string * Base.int) Base.list;
}
val sexp_of_projections_debug : projections_debug -> Sexplib0.Sexp.t
val projections_debug_of_sexp : Sexplib0.Sexp.t -> projections_debug
val unique_debug_id : Base.unit -> Base.int
type component = (Base.int * symbol) Base.list
val compare_component : component -> component -> Base.int
val equal_component : component -> component -> Base.bool
val sexp_of_component : component -> Sexplib0.Sexp.t
val component_of_sexp : Sexplib0.Sexp.t -> component
type projections = {
  1. components : component Base.array;
  2. lhs_dims : Base.int Base.array;
  3. rhs_dims : Base.int Base.array Base.array;
  4. project_lhs : axis_index Base.array;
  5. project_rhs : axis_index Base.array Base.array;
  6. extent_syms : (symbol Base.option * static_symbol) Base.list;
  7. debug_info : projections_debug;
}
val compare_projections : projections -> projections -> Base.int
val equal_projections : projections -> projections -> Base.bool
val sexp_of_projections : projections -> Sexplib0.Sexp.t
val projections_of_sexp : Sexplib0.Sexp.t -> projections
val iterated : Base.int -> Base.bool
val all_iterators : projections -> symbol Base.list
val iterator_sizes : projections -> Base.int Base.Map.M(Symbol).t
val coalesce_affine_terms : (Base.int * symbol) Base.list -> (Base.int * symbol) Base.list
val affine_injective : symbol_range:(symbol -> Base.int) -> axis_index Base.array -> Base.bool
val prod_project_for : projections -> dims:Base.int Base.array -> axis_index Base.array
val reflect_projection : dims:Base.int Base.array -> projection:axis_index Base.array -> axis_index
type variable_ref = private {
  1. ref_label : Base.string;
  2. mutable solved_dim : Base.int Base.option;
  3. mutable solved_sym : static_symbol Base.option;
}

Private (gh-ocannl-1573): read and matched freely, written only through the setters below. A solution is reached once: at most one of solved_dim, solved_sym is ever set, and a set field keeps its value. Shape inference is the only writer: the setters take shape_writer, which Shape holds, and its capture references wrap them with the session's accounting (gh-ocannl-1624). The cell is shared, so an Assignments.Embed_dim built before inference observes the solution it later reaches.

val sexp_of_variable_ref : variable_ref -> Sexplib0.Sexp.t
val equal_variable_ref : variable_ref -> variable_ref -> Base.bool
val variable_ref : Base.string -> variable_ref

A fresh, unsolved reference with the given label.

type shape_writer

The capability to write shape-inference state held by this module's records: solve a variable_ref, commit a static symbol's role (gh-ocannl-1624). A process has at most one: the first claim_shape_writer returns it and every later one raises. In a program linking the tensor frontend, Shape claims it as it initializes, so the setters taking it are Shape's alone -- a write through them could not skip the session's accounting (liveness of a rewound reference, the open set, the mutation serial).

val claim_shape_writer : Base.unit -> shape_writer

Returns the process's shape_writer; raises Utils.User_error when it was already claimed.

val set_solved_dim : shape_writer -> variable_ref -> Base.int -> Base.unit

Records a concrete solution. Setting the value it already holds is a no-op; a different value, or a reference already solved to a symbol, raises.

val set_solved_sym : shape_writer -> variable_ref -> static_symbol -> Base.unit

Records a symbolic-extent solution, guarded like set_solved_dim.

type variable_ref_snapshot

A reference's solution at a checkpoint, bound to that reference (gh-ocannl-903).

val snapshot_variable_ref : variable_ref -> variable_ref_snapshot
val restore_variable_ref : shape_writer -> variable_ref_snapshot -> Base.unit

Puts the recorded solution back on its reference -- unsolving it if it was unsolved: a rewind's write, so it takes the writer.

val variable_ref_snapshot_changed : variable_ref_snapshot -> Base.bool

Whether the reference's solution differs from the recorded one: a diagnostic.

val commit_role : shape_writer -> static_symbol -> [ `Extent | `Slice ] -> Base.unit

Sets the symbol's role flag. Committing the role it holds is a no-op; the other role raises (a binding cannot be validated both inclusively and strictly). Shape calls it only from a successful finish_inference, for the claims Row.claim_symbol_role counted.

module Doc_helpers : sig ... end