Module Ir.Resource_fault_injection

Test-only fault-injection points for resource-owning seams.

Production code calls hit at boundaries where an exception must leave resource ownership honest, passing the concrete artifact identity alongside the point (whose ownership_phase is derived exhaustively by phase_of_point). The default callback is a no-op and no configuration selects it. Tests install a callback with with_event_callback, with_callback, or with_sticky_async_fault.

The callback is per DOMAIN, like the Autotune.Seam hooks: hit calls the value installed in the calling domain, a scenario running in another domain neither reaches nor disturbs it, and a newly spawned domain starts with the no-op. That is sound because every injection point fires on the domain that called the operation (a Context transfer, compile or release, a schedule cache open, store or lookup) and none inside a task a scheduler enqueues, so the multidev_cc worker domains never reach one. A new point keeps that property: one placed in an enqueued task (a kernel or transfer task, as opposed to the routine-level schedule that only enqueues it) would fire on a worker domain and never reach the test's callback. resource_fault_injection_domains pins both halves.

type ownership_phase =
  1. | Before_allocate
  2. | After_allocate
  3. | Before_transfer
  4. | Before_await
  5. | Before_commit
  6. | Before_replay
  7. | Before_free
  8. | After_free
  9. | Before_launch
  10. | Capture_begin
  11. | Capture_launch
  12. | Capture_end
  13. | Capture_instantiate
  14. | Capture_replay
  15. | Teardown
val sexp_of_ownership_phase : ownership_phase -> Sexplib0.Sexp.t
val ownership_phase_of_sexp : Sexplib0.Sexp.t -> ownership_phase
val equal_ownership_phase : ownership_phase -> ownership_phase -> bool
type artifact =
  1. | Pool of {
    1. device_id : int;
    2. pool_id : int;
    3. constant : bool option;
    }
  2. | Merge_slab of {
    1. device_id : int;
    2. size_in_bytes : int;
    }
  3. | Routine of {
    1. name : string;
    }
  4. | Routine_segment of {
    1. routine : string;
    2. index : int;
    3. count : int;
    }
  5. | Context_handle of {
    1. device_id : int;
    }
  6. | Cache_file of {
    1. path : string;
    }
  7. | Graph_capture of {
    1. device_id : int;
    2. routine : string;
    3. key : string option;
    }
  8. | Scratch_frame of {
    1. device_id : int;
    2. bytes : int;
    }
val sexp_of_artifact : artifact -> Sexplib0.Sexp.t
val artifact_of_sexp : Sexplib0.Sexp.t -> artifact
val equal_artifact : artifact -> artifact -> bool
type point =
  1. | Delta_pool_before_allocate
    (*

    Immediately before a delta pool's allocation, under the same refusal handler as the allocation itself. The census records the pool after the allocation succeeds.

    *)
  2. | Delta_pool_allocated
  3. | Delta_unwind_before_free
  4. | Transfer_pool_allocated
  5. | From_host_before_copy
  6. | From_host_before_await
  7. | Init_from_device_before_await
  8. | Transfer_cleanup_before_await
  9. | To_host_before_copy
  10. | Merge_slab_before_allocate
  11. | Finalize_before_await
  12. | Finalize_before_free
  13. | Schedule_cache_before_lock
  14. | Schedule_cache_before_regime_commit
  15. | Schedule_cache_before_commit
  16. | Schedule_cache_before_replay
  17. | Autotune_before_winner_replay
  18. | Run_before_launch
  19. | Cuda_scratch_allocated
  20. | Cuda_scratch_freed
  21. | Graph_capture_begin
  22. | Graph_capture_launch
  23. | Graph_capture_end
  24. | Graph_capture_instantiate
  25. | Graph_capture_replay
  26. | Graph_exec_before_destroy
val sexp_of_point : point -> Sexplib0.Sexp.t
val point_of_sexp : Sexplib0.Sexp.t -> point
val equal_point : point -> point -> bool
val all_of_point : point list
type event = {
  1. point : point;
  2. phase : ownership_phase;
  3. artifact : artifact;
}
val sexp_of_event : event -> Sexplib0.Sexp.t
val event_of_sexp : Sexplib0.Sexp.t -> event
val equal_event : event -> event -> bool
val phase_of_point : point -> ownership_phase

Exhaustive ownership-phase classification for every fault-injection point.

val is_async_sync_point : point -> bool

true for asynchronous synchronization/await boundaries where persistent worker or stream errors are sticky by default (From_host_before_await, Init_from_device_before_await, Transfer_cleanup_before_await, Finalize_before_await).

exception Simulated_capture_error of string

Test-only exception injected at CUDA/HIP graph-capture points to exercise the same fallback path as a non-OOM driver capture error without linking vendor driver bindings into tests.

exception Simulated_graph_replay_oom of string

Test-only exception injected at Graph_capture_replay to exercise the same exec-drop and plain fallback path as an out-of-memory driver launch refusal.

val hit : artifact:artifact -> point -> unit
val with_event_callback : (event -> unit) -> f:(unit -> 'a) -> 'a

Installs a domain-local callback receiving both the ownership phase and the artifact identity for f, and restores the prior callback even when f raises.

val with_callback : (point -> unit) -> f:(unit -> 'a) -> 'a

Convenience wrapper over with_event_callback that passes event.point to the callback.

type sticky_fault

Domain-local sticky asynchronous fault handle. Once latched by its trigger point, every subsequent is_async_sync_point hit raises the same persistent exception until clear_sticky_fault is called.

val with_sticky_async_fault : trigger:point -> ?exn:exn -> (sticky_fault -> 'a) -> 'a

Installs a domain-local sticky asynchronous fault callback for f. When trigger fires, the fault latches and raises exn on trigger and on every subsequent is_async_sync_point hit until clear_sticky_fault is called. Restores the prior callback even when f raises.

val sticky_fault_hits : sticky_fault -> event list

Every event observed while sticky_fault was installed, in occurrence order.

val sticky_fault_triggered : sticky_fault -> bool

Whether sticky_fault is currently latched.

val clear_sticky_fault : sticky_fault -> unit

Clears a latched sticky fault so a subsequent retry can complete cleanly.

val pool_cap : default:int -> int

The working cap in the calling domain.

val with_pool_cap : int -> f:(unit -> 'a) -> 'a

Lowers the pool cap to at most the given byte count in the calling domain during f. The cap must be a positive power of two to preserve the link floor for page-rounded allocations. Otherwise raises Invalid_argument before entering f. An outer cap still applies to an inner scope. The prior cap is restored even when f raises.