pub unsafe trait DevicePtr<T: DeviceRepr> {
// Required methods
fn device_ptr(&self) -> CUdeviceptr;
fn len(&self) -> usize;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn byte_size(&self) -> usize { ... }
}Expand description
Anything that can be read as a [T] on the device.
This is the abstraction over DeviceBuffer<T>, DeviceSlice<'_, T>,
and (via DevicePtrMut) DeviceSliceMut<'_, T> — letting generic code
accept any of them without fighting the type system.
Typical usage:
use baracuda_driver::{DevicePtr, DeviceBuffer, DeviceSlice};
use baracuda_types::DeviceRepr;
fn sum_elements<T: DeviceRepr, P: DevicePtr<T>>(buf: &P) -> usize {
// You get len() + device_ptr() for free; deeper ops go through
// the concrete type via `buf.device_ptr()`.
buf.len()
}§Safety
device_ptr() returns an opaque CUdeviceptr. Any dereference is
unsafe as always. Implementors must guarantee the pointer is live for
at least len() * size_of::<T>() bytes.
Required Methods§
Sourcefn device_ptr(&self) -> CUdeviceptr
fn device_ptr(&self) -> CUdeviceptr
Raw device pointer to element 0.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".