Skip to main content

baracuda_driver/
lib.rs

1//! Safe Rust wrappers for the CUDA Driver API.
2//!
3//! This crate takes the raw FFI in [`baracuda_cuda_sys`] and dresses it up
4//! with RAII handles, typed memory, lifetime-checked slices, and a kernel
5//! launch builder. It deliberately does not hide the Driver-API model:
6//! contexts are explicit, modules are explicit, streams are explicit.
7//!
8//! # Quickstart
9//!
10//! ```no_run
11//! use baracuda_driver::{Context, Device, DeviceBuffer, Module, Stream};
12//!
13//! # fn demo() -> baracuda_driver::Result<()> {
14//! let device = Device::get(0)?;
15//! let ctx = Context::new(&device)?;
16//! let stream = Stream::new(&ctx)?;
17//! let host_data: Vec<f32> = (0..1024).map(|i| i as f32).collect();
18//! let device_data = DeviceBuffer::from_slice(&ctx, &host_data)?;
19//! let mut back = vec![0.0f32; host_data.len()];
20//! device_data.copy_to_host(&mut back)?;
21//! stream.synchronize()?;
22//! assert_eq!(host_data, back);
23//! # Ok(())
24//! # }
25//! ```
26//!
27//! # Modules
28//!
29//! - [`device`] — [`Device`] enumeration and attributes.
30//! - [`context`] — [`Context`] (explicit CUDA contexts + primary-context reuse).
31//! - [`stream`] — [`Stream`], ordered async work queues.
32//! - [`event`] — [`Event`], synchronization and timing.
33//! - [`memory`] — [`DeviceBuffer<T>`], [`DeviceSlice<'_, T>`], [`DeviceSliceMut<'_, T>`].
34//! - [`module`] — [`Module`], [`Function`] (PTX/CUBIN loading).
35//! - [`launch`] — [`launch::LaunchBuilder`] for `cuLaunchKernel`.
36//! - [`init()`] — `init()` helper and driver version queries.
37
38#![warn(missing_debug_implementations)]
39
40pub mod array;
41pub mod context;
42pub mod coredump;
43pub mod device;
44pub mod error;
45pub mod event;
46pub mod external;
47pub mod graph;
48pub mod graphics;
49pub mod green;
50pub mod init;
51pub mod ipc;
52pub mod launch;
53pub mod launch_attr;
54pub mod library;
55pub mod memcpy2d;
56pub mod memcpy3d;
57pub mod memory;
58pub mod mempool;
59pub mod module;
60pub mod multicast;
61pub mod occupancy;
62pub mod pinned;
63pub mod pointer;
64pub mod profiler;
65pub mod stream;
66pub mod tensor_map;
67pub mod user_object;
68pub mod vmm;
69
70pub use array::{
71    Array, ArrayFormat, SurfaceObject, TextureAddressMode, TextureDesc, TextureFilterMode,
72    TextureObject,
73};
74pub use context::{Context, PrimaryContext};
75pub use device::Device;
76pub use error::{error_name, error_string, Error, Result};
77pub use event::Event;
78pub use graph::{instantiate_flags, CaptureMode, Graph, GraphExec, GraphNode};
79pub use init::{init, version};
80pub use launch::{Dim3, LaunchBuilder};
81pub use memory::{
82    mem_get_info, DeviceBuffer, DevicePtr, DevicePtrMut, DeviceSlice, DeviceSliceMut,
83    ManagedAttach, ManagedBuffer, MemAdvise,
84};
85pub use pinned::{PinnedBuffer, PinnedRegistration};
86pub use module::{Function, Module};
87pub use stream::Stream;