[−][src]Struct rustacuda::memory::LockedBuffer
Fixed-size host-side buffer in page-locked memory.
See the module-level documentation
for more details on page-locked
memory.
Implementations
impl<T: DeviceCopy + Clone> LockedBuffer<T>
[src]
pub fn new(value: &T, size: usize) -> CudaResult<Self>
[src]
Allocate a new page-locked buffer large enough to hold size
T
's and initialized with
clones of value
.
Errors
If the allocation fails, returns the error from CUDA. If size
is large enough that
size * mem::sizeof::<T>()
overflows usize, then returns InvalidMemoryAllocation.
Examples
use rustacuda::memory::*; let mut buffer = LockedBuffer::new(&0u64, 5).unwrap(); buffer[0] = 1;
pub fn from_slice(slice: &[T]) -> CudaResult<Self>
[src]
Allocate a new page-locked buffer of the same size as slice
, initialized with a clone of
the data in slice
.
Errors
If the allocation fails, returns the error from CUDA.
Examples
use rustacuda::memory::*; let values = [0u64; 5]; let mut buffer = LockedBuffer::from_slice(&values).unwrap(); buffer[0] = 1;
impl<T: DeviceCopy> LockedBuffer<T>
[src]
pub unsafe fn uninitialized(size: usize) -> CudaResult<Self>
[src]
Allocate a new page-locked buffer large enough to hold size
T
's, but without
initializing the contents.
Errors
If the allocation fails, returns the error from CUDA. If size
is large enough that
size * mem::sizeof::<T>()
overflows usize, then returns InvalidMemoryAllocation.
Safety
The caller must ensure that the contents of the buffer are initialized before reading from the buffer.
Examples
use rustacuda::memory::*; let mut buffer = unsafe { LockedBuffer::uninitialized(5).unwrap() }; for i in buffer.iter_mut() { *i = 0u64; }
pub fn as_slice(&self) -> &[T]
[src]
Extracts a slice containing the entire buffer.
Equivalent to &s[..]
.
Examples
use rustacuda::memory::*; let buffer = LockedBuffer::new(&0u64, 5).unwrap(); let sum : u64 = buffer.as_slice().iter().sum();
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Extracts a mutable slice of the entire buffer.
Equivalent to &mut s[..]
.
Examples
use rustacuda::memory::*; let mut buffer = LockedBuffer::new(&0u64, 5).unwrap(); for i in buffer.as_mut_slice() { *i = 12u64; }
pub unsafe fn from_raw_parts(ptr: *mut T, size: usize) -> LockedBuffer<T>
[src]
Creates a LockedBuffer<T>
directly from the raw components of another locked buffer.
Safety
This is highly unsafe, due to the number of invariants that aren't checked:
ptr
needs to have been previously allocated viaLockedBuffer
orcuda_malloc_locked
.ptr
'sT
needs to have the same size and alignment as it was allocated with.capacity
needs to be the capacity that the pointer was allocated with.
Violating these may cause problems like corrupting the CUDA driver's internal data structures.
The ownership of ptr
is effectively transferred to the
LockedBuffer<T>
which may then deallocate, reallocate or change the
contents of memory pointed to by the pointer at will. Ensure
that nothing else uses the pointer after calling this
function.
Examples
use std::mem; use rustacuda::memory::*; let mut buffer = LockedBuffer::new(&0u64, 5).unwrap(); let ptr = buffer.as_mut_ptr(); let size = buffer.len(); mem::forget(buffer); let buffer = unsafe { LockedBuffer::from_raw_parts(ptr, size) };
pub fn drop(buf: LockedBuffer<T>) -> DropResult<LockedBuffer<T>>
[src]
Destroy a LockedBuffer
, returning an error.
Deallocating page-locked memory can return errors from previous asynchronous work. This function destroys the given buffer and returns the error and the un-destroyed buffer on failure.
Example
use rustacuda::memory::*; let x = LockedBuffer::new(&0u64, 5).unwrap(); match LockedBuffer::drop(x) { Ok(()) => println!("Successfully destroyed"), Err((e, buf)) => { println!("Failed to destroy buffer: {:?}", e); // Do something with buf }, }
Trait Implementations
impl<T: DeviceCopy> AsMut<[T]> for LockedBuffer<T>
[src]
impl<T: DeviceCopy> AsRef<[T]> for LockedBuffer<T>
[src]
impl<T: Debug + DeviceCopy> Debug for LockedBuffer<T>
[src]
impl<T: DeviceCopy> Deref for LockedBuffer<T>
[src]
impl<T: DeviceCopy> DerefMut for LockedBuffer<T>
[src]
impl<T: DeviceCopy> Drop for LockedBuffer<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for LockedBuffer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for LockedBuffer<T>
impl<T> !Sync for LockedBuffer<T>
impl<T> Unpin for LockedBuffer<T>
impl<T> UnwindSafe for LockedBuffer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,