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    Ok(LibraryVersion::from(version))
38}
39
40/// Returns the requested cuSOLVER library property.
41/// See [`LibraryProperty`] for supported properties.
42///
43/// # Errors
44///
45/// Returns an error if cuSOLVER cannot report the requested property.
46pub fn library_property(property: LibraryProperty) -> Result<i32> {
47    let mut value = 0;
48    unsafe {
49        try_ffi!(sys::cusolverGetProperty(property.into(), &raw mut value))?;
50    }
51    Ok(value)
52}
53
54#[cfg(all(test, feature = "testing"))]
55mod tests {
56    use super::*;
57    use crate::testing::setup_context_if_available;
58
59    #[test]
60    fn it_works() -> Result<()> {
61        let Some(_ctx) = setup_context_if_available()? else {
62            return Ok(());
63        };
64        let version = version()?;
65        println!("cuSOLVER version: {version}");
66        assert_ne!(version, 0);
67        assert_ne!(library_property(LibraryProperty::Major)?, 0);
68        Ok(())
69    }
70}