use std::{ffi::c_void, sync::Arc};
use ::cuda_core::{Device as ForeignDevice, Stream as ForeignStream};
use crate::{context::Context, error::Result, stream::Stream, utility::to_usize};
impl Context {
pub fn to_cuda_core(self: &Arc<Self>) -> Result<Arc<ForeignDevice>> {
self.bind()?;
let ordinal = to_usize(self.device().id(), "device ordinal")?;
let owner = Arc::clone(self);
Ok(unsafe {
ForeignDevice::borrow_with_owner(
self.as_raw().cast::<c_void>(),
self.device().id(),
ordinal,
owner,
)
})
}
}
impl Stream {
pub fn to_cuda_core(&self) -> Result<Arc<ForeignStream>> {
let device = self.context().to_cuda_core()?;
let owner = Arc::new(self.clone());
Ok(unsafe {
ForeignStream::borrow_with_owner(self.as_raw().cast::<c_void>(), &device, owner)
})
}
}