[−][src]Struct rustacuda::memory::DevicePointer
A pointer to device memory.
DevicePointer
cannot be dereferenced by the CPU, as it is a pointer to a memory allocation in
the device. It can be safely copied to the device (eg. as part of a kernel launch) and either
unwrapped or transmuted to an appropriate pointer.
DevicePointer
is guaranteed to have an equivalent internal representation to a raw pointer.
Thus, it can be safely reinterpreted or transmuted to *mut T
. It is safe to pass a
DevicePointer
through an FFI boundary to C code expecting a *mut T
, so long as the code on
the other side of that boundary does not attempt to dereference the pointer on the CPU. It is
thus possible to pass a DevicePointer
to a CUDA kernel written in C.
Methods
impl<T> DevicePointer<T>
[src]
pub fn null() -> DevicePointer<T>
[src]
Returns a null device pointer.
Examples:
use rustacuda::memory::*; let ptr : DevicePointer<u64> = DevicePointer::null(); assert!(ptr.is_null());
pub unsafe fn wrap(ptr: *mut T) -> DevicePointer<T>
[src]
Wrap the given raw pointer in a DevicePointer. The given pointer is assumed to be a valid, device pointer or null.
Safety
The given pointer must have been allocated with cuda_malloc
or
be null.
Examples:
use rustacuda::memory::*; use std::ptr; unsafe { let null : *mut u64 = ptr::null_mut(); assert!(DevicePointer::wrap(null).is_null()); }
pub fn as_raw(self) -> *const T
[src]
Returns the contained pointer as a raw pointer. The returned pointer is not valid on the CPU and must not be dereferenced.
Examples:
use rustacuda::memory::*; unsafe { let dev_ptr = cuda_malloc::<u64>(1).unwrap(); let ptr: *const u64 = dev_ptr.as_raw(); cuda_free(dev_ptr); }
pub fn as_raw_mut(&mut self) -> *mut T
[src]
Returns the contained pointer as a mutable raw pointer. The returned pointer is not valid on the CPU and must not be dereferenced.
Examples:
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(1).unwrap(); let ptr: *mut u64 = dev_ptr.as_raw_mut(); cuda_free(dev_ptr); }
pub fn is_null(self) -> bool
[src]
Returns true if the pointer is null.
Examples:
use rustacuda::memory::*; use std::ptr; unsafe { let null : *mut u64 = ptr::null_mut(); assert!(DevicePointer::wrap(null).is_null()); }
pub unsafe fn offset(self, count: isize) -> DevicePointer<T>
[src]
Calculates the offset from a device pointer.
count
is in units of T; eg. a count
of 3 represents a pointer offset of
3 * size_of::<T>()
bytes.
Safety
If any of the following conditions are violated, the result is Undefined Behavior:
-
Both the starting and resulting pointer must be either in bounds or one byte past the end of the same allocated object.
-
The computed offset, in bytes, cannot overflow an
isize
. -
The offset being in bounds cannot rely on "wrapping around" the address space. That is, the infinite-precision sum, in bytes must fit in a usize.
Consider using wrapping_offset
instead if these constraints are
difficult to satisfy. The only advantage of this method is that it
enables more aggressive compiler optimizations.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.offset(1); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
pub fn wrapping_offset(self, count: isize) -> DevicePointer<T>
[src]
Calculates the offset from a device pointer using wrapping arithmetic.
count
is in units of T; eg. a count
of 3 represents a pointer offset of
3 * size_of::<T>()
bytes.
Safety
The resulting pointer does not need to be in bounds, but it is
potentially hazardous to dereference (which requires unsafe
).
In particular, the resulting pointer may not be used to access a
different allocated object than the one self
points to. In other
words, x.wrapping_offset(y.wrapping_offset_from(x))
is
not the same as y
, and dereferencing it is undefined behavior
unless x
and y
point into the same allocated object.
Always use .offset(count)
instead when possible, because offset
allows the compiler to optimize better. If you need to cross object
boundaries, cast the pointer to an integer and do the arithmetic there.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.wrapping_offset(1); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
pub unsafe fn add(self, count: usize) -> DevicePointer<T>
[src]
Calculates the offset from a pointer (convenience for .offset(count as isize)
).
count
is in units of T; e.g. a count
of 3 represents a pointer
offset of 3 * size_of::<T>()
bytes.
Safety
If any of the following conditions are violated, the result is Undefined Behavior:
-
Both the starting and resulting pointer must be either in bounds or one byte past the end of an allocated object.
-
The computed offset, in bytes, cannot overflow an
isize
. -
The offset being in bounds cannot rely on "wrapping around" the address space. That is, the infinite-precision sum must fit in a
usize
.
Consider using wrapping_offset
instead if these constraints are
difficult to satisfy. The only advantage of this method is that it
enables more aggressive compiler optimizations.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.add(1); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
pub unsafe fn sub(self, count: usize) -> DevicePointer<T>
[src]
Calculates the offset from a pointer (convenience for
.offset((count as isize).wrapping_neg())
).
count
is in units of T; e.g. a count
of 3 represents a pointer
offset of 3 * size_of::<T>()
bytes.
Safety
If any of the following conditions are violated, the result is Undefined Behavior:
-
Both the starting and resulting pointer must be either in bounds or one byte past the end of an allocated object.
-
The computed offset, in bytes, cannot overflow an
isize
. -
The offset being in bounds cannot rely on "wrapping around" the address space. That is, the infinite-precision sum must fit in a
usize
.
Consider using wrapping_offset
instead if these constraints are
difficult to satisfy. The only advantage of this method is that it
enables more aggressive compiler optimizations.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.add(4).sub(3); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
pub fn wrapping_add(self, count: usize) -> DevicePointer<T>
[src]
Calculates the offset from a pointer using wrapping arithmetic.
(convenience for .wrapping_offset(count as isize)
)
count
is in units of T; e.g. a count
of 3 represents a pointer
offset of 3 * size_of::<T>()
bytes.
Safety
The resulting pointer does not need to be in bounds, but it is potentially hazardous to dereference.
Always use .add(count)
instead when possible, because add
allows the compiler to optimize better.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.wrapping_add(1); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
pub fn wrapping_sub(self, count: usize) -> DevicePointer<T>
[src]
Calculates the offset from a pointer using wrapping arithmetic.
(convenience for .wrapping_offset((count as isize).wrapping_sub())
)
count
is in units of T; e.g. a count
of 3 represents a pointer
offset of 3 * size_of::<T>()
bytes.
Safety
The resulting pointer does not need to be in bounds, but it is
potentially hazardous to dereference (which requires unsafe
).
Always use .sub(count)
instead when possible, because sub
allows the compiler to optimize better.
Examples
use rustacuda::memory::*; unsafe { let mut dev_ptr = cuda_malloc::<u64>(5).unwrap(); let offset = dev_ptr.wrapping_add(4).wrapping_sub(3); // Points to the 2nd u64 in the buffer cuda_free(dev_ptr); // Must free the buffer using the original pointer }
Trait Implementations
impl<T> PartialEq<DevicePointer<T>> for DevicePointer<T> where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
fn eq(&self, other: &DevicePointer<T>) -> bool
[src]
fn ne(&self, other: &DevicePointer<T>) -> bool
[src]
impl<T> PartialOrd<DevicePointer<T>> for DevicePointer<T> where
T: PartialOrd<T>,
[src]
T: PartialOrd<T>,
fn partial_cmp(&self, other: &DevicePointer<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &DevicePointer<T>) -> bool
[src]
fn le(&self, other: &DevicePointer<T>) -> bool
[src]
fn gt(&self, other: &DevicePointer<T>) -> bool
[src]
fn ge(&self, other: &DevicePointer<T>) -> bool
[src]
impl<T> Eq for DevicePointer<T> where
T: Eq,
[src]
T: Eq,
impl<T> Clone for DevicePointer<T>
[src]
fn clone(&self) -> DevicePointer<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T> Pointer for DevicePointer<T>
[src]
impl<T> Copy for DevicePointer<T>
[src]
impl<T> Ord for DevicePointer<T> where
T: Ord,
[src]
T: Ord,
fn cmp(&self, other: &DevicePointer<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<T> Debug for DevicePointer<T> where
T: Debug,
[src]
T: Debug,
impl<T> Hash for DevicePointer<T> where
T: Hash,
[src]
T: Hash,
fn hash<__HT>(&self, state: &mut __HT) where
__HT: Hasher,
[src]
__HT: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> DeviceCopy for DevicePointer<T>
[src]
Auto Trait Implementations
impl<T> !Send for DevicePointer<T>
impl<T> !Sync for DevicePointer<T>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,