Skip to main content

singe_cuda/
runtime.rs

1use singe_cuda_sys::runtime;
2
3use crate::{error::Result, try_ffi};
4
5/// Returns the version number of the current CUDA Runtime instance.
6/// The version is returned as `1000 * major + 10 * minor`.
7/// For example, CUDA 9.2 would be represented by 9020.
8///
9/// As of CUDA 12.0, this no longer initializes CUDA.
10/// The purpose of this call is solely to return a compile-time constant stating the CUDA Toolkit version in the above format.
11///
12/// This may also return [`crate::error::Status::NotInitialized`], [`crate::error::Status::CallRequiresNewerDriver`],
13/// or [`crate::error::Status::NoDevice`] if the call tries to initialize internal CUDA Runtime state.
14///
15/// No CUDA function may be called from a [`Stream::add_callback`](crate::stream::Stream::add_callback)
16/// callback. [`crate::error::Status::NotPermitted`] may be returned as a diagnostic in that case, but this is not guaranteed.
17///
18/// # Errors
19///
20/// Returns an error if CUDA Runtime cannot report its version, if a previous asynchronous launch
21/// failed, or if CUDA Runtime reports initialization or driver/device availability errors.
22pub fn version() -> Result<i32> {
23    let mut version = 0;
24    unsafe {
25        try_ffi!(runtime::cudaRuntimeGetVersion(&raw mut version))?;
26    }
27    Ok(version)
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn it_works() {
36        assert_ne!(version().unwrap(), 0);
37    }
38}