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
impl DevicePtr
Sourcepub unsafe fn null() -> Self
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.
Sourcepub fn as_mut_ptr(&mut self) -> *mut c_void
pub fn as_mut_ptr(&mut self) -> *mut c_void
Get the mutable pointer value.
Sourcepub unsafe fn take(&mut self) -> DevicePtr
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!
}
}