Skip to content
antonellofPublic

About

MARS (Memory for Autonomous Real-Time Systems): a GPU-resident memory store with episode scope, temporal decay and cross-modal traversal in one query API, for real-time embodied AI (autonomous vehicles, humanoid robots, AR/VR, voice agents).

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

40 Commits

Folders and files

Repository files navigation

MARS: Memory for Autonomous Real-Time Systems

Episode-scoped GPU retrieval for real-time embodied AI, with native temporal decay and cross-modal bridges.

CUDA C++ License Tests Paper DOI


The problem

A child's ball rolls into the road from behind a parked van. Vision sees only the ball. But 600 ms earlier the vehicle's microphones picked up children's voices from that direction. If that memory can be retrieved now, it raises the prior that a child will follow.

Embodied perception stacks usually know more than "find the nearest vector". They carry an active track id, a dialogue session, an AR room or a robot sub-task, and the answer almost always lies inside that episode. GPU vector-search libraries (FAISS, cuVS) rank by similarity over the whole index, and the application adds scope and recency with an ID filter or by post-processing on the host.

MARS puts scope, temporal decay and an optional cross-modal graph traversal into one GPU-side query call.

Signal In MARS Status
Episode scope RetrievalScope::EpisodeScoped restricts Stage 1 to the episode's member range Measured for latency; hit rate is 1.0 by construction on the benchmark
Temporal decay score × exp(-λ·age) before top-K Implemented; quality effect shown with a FAISS-based emulation
Cross-modal traversal NSN graph bridges via warp-cooperative BFS Implemented; no measured quality benefit in the ablation
Insertion Host-side staging buffer, graph re-uploaded before the next query No device-side append yet; not measured

Key results

All corpora are synthetic. The paper (PDF) is the authoritative source for every number below and says which rows have archived raw output.

Episode-scoped retrieval: about 0.2 ms from N=10K to N=1M

When the application supplies query_episode_id, Stage 1 covers only the episode's members and BFS is skipped, so the work falls from Θ(N·D) to Θ(|episode|·D). On an A100 SXM4 40 GB, kids-ball benchmark, paired probes:

N Global p99 Episode-scoped p99 Ratio Global hit@15
10K 0.349 ms 0.165 ms 2.1× 0.83
50K 0.462 ms 0.172 ms 2.7× 0.88
100K 0.551 ms 0.174 ms 3.2× 0.79
1M 2.561 ms 0.197 ms 13× 0.84

Three caveats:

  • The scoped hit@15 is 1.0 by construction: episodes have 10 nodes and K=15, so the scope is the answer set. This is a latency result.
  • The fair comparator is a filtered library search (FAISS with IDSelector, CAGRA filtered search). We have no valid measurement of it. The GPU flat index in FAISS 1.14.1 does not apply ID selectors, so an earlier "within ~1.3×" figure has been withdrawn.
  • A per-episode ring buffer with one small SGEMV is faster than the scoped path (0.12 ms in an earlier spot check).

Episode scope only applies when the right episode is known before the query. Both paths are available via --scope=episode|global.

Global-path scaling (cuBLAS + CUB, FP32)

A100 SXM4 40 GB, D=768, K=10, random embeddings:

Corpus Wall p99 Raw output archived
1K 0.31 ms yes
10K 0.44 ms yes
50K 0.56 ms yes
100K 0.74 ms no
1M 2.67 ms no (kids-ball global path at 1M: 2.5 to 2.6 ms)
10M 22.3 ms no
13M 29.1 ms no

The global path stays under 1 ms up to about N=100K. Against FAISS Flat on the same card with random embeddings, MARS is 1.5 to 1.7 times slower up to N=20K and at parity at N=50K.

An out-of-core tiled path streams tiles from host RAM for corpora larger than VRAM (a single 50M run took about 14 s, almost all PCIe transfer). It is an offline capacity extension.

Unfiltered FAISS and cuVS on the kids-ball benchmark

A100 SXM4 40 GB, 2026-04-17; the probe is an IMAGE node and a hit needs a same-episode TEXT and AUDIO vector in the top 15. Raw output: results/competitors_20260417/.

System (all unfiltered except the last) N=10K p99 / hit@15 N=100K p99 / hit@15 N=1M p99 / hit@15
FAISS Flat-GPU (exhaustive) 0.18 ms / 1.00 0.78 ms / 1.00 6.64 ms / 1.00
FAISS IVF-GPU (nprobe=64) 0.45 ms / 0.52 0.60 ms / 0.37 1.42 ms / 0.00
cuVS CAGRA (graph_degree=64) 3.32 ms / 1.00 3.23 ms / 0.01 3.25 ms / 0.00
MARS global (FP32 cuBLAS) 0.47 ms / 0.83 0.67 ms / 0.79 2.51 ms / 0.84
MARS global (FP16 fused) 0.28 ms / 0.83 0.66 ms / 0.79 3.73 ms / 0.84
MARS episode-scoped 0.19 ms / 1.00* 0.20 ms / 1.00* 0.20 ms / 1.00*

* by construction.

Kids-ball comparison

What this shows:

  • The scoped path is 33 times faster than an unfiltered exhaustive FAISS scan at N=1M. It says nothing about a filtered one.
  • Unfiltered IVF and CAGRA lose the episode at N ≥ 100K. That failure mode is known and is why filtered search exists. IVF still recovers 75% of the exact top 96 at N=1M, which suggests its partitions follow the per-slot direction in the synthetic corpus; this is untested.
  • The MARS global path is slower than FAISS Flat and has a lower hit rate at N=10K and 100K. The BFS re-ranking is the likely cause.

The kids-ball corpus is synthetic: 10-node episodes (three IMAGE, four AUDIO, three TEXT), same-episode cosine about 0.32, cross-episode cosine below 0.27. Real encoder outputs will behave differently, and a real-encoder run is the main missing experiment.

Episode-scoped scaling

See docs/BENCHMARKS.md for the per-GPU tables.


How it works

Pipeline

Text, audio, image, and sensor embeddings share a 768-D space as nodes in a multimodal graph with explicit cross-modal bridges. Two contracts share the same GPU-resident data:

Global path (when no episode handle is available): three stages, sub-millisecond at N ≤ 50K, zero per-query allocation.

  1. Stage 1 — Cosine + temporal decay. Default: cuBLAS Sgemv (FP32) followed by score × exp(-λ·age). Opt-in --use-fp16 switches to the hand-fused FP16 cosine kernel — wins by 41 % at N=10K but loses by 49 % at N=1M (see fig_fp16_crossover in the paper).
  2. Stage 2 — CUB radix sort top-K in O(N).
  3. Stage 3 — Warp-cooperative BFS — cross-modal graph expansion through NSN bridges with atomicCAS race-free neighbor claiming.

Episode-scoped fast path (when query_episode_id is supplied — embodied loops, AV per-track memory, voice-agent conversation): Stage 1 is restricted to the episode's CSR member list and Stage 3 BFS is skipped entirely. Latency stays near 0.2 ms p99 from N=10K to N=1M on the kids-ball benchmark (the green dashed arc in the diagram above). The hit rate on that benchmark is 1.0 by construction.


Quick start

git clone https://github.com/antonellof/MARS.git
cd MARS

make tests          # host-only unit tests (no GPU needed)
make                # full build
make check          # hardware validation → results/results.json
make demo-av        # 60 Hz AV perception demo
make bench-mars       # MARS benchmark sweep
make bench-ablation # NSN ablation study

On vast.ai / cloud GPU

git clone https://github.com/antonellof/MARS.git
cd MARS
make info && make && make check

Four application demonstrators

Demo Rate Budget Corpus Command
AV perception 60 Hz 1 ms 2,400 make demo-av
Humanoid robot 1 kHz 1 ms 10,000 make demo-robot
AR/VR spatial 90 Hz 5 ms 27,000 make demo-ar
Voice agent 30 Hz 20 ms 9,000 make demo-voice

All pass wall-clock p99 budgets on A100 and RTX 5060 Ti. Temporal decay constants: AV lambda=0.5 (2s window), robot lambda=0.1 (10s), AR lambda=0.003 (5min), voice lambda=1e-4 (30min).


Temporal decay and insertion experiments

Temporal relevance (simulated AV perception, 9K memories)

System TP@10 Stale rate Object recall
FAISS GPU Flat, cosine only 0.218 0.493 1.000
FAISS top-50 + decay re-rank (λ=0.5) 0.910 0.000 0.940

The decay score raises temporal precision and removes stale results, at some cost in object recall. The second row applies the MARS score to a FAISS shortlist. MARS itself was not run on this scenario; an earlier version of this table included a MARS row that this experiment did not produce.

Insertion

A FAISS deployment that rebuilds its index once per second returned nothing fresh for 93.2% of queries. That is a property of the rebuild cadence: FAISS Flat with per-frame add() has no such window. MARS currently stages inserts on the host and re-uploads the graph before the next query, which gives the same visibility at O(N) cost. There is no device-side append and no measured MARS insertion latency.


Comparison to similar projects

System GPU-resident Incremental insert ID / scope filter Temporal decay in ranking Cross-modal traversal
FAISS GPU (Flat/IVF) ✅ ✅ partial (CPU; GPU via cuVS path in recent releases) ❌ ❌
cuVS CAGRA ✅ ✅ (extend()) ✅ ❌ ❌
Milvus / Qdrant partial / ❌ ✅ ✅ ❌ ❌
MARS ✅ partial (host-side) ✅ ✅ ✅ (structural; no measured quality benefit)

An application can build any missing control on top of any of these systems. What MARS offers is the three controls behind one GPU-side call.


Future directions

Shipped on feature/landscape-2026-improvements (2026-04-17)

Feature Branch Status
Episode-scoped retrieval: RetrievalScope::EpisodeScoped restricts Stage 1 to episode members, skips BFS, about 0.2 ms at N=1M feature/landscape-2026-improvements Shipped, validated on A100
FP16 fused cosine — hand-fused FP16 + temporal-decay kernel; opt-in via --use-fp16 flag feature/landscape-2026-improvements Shipped, validated (wins at N≤10K, loses at N=1M — opt-in only)
Head-to-head competitor benchmarks — paired-RNG FAISS-GPU and cuVS CAGRA harness (scripts/bench_kids_ball_{faiss,cuvs_cagra}.py) feature/landscape-2026-improvements Shipped, see SUMMARY.md

In progress (feature branches)

Feature Branch Status
Binary persistence — checkpoint/restore MemoryGraph to disk with FNV-1a checksums feature/persistence Scaffolded + tests
Python bindings — pybind11 wrapper for MemoryGraph, NSN builder, NumPy interop feature/python-bindings Scaffolded + tests
Streaming insertion — pre-allocated ring buffer with batch commit + incremental NSN edges feature/streaming-insertion Scaffolded + tests
VRAM budget calculator — deterministic worst-case memory footprint for safety-critical deployment feature/memory-budget Scaffolded + tests
CUDA Graph capture — record 4-kernel pipeline as CUDA Graph for replay, eliminates launch overhead feature/cuda-graph-capture Scaffolded — known bug at memory_cuda.cu:1197 (counters not reset between replays); see docs/ARCHITECTURE.md §7.4
FP16 tensor-core (WMMA) — nvcuda::wmma kernel using tensor cores on V100+ — distinct from the shipped hand-fused FP16 above feature/fp16-tensor-core Scaffolded

Planned

  • cuBLAS epilogue fusion — fuse temporal decay into the SGEMV epilogue via cuBLASLt to eliminate the separate decay kernel
  • Multi-stream concurrent retrieval — CUDA streams with priority hints for parallel fast-control + slow-planning queries
  • Multi-GPU sharding — NVLink-based partitioning for corpora exceeding single-GPU HBM
  • Cross-modal hero demo — audio event in, visual + sensor context out in one query, sub-3 ms
  • Integration adapters — MARS as L1 cache beneath Milvus, nvblox, LangGraph
  • Learned importance — online-updated importance head conditioned on downstream task outcomes

Validation plan (vast.ai A100)

Each feature branch will be validated on vast.ai A100 SXM4 80 GB:

# 1. Persistence: save/load round-trip + latency overhead
make tests                          # host-only persistence tests
make bench-av                       # baseline
# save → load → bench-av            # verify no regression after reload

# 2. Streaming insertion: flush latency + query correctness during insert
make bench-av                       # baseline with static corpus
# streaming insert 1K nodes → re-bench → compare p99

# 3. VRAM budget: predicted vs actual
make check                          # compare budget prediction to cudaMemGetInfo

# 4. CUDA Graph: A/B comparison
make bench-graph                    # no-graph vs graph at N=10K, 50K

# 5. FP16 WMMA: tensor-core vs scalar FP16
make bench-wmma                     # FP32 vs FP16-scalar vs FP16-WMMA at N=10K, 50K

# 6. Full regression
make bench-av && make bench-robot && make bench-ar && make bench-voice
make bench-sustained && make bench-scale

Repository layout

include/
  memory_graph.h       Host-side CSR graph + NSN builder
  memory_cuda.cuh      CUDA kernel API + importance + novelty gate
  persistence.h        Binary checkpoint/restore with FNV-1a checksums
  streaming.h          Pre-allocated ring buffer for online insertion
  memory_budget.h      Deterministic VRAM budget calculator
  tiled_query.h        Out-of-core tiled retrieval for 50M+ corpus
  cuda_graph_capture.h CUDA Graph capture/replay management
  wmma_similarity.cuh  Tensor-core similarity kernel

src/
  memory_cuda.cu       CUDA kernels (similarity, temporal decay, top-K, BFS,
                       novelty gate, adaptive graph, importance)
  memory_graph.cpp     NSN construction (5 phases, configurable)
  persistence.cpp      Binary serialization with integrity verification
  streaming.cpp        Streaming insertion + incremental NSN edges
  memory_budget.cpp    VRAM budget computation
  tiled_query.cu       Out-of-core retrieval (host RAM -> GPU tiles)
  latency_bench.cu     Deadline-aware benchmark with --ablate and --recall
  validate.cu          JSON validation harness

python/                pybind11 bindings for MemoryGraph
demos/                 4 real-world demonstrators + AV visual demo
tests/                 Host-only unit tests (17 passing)
results/               Raw JSON from experiments
paper/                 MARS paper (LaTeX + PDF)
scripts/               FAISS comparison, figure generation, ablation parser
docs/                  Architecture, benchmarks, validation guides

Documentation


Citation

@misc{fratepietro2026mars,
  title     = {{MARS} ({M}emory for {A}utonomous {R}eal-{T}ime {S}ystems):
               Episode-Scoped {GPU} Retrieval for Real-Time
               Embodied {AI} with Native Temporal Decay and
               Cross-Modal Bridges},
  author    = {Fratepietro, Antonello},
  year      = {2026},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.24622392},
  url       = {https://doi.org/10.5281/zenodo.24622392}
}

License

MIT — see LICENSE.

Author

Antonello Fratepietro

About

MARS (Memory for Autonomous Real-Time Systems): a GPU-resident memory store with episode scope, temporal decay and cross-modal traversal in one query API, for real-time embodied AI (autonomous vehicles, humanoid robots, AR/VR, voice agents).

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages