1pub mod context;
8pub mod error;
9pub mod matrix;
10pub mod operation;
11pub mod scalar;
12pub mod sddmm;
13pub mod spgemm;
14pub mod spmm;
15pub mod spmv;
16pub mod spsm;
17pub mod spsv;
18pub mod spvv;
19pub mod types;
20pub mod vector;
21
22pub(crate) mod utility;
23
24#[cfg(feature = "testing")]
25pub mod testing;
26
27use singe_core::LibraryVersion;
28use singe_cuda::types::LibraryProperty;
29use singe_cusparse_sys as sys;
30
31use crate::error::Result;
32
33pub fn version() -> Result<LibraryVersion> {
39 let major = library_property(LibraryProperty::Major)?;
40 let minor = library_property(LibraryProperty::Minor)?;
41 let patch = library_property(LibraryProperty::Patch)?;
42 Ok(LibraryVersion::new(major as _, minor as _, patch as _))
43}
44
45pub fn library_property(property: LibraryProperty) -> Result<i32> {
52 let mut value = 0;
53 unsafe {
54 try_ffi!(sys::cusparseGetProperty(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;
63 use singe_cuda::error::Error as CudaError;
64
65 #[test]
66 fn it_works() -> Result<()> {
67 let ctx = match setup_context() {
68 Ok(ctx) => ctx,
69 Err(crate::error::Error::Cuda(CudaError::Cuda { message, .. }))
70 if message == "CUDA driver is a stub library" =>
71 {
72 return Ok(());
73 }
74 Err(error) => return Err(error),
75 };
76 let context_version = ctx.version()?;
77 let library_version = version()?;
78 println!("cuSPARSE version: {context_version}");
79 assert_ne!(context_version, 0);
80 assert_ne!(library_version, 0);
81 assert_ne!(library_property(LibraryProperty::Major)?, 0);
82 Ok(())
83 }
84}