How pc003/tensor_alloc works
tensor_alloc is a CPU tensor-memory allocator with a C API, aligned pooling, safe size-class selection, ownership checks, metrics, and event tracing. Its main workflow validates a tensor request, chooses a capacity, allocates and registers memory, then records metrics and tracing; freeing returns the block to the pool. A separate Python workflow collects and analyzes workload traces, builds training labels, trains a predictor, and evaluates it. The README documents learned prediction in the runtime; some internal wiring beyond the sampled API and predictor sources is not shown.
Main entry points: api.cpp Public allocator API · predictor_interface.h Predictor interface · collect_trace.py Workload collection · build_labels.py Label generation
Components 16
Allocator runtime
- Public allocator API
src/api.cpp - Request validation
src/request_validation.cpp - CPU memory pool
src/cpu_backend.cpp - Allocation registry
src/allocation_registry.cpp
Sizing policy
- Size classes
src/size_class.cpp - Predictor interface
src/predictor_interface.h - Learned tree inference
src/learned_predictor.cpp - Baseline fallback
src/predictor_fallback.cpp
Metrics and tracing
- Runtime metrics
src/metrics.cpp - JSONL trace recorder
src/trace_recorder.cpp
Trace and learning
- Workload collection
python/collect_trace.py - Trace analysis
python/analyze_trace.py - Label generation
python/build_labels.py - Predictor training
python/train_predictor.py - Policy evaluation
python/evaluate_predictor.py
Other components
- C/C++ caller
Connections 17
- C/C++ caller → Public allocator API: requests allocation
README.md - Public allocator API → Request validation: validates request
src/api.cpp - Public allocator API → Predictor interface: selects capacity
src/api.cpp - Predictor interface → Size classes: checks class
- Predictor interface → Baseline fallback: falls back
- Predictor interface → Learned tree inference: uses learned policy
README.md - Public allocator API → CPU memory pool: allocates or frees
src/api.cpp - Public allocator API → Allocation registry: registers ownership
src/api.cpp - Public allocator API → Runtime metrics: records metrics
src/api.cpp - Public allocator API → JSONL trace recorder: records events
src/api.cpp - C/C++ caller → Workload collection: generates workload
README.md - Workload collection → Trace analysis: produces trace for
README.md - Workload collection → Label generation: supplies trace to
README.md - Label generation → Predictor training: supplies dataset to
README.md - Label generation → Policy evaluation: supplies dataset to
README.md - Predictor training → Policy evaluation: supplies model to
README.md - Predictor training → Learned tree inference: exports predictor model
README.md