Skip to main content

singe_cusolver/
lib.rs

1//! Safe cuSOLVER wrappers for dense linear algebra and solver operations.
2//!
3//! This crate covers cuSOLVER context management, dense matrix routines,
4//! eigenvalue helpers, SVD helpers, iterative refinement solver APIs, and parameter objects.
5
6pub mod context;
7pub mod dense;
8pub mod eigen;
9pub mod error;
10pub mod irs;
11pub mod layout;
12pub mod params;
13pub mod svd;
14pub mod types;
15
16pub(crate) mod utility;
17
18#[cfg(feature = "testing")]
19pub mod testing;
20
21use singe_core::LibraryVersion;
22use singe_cuda::types::LibraryProperty;
23use singe_cusolver_sys as sys;
24
25use crate::error::Result;
26
27/// Returns the cuSOLVER library version.
28///
29/// # Errors
30///
31/// Returns an error if cuSOLVER cannot report the loaded library version.
32pub fn version() -> Result<LibraryVersion> {
33    let mut version = 0;
34    unsafe {
35        try_ffi!(sys::cusolverGetVersion(&raw mut version))?;
36    }
37    let version = version as u64;
38    Ok(LibraryVersion::new(
39        version / 10000,
40        (version % 10000) / 100,
41        version % 100,
42    ))
43}
44
45/// Returns the requested cuSOLVER library property.
46/// See [`LibraryProperty`] for supported properties.
47///
48/// # Errors
49///
50/// Returns an error if cuSOLVER cannot report the requested property.
51pub fn library_property(property: LibraryProperty) -> Result<i32> {
52    let mut value = 0;
53    unsafe {
54        try_ffi!(sys::cusolverGetProperty(property.into(), &raw mut value))?;
55    }
56    Ok(value)
57}
58
59#[cfg(all(test, feature = "testing"))]
60mod tests {
61    use super::*;
62    use crate::testing::setup_context_if_available;
63
64    #[test]
65    fn it_works() -> Result<()> {
66        let Some(_ctx) = setup_context_if_available()? else {
67            return Ok(());
68        };
69        let version = version()?;
70        println!("cuSOLVER version: {version}");
71        assert_ne!(version, 0);
72        assert_ne!(library_property(LibraryProperty::Major)?, 0);
73        Ok(())
74    }
75}