4 releases
| new 0.6.2 | Feb 14, 2026 |
|---|---|
| 0.6.1 | Feb 13, 2026 |
| 0.6.0 | Feb 13, 2026 |
| 0.5.0 | Feb 11, 2026 |
#259 in Memory management
Used in 2 crates
66KB
1.5K
SLoC
edgefirst-tensor
Zero-copy tensor memory management for edge AI applications.
This crate provides a unified interface for managing multi-dimensional arrays (tensors) with support for different memory backends optimized for ML inference pipelines.
Memory Types
| Type | Description | Use Case |
|---|---|---|
| DMA | Linux DMA-BUF allocation | Hardware accelerators (GPU, NPU, video codecs) |
| SHM | POSIX shared memory | Inter-process communication, zero-copy IPC |
| Mem | Standard heap allocation | General purpose, maximum compatibility |
Features
- Automatic memory selection - Tries DMA → SHM → Mem based on availability
- Zero-copy sharing - Share tensors between processes via file descriptors
- Memory mapping - Efficient CPU access to tensor data
- ndarray integration - Optional conversion to/from
ndarray::Array(feature:ndarray)
Quick Start
use edgefirst_tensor::{Tensor, TensorMemory, TensorTrait, TensorMapTrait};
// Create a tensor with automatic memory selection
let tensor = Tensor::<f32>::new(&[1, 3, 224, 224], None, None)?;
println!("Memory type: {:?}", tensor.memory());
// Create with explicit memory type
let dma_tensor = Tensor::<u8>::new(&[1920, 1080, 4], Some(TensorMemory::Dma), None)?;
// Map tensor for CPU access
let mut map = tensor.map()?;
map.as_mut_slice().fill(0.0);
// Share via file descriptor (Unix only)
#[cfg(unix)]
let fd = tensor.clone_fd()?;
Platform Support
| Platform | DMA | SHM | Mem |
|---|---|---|---|
| Linux | Yes | Yes | Yes |
| macOS | No | Yes | Yes |
| Other Unix | No | Yes | Yes |
| Windows | No | No | Yes |
Feature Flags
ndarray(default) - Enablendarrayintegration for array conversions
Environment Variables
EDGEFIRST_TENSOR_FORCE_MEM- Set to1ortrueto force heap allocation
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Dependencies
~4.5–9.5MB
~202K SLoC