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    let version = nonzero_version("library", unsafe { sys::cutensorGetVersion() as _ })? as u64;
31    Ok(LibraryVersion::new(
32        version / 10000,
33        (version % 10000) / 100,
34        version % 100,
35    ))
36}
37
38/// Returns the CUDA runtime version that cuTENSOR was compiled against.
39///
40/// Can be compared against the CUDA runtime version reported by the CUDA wrapper crate.
41pub fn cudart_version() -> error::Result<CudaRuntimeVersion> {
42    nonzero_version("cuda runtime", unsafe {
43        sys::cutensorGetCudartVersion() as _
44    })
45    .map(CudaRuntimeVersion::from)
46}
47
48fn nonzero_version(name: &'static str, version: usize) -> error::Result<usize> {
49    if version == 0 {
50        return Err(Error::InvalidVersion { name });
51    }
52    Ok(version)
53}
54
55#[cfg(all(test, feature = "testing"))]
56mod tests {
57    use super::*;
58    use crate::error::Result;
59    use crate::testing::setup_context;
60
61    #[test]
62    fn it_works() -> Result<()> {
63        let _context = setup_context()?;
64        assert_ne!(version()?, 0);
65        assert_ne!(cudart_version()?, 0);
66        Ok(())
67    }
68}