memkit-co
CPU-GPU memory coordination for the memkit ecosystem.
Version: 0.1.0-alpha.1
Overview
memkit-co is the coordination layer that bridges CPU memory management (memkit) with GPU memory management (memkit-gpu). It provides unified APIs for:
- Frame-based coordination — Allocate on CPU arena, auto-upload to GPU
- Staging pool management — Efficient staging buffer reuse
- Transfer scheduling — Batch and optimize CPU→GPU transfers
- Fence tracking — Track GPU work completion
- Pipeline synchronization — Double/triple buffering patterns
When to Use memkit-co
| Use Case | Crate |
|---|---|
| CPU-only allocation | memkit |
| GPU-only memory | memkit-gpu |
| CPU ↔ GPU coordination | memkit-co |
Quick Start
use ;
use DummyBackend;
// Create coordinator with default config
let config = default;
let mut coordinator = new;
// Allocate data on CPU, upload to GPU in one call
let vertices: & = &;
let gpu_buffer = coordinator.upload_slice?;
// Frame-based workflow
coordinator.begin_frame;
coordinator.end_frame?; // Commits all staged transfers
Architecture
┌─────────────────────────────────────────────────────────────┐
│ memkit-co │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Frame │ │ Staging │ │ Transfer │ │
│ │ Coordinator │ │ Pool │ │ Scheduler │ │
│ └──────┬──────┘ └──────┬──────┘ └──────────┬──────────┘ │
└─────────┼────────────────┼─────────────────────┼────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ memkit │ │ memkit-gpu │ │ memkit-gpu │
│ (CPU arenas) │ │ (staging bufs) │ │ (device bufs) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Features
Frame Coordinator
Manages per-frame CPU allocations that automatically sync to GPU:
// Frame-scoped allocation with automatic GPU upload
coordinator.begin_frame;
// Allocate transform matrices for this frame
let transforms = coordinator.;
for in transforms.iter_mut.enumerate
// Mark for GPU upload
let gpu_transforms = coordinator.stage_transforms?;
// End frame commits all pending transfers
coordinator.end_frame?;
Staging Pool
Reuses staging buffers to minimize allocation overhead:
// Acquire staging buffer from pool
let staging = coordinator.acquire_staging?;
// Write data
staging.write_data;
// Transfer and release back to pool
coordinator.transfer_and_release?;
Transfer Scheduler
Batches transfers for optimal GPU utilization:
// Queue multiple transfers
coordinator.queue_transfer;
coordinator.queue_transfer;
coordinator.queue_transfer;
// Submit all as single batch
coordinator.flush_transfers?;
Double/Triple Buffering
Built-in support for frame-pipelined uploads:
let coordinator = with_buffering;
// Coordinator automatically rotates buffers each frame
for frame in 0..1000
Integration with Other Crates
Standalone memkit-gpu
If you're using memkit-gpu without coordination needs:
use ;
let gpu = new;
// Direct GPU operations, no coordinator needed
Standalone memkit
If you're using memkit without GPU:
use MkFastArena;
let arena = new;
// CPU-only allocations
Full Stack with Coordinator
When you need coordinated CPU-GPU memory:
use MkCoordinator;
let coordinator = new;
// Coordinator internally uses both memkit and memkit-gpu
Configuration
use ;
let config = CoordinatorConfig ;
let coordinator = new;
Performance Tips
- Batch transfers — Queue multiple transfers, flush once per frame
- Reuse staging buffers — Use the staging pool instead of creating new buffers
- Frame arenas — Use frame allocations for temporary per-frame data
- Double buffering — Allows GPU to work on previous frame while CPU prepares next
License
Licensed under the Mozilla Public License 2.0.