Module Ir.Compile_cost

Where a compile's host wall time goes (gh-ocannl-1314).

A domain-local census of the phases of Backends' compile and link, bracketed like the codegen censuses (C_syntax.with_census): each phase is timed where it runs and added to the innermost enclosing with_census, and a bracket's totals are added to the bracket around it when it closes, so an outer bracket counts what an inner one saw exactly once. Outside any bracket the recording functions do nothing but run their thunk.

What each field covers:

A host wall-clock reading for diagnosis, not a timing claim.

type t = {
  1. lower_s : float;
  2. transform_s : float;
  3. backend_compile_s : float;
  4. device_s : float option;
  5. kernels : int;
  6. kernels_compiled : int;
  7. kernels_reused : int;
  8. pipelines_created : int;
  9. pipeline_s : float;
  10. reuse_capable : bool;
}
val sexp_of_t : t -> Sexplib0.Sexp.t
val empty : t
val codegen_s : t -> float

backend_compile_s less device_s (taken as 0 when None): rendering and the backend's own bookkeeping around the vendor compile.

val total_s : t -> float

The sum of the disjoint phases: lower_s +. transform_s +. backend_compile_s +. link_s.

val add : t -> t -> t

Field-wise sum; device_s is None only when both are, reuse_capable is the disjunction.

val with_census : (unit -> 'a) -> 'a * t

with_census f runs f with a fresh census and returns what it recorded. The enclosing census, if any, is restored and also receives these totals. When f raises, the enclosing census still receives them and the exception propagates.

val time_lower : (unit -> 'a) -> 'a
val time_transform : (unit -> 'a) -> 'a
val time_backend_compile : (unit -> 'a) -> 'a
val time_device : (unit -> 'a) -> 'a
val time_pipeline : (unit -> 'a) -> 'a

Times pipeline_s, inside a time_link.

Times link_delta_s; it runs inside a time_link, which counts the same seconds in link_s.

val record_kernels : rendered:int -> compiled:int -> unit

Adds a compile's kernel counts.

val record_kernels_reused : int -> unit

Adds kernels a compile took from code an earlier compile published (kernels_reused).

val record_pipeline_created : unit -> unit

Counts one pipeline object created at link (pipelines_created).

val record_reuse_capable : unit -> unit

Marks the bracket as having compiled through a kernel code cache, enabled or not.