Skip to main content

singe_cublas/
lib.rs

1//! Safe cuBLAS and cuBLASLt wrappers for dense GPU linear algebra.
2//!
3//! This crate provides BLAS level routines, cuBLAS context management, cuBLASLt
4//! matmul descriptors, algorithm selection, layouts, preferences, epilogues, and
5//! execution helpers over the raw `singe-cublas-sys` bindings.
6
7#[allow(unused_imports)]
8use crate::error::Status;
9
10pub mod blas;
11pub mod context;
12pub mod error;
13pub mod gemm;
14pub mod lt;
15pub mod memory;
16pub mod scalar;
17pub mod types;
18
19pub(crate) mod utility;
20
21#[cfg(feature = "testing")]
22pub mod testing;
23
24use singe_cublas_sys as sys;
25use singe_cuda::types::LibraryProperty;
26
27use crate::{error::Result, utility::to_u64};
28
29/// Returns the CUDA runtime version used by cuBLAS.
30///
31/// This is the version of the CUDA runtime that cuBLAS was linked against at
32/// build time.
33pub fn cudart_version() -> Result<u64> {
34    to_u64(unsafe { sys::cublasGetCudartVersion() }, "version")
35}
36
37/// Returns the requested cuBLAS library property.
38/// See [`LibraryProperty`] for supported properties.
39///
40/// # Errors
41///
42/// Returns an error if cuBLAS cannot report the requested property.
43pub fn library_property(property: LibraryProperty) -> Result<i32> {
44    let mut value = 0;
45    unsafe {
46        try_ffi!(sys::cublasGetProperty(property.into(), &raw mut value))?;
47    }
48    Ok(value)
49}
50
51#[cfg(all(test, feature = "testing"))]
52mod tests {
53    use super::*;
54    use crate::testing::setup_context;
55
56    #[test]
57    fn it_works() -> Result<()> {
58        let ctx = setup_context()?;
59        let version = ctx.version()?;
60        println!("cuBLAS version: {version}");
61        assert_ne!(version, 0);
62        assert_ne!(cudart_version()?, 0);
63        assert_ne!(library_property(LibraryProperty::Major)?, 0);
64        Ok(())
65    }
66}