morok_device/lib.rs
1//! Device abstraction layer for tensor operations.
2//!
3//! This module provides a clean abstraction over different compute devices (CPU, CUDA, etc.)
4//! with support for:
5//! - Lazy buffer allocation
6//! - Buffer views with zero-copy slicing
7//! - LRU caching of allocations for performance
8//! - Device-agnostic copy operations
9//!
10//! # Examples
11//!
12//! ```no_run
13//! use morok_device::allocator::BufferOptions;
14//! use morok_device::{Buffer, registry};
15//! use morok_dtype::DType;
16//!
17//! // Get a CPU device
18//! let cpu = registry::cpu().unwrap();
19//!
20//! // Create a buffer with lazy allocation
21//! let buffer = Buffer::new(cpu, DType::Float32, vec![10, 10], BufferOptions::default());
22//!
23//! // Allocation happens on first use
24//! buffer.ensure_allocated().unwrap();
25//! ```
26
27pub mod allocator;
28pub mod buffer;
29pub mod device;
30pub mod error;
31pub mod queue;
32pub mod registry;
33pub mod sync;
34
35pub use buffer::{Buffer, BufferId};
36pub use error::{Error, Result};
37pub use queue::{DynQueue, ExecParams, HardwareQueue, Program, QueueFactory};
38pub use sync::{CpuTimelineSignal, TimelineSignal};
39
40#[cfg(test)]
41mod test;
42
43// Re-export commonly used types
44#[cfg(feature = "cuda")]
45pub use allocator::CudaAllocator;
46pub use allocator::{Allocator, BufferOptions, CpuAllocator};
47#[cfg(feature = "cuda")]
48pub use registry::cuda;
49pub use registry::{DeviceSpec, cpu, get_device};