use crate::Result;
#[derive(Debug)]
pub struct Driver {
native: mircuda_sys::Driver,
}
impl Driver {
pub fn initialize() -> Result<Self> {
Ok(Self {
native: mircuda_sys::Driver::initialize()?,
})
}
pub fn devices(&self) -> Result<Vec<Device>> {
let count = self.native.device_count()?;
Ok((0..count).map(|ordinal| Device { ordinal }).collect())
}
pub fn create_context(&self, device: Device) -> Result<Context> {
Ok(Context {
native: self.native.create_context(device.ordinal)?,
})
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Device {
ordinal: usize,
}
impl Device {
#[must_use]
pub const fn ordinal(self) -> usize {
self.ordinal
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DeviceInfo {
pub ordinal: usize,
pub name: String,
pub compute_capability: (i32, i32),
pub multiprocessor_count: u32,
pub total_memory: usize,
pub memory_pools: bool,
pub integrated: bool,
}
#[derive(Clone, Debug)]
pub struct Context {
pub(crate) native: mircuda_sys::Context,
}
impl Context {
pub fn memory_info(&self) -> Result<(usize, usize)> {
Ok(self.native.memory_info()?)
}
pub fn device_info(&self) -> Result<DeviceInfo> {
let info = self.native.device_info()?;
Ok(DeviceInfo {
ordinal: info.ordinal,
name: info.name,
compute_capability: info.compute_capability,
multiprocessor_count: u32::try_from(info.multiprocessor_count)?,
total_memory: info.total_memory,
memory_pools: info.memory_pools,
integrated: info.integrated,
})
}
pub fn create_stream(&self) -> Result<Stream> {
Ok(Stream { native: self.native.create_stream()? })
}
}
#[derive(Clone, Debug)]
pub struct Stream {
pub(crate) native: mircuda_sys::Stream,
}
impl Stream {
pub fn synchronize(&self) -> Result<()> {
Ok(self.native.synchronize()?)
}
}