Skip to main content

singe_cutensor/
lib.rs

1//! Safe cuTENSOR wrappers for tensor descriptors, operations, plans, and execution.
2//!
3//! Optional `mg` and `mp` features expose multi-GPU and multi-process cuTENSOR modules.
4
5pub mod context;
6pub mod error;
7pub mod execution;
8pub mod operation;
9pub mod plan;
10pub mod tensor;
11pub mod types;
12
13#[cfg(feature = "mg")]
14pub mod mg;
15
16#[cfg(feature = "mp")]
17pub mod mp;
18
19pub(crate) mod utility;
20
21#[cfg(feature = "testing")]
22pub mod testing;
23
24use singe_core::{CudaRuntimeVersion, LibraryVersion};
25use singe_cutensor_sys as sys;
26
27use crate::error::Error;
28
29pub fn version() -> error::Result<LibraryVersion> {
30    nonzero_version("library", unsafe { sys::cutensorGetVersion() as _ }).map(LibraryVersion::from)
31}
32
33/// Returns the CUDA runtime version that cuTENSOR was compiled against.
34///
35/// Can be compared against the CUDA runtime version reported by the CUDA wrapper crate.
36pub fn cudart_version() -> error::Result<CudaRuntimeVersion> {
37    nonzero_version("cuda runtime", unsafe {
38        sys::cutensorGetCudartVersion() as _
39    })
40    .map(CudaRuntimeVersion::from)
41}
42
43fn nonzero_version(name: &'static str, version: usize) -> error::Result<usize> {
44    if version == 0 {
45        return Err(Error::InvalidVersion { name });
46    }
47    Ok(version)
48}
49
50#[cfg(all(test, feature = "testing"))]
51mod tests {
52    use super::*;
53    use crate::error::Result;
54    use crate::testing::setup_context;
55
56    #[test]
57    fn it_works() -> Result<()> {
58        let _context = setup_context()?;
59        assert_ne!(version()?, 0);
60        assert_ne!(cudart_version()?, 0);
61        Ok(())
62    }
63}