Struct ocl::builders::BufferMapCmd

source ·
pub struct BufferMapCmd<'c, T>
where T: 'c + OclPrm,
{ /* private fields */ }
Expand description

A command builder used to enqueue a map command.

Enqueuing a map command will map a region of a buffer into the host address space and return a MemMap or FutureMemMap, allowing access to this mapped region. Accessing memory via a MemMap is exactly like using a slice.

See SDK docs for more details.

Implementations§

source§

impl<'c, T> BufferMapCmd<'c, T>
where T: OclPrm,

source

pub fn flags(self, flags: MapFlags) -> BufferMapCmd<'c, T>

Specifies the flags to be used for this map command.

Flags can also be specified using the ::read, ::write, and ::write_invalidate methods instead.

See SDK docs for more details.

source

pub fn read(self) -> BufferMapCmd<'c, T>

Specifies that the memory object is being mapped for reading.

Sets the flag to be used for this map command to [CL_]MAP_READ.

This is the fastest way to move data from device to host for many use cases when used with buffers created with the MEM_ALLOC_HOST_PTR or MEM_USE_HOST_PTR flags.

source

pub fn write(self) -> BufferMapCmd<'c, T>

Specifies that the memory object is being mapped for writing.

Sets the flag to be used for this map command to [CL_]MAP_WRITE.

This is not the most efficient method of transferring data from host to device due to the memory being synchronized beforehand. Prefer ::write_invalidate unless you need the memory region to be updated (e.g. if you are only writing to particular portions of the data, and will not be overwriting the entire contents, etc.). Use this with buffers created with the MEM_ALLOC_HOST_PTR or MEM_USE_HOST_PTR flags for best performance.

source

pub fn write_invalidate(self) -> BufferMapCmd<'c, T>

Specifies that the memory object is being mapped for writing and that the local (host) memory region may contain stale data that must be completely overwritten before unmapping.

Sets the flag to be used for this map command to [CL_]MAP_WRITE_INVALIDATE_REGION.

This option may provide a substantial performance improvement when writing and is the fastest method for moving data in bulk from host to device memory when used with buffers created with the MEM_ALLOC_HOST_PTR or MEM_USE_HOST_PTR flags. Only use this when you will be overwriting the entire contents of the mapped region otherwise you will send stale or junk data to the device.

source

pub fn len(self, len: usize) -> BufferMapCmd<'c, T>

Specifies the length of the region to map.

If unspecified the entire buffer will be mapped.

source

pub fn queue(self, queue: &'c Queue) -> BufferMapCmd<'c, T>

Specifies a queue to use for this call only.

Overrides the buffer’s default queue if one is set. If no default queue is set, this method must be called before enqueuing the command.

source

pub fn offset(self, offset: usize) -> BufferMapCmd<'c, T>

Sets the linear offset for an operation.

§Panics

The ‘shape’ may not have already been set to rectangular by the ::rect function.

source

pub fn ewait<'e, Ewl>(self, ewait: Ewl) -> BufferMapCmd<'c, T>
where Ewl: Into<ClWaitListPtrEnum<'e>>, 'e: 'c,

Specifies an event or list of events to wait on before the command will run.

When events generated using the ::enew method of other, previously enqueued commands are passed here (either individually or as part of an EventList), this command will not execute until those commands have completed.

Using events can compliment the use of queues to order commands by creating temporal dependencies between them (where commands in one queue must wait for the completion of commands in another). Events can also supplant queues altogether when, for example, using out-of-order queues.

§Example
// Create an event list:
let mut event_list = EventList::new();
// Enqueue a kernel on `queue_1`, creating an event representing the kernel
// command in our list:
kernel.cmd().queue(&queue_1).enew(&mut event_list).enq()?;
// Map a buffer using `queue_2`, ensuring the map does not begin until
// after the kernel command has completed:
buffer.map().queue(&queue_2).ewait(&event_list).enq_async()?;
source

pub fn enew<'e, En>(self, enew: En) -> BufferMapCmd<'c, T>
where En: Into<ClNullEventPtrEnum<'e>>, 'e: 'c,

Specifies the destination to store a new, optionally created event associated with this command.

The destination can be a mutable reference to an empty event (created using Event::empty) or a mutable reference to an event list.

After this command is enqueued, the event in the destination can be passed to the ::ewait method of another command. Doing so will cause the other command to wait until this command has completed before executing.

Using events can compliment the use of queues to order commands by creating temporal dependencies between them (where commands in one queue must wait for the completion of commands in another). Events can also supplant queues altogether when, for example, using out-of-order queues.

§Example
// Create an event list:
let mut event = Event::empty();
// Enqueue a kernel on `queue_1`, creating an event representing the kernel
// command in our list:
kernel.cmd().queue(&queue_1).enew(&mut event).enq()?;
// Map a buffer using `queue_2`, ensuring the map does not begin until
// after the kernel command has completed:
buffer.map().queue(&queue_2).ewait(&event).enq_async()?;
source

pub unsafe fn enq(self) -> OclResult<MemMap<T>>

Enqueues a map command, blocking the current thread until it completes and returns a reference to the mapped memory.

§Safety

The caller must ensure that either only one mapping of a buffer exists at a time or that, if simultaneously mapping for the purposes of sub-region access or whole-buffer aliasing, no two mappings will allow writes to the same memory region at the same time. Use atomics or some other synchronization mechanism to ensure this.

source

pub unsafe fn enq_async(self) -> OclResult<FutureMemMap<T>>

Enqueues a map command and returns a future representing the completion of that map command.

The returned future will resolve to a reference to the mapped memory.

§Safety

The caller must ensure that either only one mapping of a buffer exists at a time or that, if simultaneously mapping for the purposes of sub-region access or whole-buffer aliasing, no two mappings will allow writes to the same memory region at the same time. Use atomics or some other synchronization mechanism to ensure this.

Auto Trait Implementations§

§

impl<'c, T> Freeze for BufferMapCmd<'c, T>
where T: Freeze,

§

impl<'c, T> !RefUnwindSafe for BufferMapCmd<'c, T>

§

impl<'c, T> !Send for BufferMapCmd<'c, T>

§

impl<'c, T> !Sync for BufferMapCmd<'c, T>

§

impl<'c, T> Unpin for BufferMapCmd<'c, T>
where T: Unpin,

§

impl<'c, T> !UnwindSafe for BufferMapCmd<'c, T>

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.