Module Ir.Host_pinning

Backend-agnostic sighting table for page-locking recurring host arrays (gh-ocannl-1854).

Tracks host arrays by their byte range from addr to addr + bytes:

type 'token t
type stats = {
  1. registered : int;
  2. unregistered : int;
  3. declined : int;
  4. unregister_failures : int;
  5. live_bytes : int;
}
val sexp_of_stats : stats -> Sexplib0.Sexp.t
exception Overlap_eviction_failed of {
  1. addr : nativeint;
  2. bytes : int;
}

Raised by with_transfer / note_transfer when a transfer partially overlaps an active registration whose unregister failed, refusing to let the backend submit a mixed registered/unregistered copy.

val create : min_bytes:(unit -> int) -> register:(addr:nativeint -> bytes:int -> 'token option) -> unregister:('token -> unit) -> 'token t
val with_transfer : 'token t -> Ndarray.t -> (registered:bool -> 'a) -> 'a

Records a host-to-device transfer of nd and executes the transfer callback while guarding its byte range against overlapping pin-state mutations, passing ~registered:true iff nd is covered by a live registration for this transfer (including a registration whose rollback failed and remains pinned in the driver). When min_bytes () <= 0 and no array is registered, takes a zero-lock fast path; otherwise briefly acquires the table mutex to check/update range coverage and register the active transfer range, releases the mutex before running the callback (so disjoint multi-device transfers run concurrently through copy and stream synchronisation), and serialises only transfers or teardowns whose byte ranges overlap. Raises Overlap_eviction_failed if a partially overlapping registration could not be unregistered.

val note_transfer : 'token t -> Ndarray.t -> bool

Convenience wrapper returning with_transfer t nd (fun ~registered -> registered).

val unregister_all : 'token t -> unit

Retries any pending failed unregistrations and unregisters every currently live registered entry. Entries whose unregister succeeds are marked dead and removed; entries whose unregister raises remain retryable with their live accounting intact. Safe to call at process exit after device streams are idle.

val stats : _ t -> stats