Struct ocl::builders::BufferBuilder

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

A buffer builder.

Implementations§

source§

impl<'a, T> BufferBuilder<'a, T>
where T: 'a + OclPrm,

source

pub fn new() -> BufferBuilder<'a, T>

Returns a new buffer builder.

source

pub fn context<'o>(self, context: &'o Context) -> BufferBuilder<'a, T>
where 'o: 'a,

Sets the context with which to associate the buffer.

May not be used in conjunction with ::queue (use one or the other).

source

pub fn queue(self, default_queue: Queue) -> BufferBuilder<'a, T>

Specifies the default queue used to be used by the buffer for all command enqueue operations (reads, writes, etc.).

The default queue is the queue which will be used when enqueuing commands if no queue is specified.

Without a default queue:

buffer.read(data).queue(&queue).enq()?;

With a default queue:

buffer.read(data).enq()?;

If this is set, the context associated with the default_queue will be used when creating the buffer. Attempting to specify the context separately (by calling ::context) will cause a panic.

source

pub fn flags(self, flags: MemFlags) -> BufferBuilder<'a, T>

Sets the flags used when creating the buffer.

Defaults to flags::MEM_READ_WRITE aka. MemFlags::new().read_write() if this is not set. See the SDK Docs for more information about flags. Note that the names of all flags in this library have the CL_ prefix removed for brevity.

§Panics

Due to its unsafety, setting the MEM_USE_HOST_PTR/MemFlags::new()::use_host_ptr() flag will cause a panic. Use the ::use_host_slice method instead.

source

pub unsafe fn use_host_slice<'d>( self, host_slice: &'d [T] ) -> BufferBuilder<'a, T>
where 'd: 'a,

Specifies a region of host memory to use as storage for the buffer.

OpenCL implementations are allowed to cache the buffer contents pointed to by host_slice in device memory. This cached copy can be used when kernels are executed on a device.

The result of OpenCL commands that operate on multiple buffer objects created with the same host_slice or overlapping host regions is considered to be undefined

Refer to the description of the alignment rules for host_slice for memory objects (buffer and images) created using this method.

Automatically sets the flags::MEM_USE_HOST_PTR aka. MemFlags::new().use_host_ptr() flag.

§Panics

::copy_host_slice or ::use_host_slice must not have already been called.

§Safety

The caller must ensure that host_slice lives until the buffer is destroyed. The caller must also ensure that only one buffer uses host_slice and that it is not tampered with inappropriately.

source

pub fn copy_host_slice<'d>(self, host_slice: &'d [T]) -> BufferBuilder<'a, T>
where 'd: 'a,

Specifies a region of memory to copy into the buffer upon creation.

Automatically sets the flags::MEM_COPY_HOST_PTR aka. MemFlags::new().copy_host_ptr() flag.

§Panics

::copy_host_slice or ::use_host_slice must not have already been called.

source

pub fn len<D>(self, len: D) -> BufferBuilder<'a, T>
where D: Into<SpatialDims>,

Sets the length for this buffer.

Note that although sizes in the standard OpenCL API are expressed in bytes, sizes, lengths, and dimensions in this library are always specified in bytes / sizeof(T) (like everything else in Rust) unless otherwise noted.

source

pub fn fill_val(self, fill_val: T) -> BufferBuilder<'a, T>

Allows the caller to automatically fill the buffer with a value (such as zero) immediately after creation.

Use ::fill_event to set an event associated with the completion of the fill command if you want it to execute asynchronously (it will otherwise block the calling thread).

Platforms that have trouble with clEnqueueFillBuffer such as pocl should not use this option and should handle initializing buffers manually (using a kernel or copy host data flag).

§Examples
  • TODO: Provide examples once this stabilizes.

[UNSTABLE]: May be changed or removed.

source

pub fn fill_event<'b, 'e, En>(self, enew: En) -> BufferBuilder<'a, T>
where En: Into<ClNullEventPtrEnum<'e>>, 'e: 'a,

Specifies the (empty) event to use for association with the completion of the fill command.

enew specifies an empty event (generally a &mut Event) to be associated with the fill command which will be enqueued after creation and just before returning the new buffer. It is up to the caller to ensure that the command has completed before performing any other operations on the buffer. Failure to do so may cause the fill command to run after subsequently queued commands if multiple or out-of-order queues are being used.

Not calling this method at all will cause the fill command to block before returning the new buffer and is the safe option if you don’t want to worry about it.

source

pub fn build(self) -> OclResult<Buffer<T>>

Creates a buffer and returns it.

Dimensions and either a context or default queue must be specified before calling ::build.

Trait Implementations§

source§

impl<'a, T> Debug for BufferBuilder<'a, T>
where T: OclPrm + Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for BufferBuilder<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for BufferBuilder<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for BufferBuilder<'a, T>

§

impl<'a, T> Sync for BufferBuilder<'a, T>

§

impl<'a, T> Unpin for BufferBuilder<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for BufferBuilder<'a, 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.