Module Tolk.Postrange
Post-range kernel optimisation scheduler.
Wraps a kernel-stage Tolk_uop.Uop.t AST and applies optimisation passes (upcast, local, unroll, group, tensor core, padding, swap) that reshape the iteration space before expansion and devectorisation.
Types
Lifecycle
val create : Tolk_uop.Uop.t -> Renderer.t -> tcreate ast ren is a fresh scheduler for ast with renderer ren.
val apply_opt :
?append_opt:bool ->
t ->
Tolk_uop.Uop.Opt.t ->
(Tolk_uop.Uop.t * Tolk_uop.Uop.t) optionapply_opt t opt applies opt to t and returns Some (replaced_rng, new_rng) for shift_to opts, the first two TC axes as a pair for TC opts, or None otherwise. append_opt defaults to true.
Raises Opt_error on precondition failure.
val get_optimized_ast : ?name_override:string -> t -> Tolk_uop.Uop.tget_optimized_ast t finalises t: flattens ranges, generates a debug name, and returns the AST with updated kernel info.
Pipeline
val apply_opts :
?beam_search:(t -> t) ->
?hand_coded_optimizations:(t -> t) ->
Tolk_uop.Uop.t ->
Renderer.t ->
Tolk_uop.Uop.tval bufs_from_ast : Tolk_uop.Uop.t -> Tolk_uop.Uop.t listbufs_from_ast ast is the Param nodes of ast sorted by index.
Accessors
val ast : t -> Tolk_uop.Uop.tast t is t's current kernel AST.
val ren : t -> Renderer.tren t is t's renderer.
val applied_opts : t -> Tolk_uop.Uop.Opt.t listapplied_opts t is the opts applied so far.
Shape queries
val rngs : t -> Tolk_uop.Uop.t listActive ranges sorted by (axis kind, axis number).
val shape_len : t -> intNumber of active ranges.
val full_shape : t -> Tolk_uop.Uop.t listSize node of each active range.
val axis_types : t -> Tolk_uop.Axis_type.t listAxis kind of each active range.
val shape_str : t -> string listLabelled axis names ("g0"; "l0"; "r0"; …).
val shape_str_to_axis : t -> string list -> int listMap axis label names to indices. Raises Opt_error if not found.
val axes_of : t -> Tolk_uop.Axis_type.t list -> int listIndices of ranges whose kind is in the given list.
val ranges_of : t -> Tolk_uop.Axis_type.t list -> Tolk_uop.Uop.t listRanges whose kind is in the given list.
val upcastable_dims : t -> int listGlobal/Local/Loop axes with constant size > 1.
val unrollable_dims : t -> int listGroup_reduce/Reduce axes with constant size > 1.
val upcast_size : t -> intProduct of Upcast and Unroll shape sizes.
val output_shape : t -> Tolk_uop.Uop.t listfull_shape with reduce/unroll/group axes replaced by 1.
val upcasted : t -> intNumber of Upcast and Unroll axes.
val group_for_reduces : t -> intNumber of Group_reduce axes.
Queries
val reduceop : t -> Tolk_uop.Uop.t optionFirst Reduce node in the AST, if any.
val bufs : t -> Tolk_uop.Uop.t listIndex nodes in the AST, reversed.
val colored_shape : t -> stringDebug string of range sizes with axis-kind labels.
val range_int_size : Tolk_uop.Uop.t -> intConstant integer size of a range node, or 0.
val real_axis : t -> Tolk_uop.Uop.Opt.t -> int option -> intreal_axis t op axis resolves axis for op to a range index. Returns -1 when axis is None or op is TC.
Raises Opt_error on invalid axis.
Transforms
val convert_loop_to_global : t -> unitPromote eligible Loop ranges to Global.
val shift_to :
?top:bool ->
?input_new_rng:Tolk_uop.Uop.t ->
t ->
Tolk_uop.Uop.t ->
int ->
Tolk_uop.Axis_type.t ->
Tolk_uop.Uop.t * Tolk_uop.Uop.tshift_to t rng amount kind splits rng by amount. Returns (replaced_rng, new_rng). top defaults to false. Raises Opt_error if amount does not divide the range.