Module Spoc_core.Profiling

Profiling State

val enabled : bool Stdlib.ref
val enable : unit -> unit
val disable : unit -> unit
val is_enabled : unit -> bool

Event-Based Timing

module type EVENT = sig ... end

Event handle - packages backend event with operations

type event = (module EVENT)
val create_event : Device.t -> event

Create a timing event on a device

val record_event : event -> unit

Record event (mark current point in stream)

val synchronize_event : event -> unit

Wait for event to complete

val destroy_event : event -> unit

Destroy event

Elapsed Time Measurement

module type EVENT_PAIR = sig ... end

Event pair for timing - packages start/stop with backend

type timer = (module EVENT_PAIR)
val create_timer : Device.t -> timer

Create a timer for measuring GPU operations

val timer_start : timer -> unit
val timer_stop : timer -> unit
val timer_elapsed_ms : timer -> float
val timer_destroy : timer -> unit

Convenience Timing Functions

val timed : Device.t -> (unit -> 'a) -> 'a * float

Time a GPU operation and return result with elapsed time in ms

val time : string -> Device.t -> (unit -> 'a) -> 'a

Time a GPU operation and print result

CPU-Side Timing

val cpu_timed : (unit -> 'a) -> 'a * float

Simple wall-clock timing for CPU operations

val cpu_time : string -> (unit -> 'a) -> 'a

Kernel Statistics

type kernel_stats = {
  1. name : string;
  2. mutable invocations : int;
  3. mutable total_time_ms : float;
}
val kernel_stats_table : (string, kernel_stats) Stdlib.Hashtbl.t
val record_kernel_invocation : name:string -> time_ms:float -> unit

Record a kernel invocation

val kernel_stats : unit -> kernel_stats list

Get all kernel statistics

val get_kernel_stats : string -> kernel_stats option

Get stats for a specific kernel

val reset_stats : unit -> unit

Reset all kernel statistics

val avg_time_ms : kernel_stats -> float

Average time per invocation

val print_stats : unit -> unit

Print kernel statistics summary

Scoped Profiling

val with_profiling : (unit -> 'a) -> 'a

Run function with profiling enabled, then restore previous state