use std::sync::Arc;
use oxicuda_dnn::handle::DnnHandle;
use oxicuda_driver::{Context, Device};
pub struct CudaContext {
pub(crate) context: Arc<Context>,
pub(crate) dnn: DnnHandle,
}
impl CudaContext {
pub fn driver_context(&self) -> &Arc<Context> {
&self.context
}
pub fn try_new() -> Option<Self> {
match oxicuda_driver::init() {
Ok(()) => {}
Err(_) => return None,
}
let dev = Device::get(0).ok()?;
let context = Arc::new(Context::new(&dev).ok()?);
context.set_current().ok()?;
let dnn = DnnHandle::new(&context).ok()?;
Some(Self { context, dnn })
}
}