Module Device.Graph
Backend interface for batched replay of a fixed call sequence.
A graph records a sequence of kernel launches and buffer copies once and replays them with a single dispatch, eliminating per-call launch overhead. The engine builds the node list, tracks node dependencies, and patches per-replay state (rebound buffer arguments, variable values, launch dimensions) through exec before each launch.
type node = | Kernel of {handle : nativeint;global : int array;(*Global launch dimensions (3 entries).
*)local : int array;(*Local launch dimensions (3 entries).
*)bufs : nativeint array;(*Buffer argument addresses.
*)vals : int array;(*Scalar arguments.
*)deps : int array;(*Indices of nodes this node must wait on.
*)
}| Copy of {dest : nativeint;(*Destination address.
*)src : nativeint;(*Source address.
*)nbytes : int;(*Copied byte count.
*)deps : int array;(*Indices of nodes this node must wait on.
*)
}(*One recorded call. Node indices follow build order.
*)
type exec = {set_buf : int -> int -> nativeint -> unit;(*
*)set_buf node pos addrstages buffer argumentposofnodetoaddr. ForCopynodes position0is the destination and position1the source.set_val : int -> int -> int -> unit;(*
*)set_val node idx vstages scalar argumentidxofnode.set_launch_dims : int -> global:int array -> local:int array -> unit;(*
*)set_launch_dims node ~global ~localstages new launch dimensions for kernelnode.set_params : int -> unit;(*
*)set_params nodecommits the staged state ofnodeinto the instantiated graph.launch : wait:bool -> float option;(*
*)launch ~waitreplays the graph. Returns the elapsed device time in seconds whenwaitistrueand the backend supports timing.
}An instantiated graph.