Ir.Host_pinningBackend-agnostic sighting table for page-locking recurring host arrays (gh-ocannl-1854).
Tracks host arrays by their byte range from addr to addr + bytes:
true immediately without re-registering (even when smaller than min_bytes () or when min_bytes () = 0), so the caller still synchronises the stream on a sub-slice of a pinned parent.min_bytes (), or when min_bytes () <= 0, never sight or register new arrays.Bigarray.Genarray.t. The second transfer of that live array calls register ~addr ~bytes; if it returns Some token, the entry becomes registered and note_transfer returns true until finalisation, overlap eviction, or unregister_all. If register returns None, the entry is marked declined and never retried.live_bytes and unregistered update only after unregister succeeds. If unregister raises inside GC finalisation, overlap eviction, or unregister_all, the token, backing storage (when finalised), and live accounting stay queued for retry on the next note_transfer or unregister_all. The GC finaliser takes no lock, spins on nothing, and mutates no table.val sexp_of_stats : stats -> Sexplib0.Sexp.tRaised 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 tRecords 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.
Convenience wrapper returning with_transfer t nd (fun ~registered -> registered).
val unregister_all : 'token t -> unitRetries 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.