Module Spoc_core.Gpu_memory

Configuration

val auto_gc : bool Stdlib.ref

Whether to automatically retry allocations after GC on failure

val set_auto_gc : bool -> unit
val get_auto_gc : unit -> bool

Memory Tracking

val allocated_bytes : int Stdlib.Atomic.t

Total GPU memory currently allocated (bytes), across all devices

val alloc_count : int Stdlib.Atomic.t

Statistics counters

val free_count : int Stdlib.Atomic.t
val gc_free_count : int Stdlib.Atomic.t
val gc_freed_bytes : int Stdlib.Atomic.t
val retry_count : int Stdlib.Atomic.t
val peak_bytes : int Stdlib.Atomic.t
val track_alloc : int -> unit
val track_free : int -> unit
val track_gc_free : int -> unit

Decrement allocated bytes without counting as an explicit free (used by GC finalizers)

val usage : unit -> int

Query current GPU memory usage in bytes

val peak_usage : unit -> int

Query peak GPU memory usage in bytes

type stats = {
  1. current_bytes : int;
  2. peak_bytes : int;
  3. alloc_count : int;
  4. free_count : int;
  5. gc_free_count : int;
  6. gc_freed_bytes : int;
  7. retry_count : int;
}
val stats : unit -> stats

Get all statistics

val print_stats : unit -> unit

Print statistics to stderr

val reset_stats : unit -> unit

Reset all statistics (useful for per-benchmark tracking)

GC Integration

val trigger_gc : unit -> unit

Trigger a full major GC to free unreachable GPU buffers

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

Attempt an allocation, retrying after GC if it fails. On first failure: run Gc.full_major to trigger finalizers. On second failure: run Gc.compact for maximum cleanup. On third failure: propagate the exception.

Finalizer Registration

val register_finalizer : ('a, 'b) Vector_types.t -> unit

Register a finalizer on a vector to free device buffers when GC'd.