Skip to main content

DevicePtr

Trait DevicePtr 

Source
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§

Source

fn device_ptr(&self) -> CUdeviceptr

Raw device pointer to element 0.

Source

fn len(&self) -> usize

Number of T elements visible through this pointer.

Provided Methods§

Source

fn is_empty(&self) -> bool

true if len is 0.

Source

fn byte_size(&self) -> usize

Size in bytes (len * size_of::<T>()).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: DeviceRepr, P: DevicePtr<T> + ?Sized> DevicePtr<T> for &P

Source§

impl<T: DeviceRepr, P: DevicePtr<T> + ?Sized> DevicePtr<T> for &mut P

Implementors§

Source§

impl<'a, T: DeviceRepr> DevicePtr<T> for DeviceSlice<'a, T>

Source§

impl<'a, T: DeviceRepr> DevicePtr<T> for DeviceSliceMut<'a, T>

Source§

impl<T: DeviceRepr> DevicePtr<T> for DeviceBuffer<T>