Struct DevicePtr

Source
pub struct DevicePtr(/* private fields */);
Expand description

Represents a device-local pointer. Pointers qualify as device-local if they refer to memory that lives on the device, and not on the host.

§Safety

§Null

Creating a null pointer is always unsafe, because any CUDA operations on null pointers can cause undefined behavior.

Use the unsafe function Ptr::null to create a null pointer in cases where usage is safe.

Implementations§

Source§

impl DevicePtr

Source

pub fn from_raw(raw: *mut c_void) -> Self

Create from raw pointer.

Source

pub unsafe fn null() -> Self

Create null pointer.

§Safety

This is unsafe because operating on a null pointer in CUDA code can cause crashes. In some cases it is allowed though, for example, a null pointer can designate the default stream in stream-related operations.

Source

pub fn is_null(&self) -> bool

Whether or not the device pointer is a null pointer.

Source

pub fn as_ptr(&self) -> *const c_void

Get the readonly pointer value.

Source

pub fn as_mut_ptr(&mut self) -> *mut c_void

Get the mutable pointer value.

Source

pub unsafe fn take(&mut self) -> DevicePtr

Take the pointer from this wrapper and replace it with a null pointer.

§Safety

This operation is unsafe because it creates a null pointer.

§Usage

This function can be used inside Drop if it known that the pointer object will not be used for the remainder of the function scope, and the object is to be dropped.

§Example
pub struct Object {
    internal: DevicePtr,
}

impl Drop for Object {

    fn drop(&mut self) {
        // SAFETY: This is safe because `self` and `self.internal`
        // are not used beyond this unsafe block.
        let ptr = unsafe {
            self.internal.take_raw();
        };
        // Propertly deallocate the pointer here and do *NOT* use
        // use `self` for anything!
    }

}

Trait Implementations§

Source§

impl Display for DevicePtr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<*mut c_void> for DevicePtr

Source§

fn from(value: *mut c_void) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.