#[cfg(feature = "cuda")]
use cudarc::driver::CudaSlice;
#[cfg(feature = "cuda")]
pub struct CudaBuffer<T> {
pub(crate) data: CudaSlice<T>,
pub(crate) len: usize,
pub(crate) device_ordinal: usize,
}
#[cfg(feature = "cuda")]
impl<T> CudaBuffer<T> {
#[inline]
pub fn len(&self) -> usize {
self.len
}
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
pub fn device_ordinal(&self) -> usize {
self.device_ordinal
}
#[inline]
pub fn inner(&self) -> &CudaSlice<T> {
&self.data
}
#[inline]
pub fn inner_mut(&mut self) -> &mut CudaSlice<T> {
&mut self.data
}
}
#[cfg(feature = "cuda")]
impl<T> std::fmt::Debug for CudaBuffer<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CudaBuffer")
.field("len", &self.len)
.field("device_ordinal", &self.device_ordinal)
.finish_non_exhaustive()
}
}
#[cfg(not(feature = "cuda"))]
#[derive(Debug)]
pub struct CudaBuffer<T> {
pub(crate) _phantom: std::marker::PhantomData<T>,
pub(crate) len: usize,
pub(crate) device_ordinal: usize,
}
#[cfg(not(feature = "cuda"))]
impl<T> CudaBuffer<T> {
#[inline]
pub fn len(&self) -> usize {
self.len
}
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
pub fn device_ordinal(&self) -> usize {
self.device_ordinal
}
}