tenferro_gpu/lib.rs
1//! GPU backend implementations for tenferro tensors.
2//!
3//! # Examples
4//!
5//! ```rust
6//! #[cfg(feature = "cuda")]
7//! use tenferro_gpu::{cuda::cuda_devices, cuda::CudaEngine};
8//!
9//! #[cfg(feature = "cuda")]
10//! fn first_cuda_backend() -> Result<Option<CudaEngine>, Box<dyn std::error::Error>> {
11//! let devices = cuda_devices()?;
12//! let Some(device) = devices.first() else {
13//! return Ok(None);
14//! };
15//! Ok(Some(CudaEngine::open(device.id())?))
16//! }
17//!
18//! // This ordinary doctest checks the discovery-based selection API without
19//! // requiring CUDA hardware at test time.
20//! #[cfg(feature = "cuda")]
21//! let _example: fn() -> Result<Option<CudaEngine>, Box<dyn std::error::Error>> = first_cuda_backend;
22//! ```
23// A misaligned pointer handed to a CUDA library is undefined behaviour and
24// fails only on some library versions: `cuDoubleComplex` is `double2`, which
25// CUDA declares `__align__(16)`, while `num_complex::Complex64` is 8-aligned,
26// so casting `&Complex64` to `*const cuDoubleComplex` produced a pointer
27// cuBLAS >= 12.9 faults on (issue #1870). Deny the whole cast class at this
28// FFI boundary rather than re-auditing it by hand.
29#![deny(clippy::cast_ptr_alignment)]
30
31#[cfg(feature = "cuda")]
32mod event_domain_admission;
33#[cfg(feature = "cuda")]
34mod event_retirement;
35#[cfg(feature = "cuda")]
36pub mod gpu;
37
38#[cfg(feature = "cuda")]
39pub mod cuda;
40
41#[cfg(feature = "cuda")]
42use tenferro_tensor::*;