Skip to main content

Module tensor_gc

Module tensor_gc 

Source
Expand description

Garbage collector for unreachable tensor allocations.

Identifies and collects unreachable tensor allocations using reference counting and reachability analysis from named roots. The collector implements a classic mark-and-sweep algorithm operating in three phases:

  1. MarkRoots — seed the reachable set with explicit roots and pinned tensors.
  2. Trace — BFS-expand the reachable set through dependency edges.
  3. Sweep — remove every tensor that is neither reachable nor ref-counted.

§Example

use ipfrs_tensorlogic::tensor_gc::{TensorGarbageCollector, TensorRef};

let mut gc = TensorGarbageCollector::new();

// Register two tensors: A depends on B.
gc.register(TensorRef {
    tensor_id: 1,
    name: Some("A".to_string()),
    size_bytes: 1024,
    ref_count: 0,
    dependencies: vec![2],
    pinned: false,
});
gc.register(TensorRef {
    tensor_id: 2,
    name: Some("B".to_string()),
    size_bytes: 512,
    ref_count: 0,
    dependencies: vec![],
    pinned: false,
});

// Make A a root; B is reachable through A's dependency edge.
gc.add_root(1);
let stats = gc.collect();
assert_eq!(stats.collected, 0);
assert_eq!(stats.reachable, 2);

Structs§

GcStats
Statistics produced at the end of a collection cycle.
TensorGarbageCollector
Mark-and-sweep garbage collector for tensor allocations.
TensorRef
Descriptor for a single tensor allocation tracked by the GC.

Enums§

GcPhase
The current phase of a mark-and-sweep garbage collection cycle.