cuda_oxide/init.rs
1use std::sync::atomic::{AtomicBool, Ordering};
2
3use crate::{error::*, sys, Cuda};
4
5static CHECK_INIT: AtomicBool = AtomicBool::new(false);
6impl Cuda {
7 /// Initialize the CUDA library. Can be called repeatedly at no cost.
8 pub fn init() -> CudaResult<()> {
9 if CHECK_INIT.load(Ordering::SeqCst) {
10 return Ok(());
11 }
12 cuda_error(unsafe { sys::cuInit(0) })?;
13 CHECK_INIT.store(true, Ordering::SeqCst);
14 Ok(())
15 }
16}