pub struct Command<'a, D: Driver> { /* private fields */ }Expand description
One unit of work against the device: the context that holds its compiled kernels, and the streams it was resolved against.
Built per operation rather than held, because resolving is what orders the current stream behind whichever streams own the buffers it was given.
Implementations§
Source§impl<'a, D: Driver> Command<'a, D>
impl<'a, D: Driver> Command<'a, D>
Sourcepub fn new(
ctx: &'a mut D::Context,
streams: ResolvedStreams<'a, D::Backend>,
service: ServiceId,
) -> Self
pub fn new( ctx: &'a mut D::Context, streams: ResolvedStreams<'a, D::Backend>, service: ServiceId, ) -> Self
A command against ctx over the streams streams resolved.
Sourcepub fn stream(&mut self) -> &mut D::Stream
pub fn stream(&mut self) -> &mut D::Stream
The stream this command is issued on.
The one part of the resolution a backend reaches for directly: the driver calls take a stream, and this is the one they take.
Sourcepub fn resource(
&mut self,
binding: BufferBinding,
) -> Result<DeviceResource<D>, IoError>
pub fn resource( &mut self, binding: BufferBinding, ) -> Result<DeviceResource<D>, IoError>
The device allocation binding names, resolved on the stream that
created it rather than the current one.
§Errors
IoError::StorageHandleNotFound when the binding names no live allocation.
Sourcepub fn memory_usage(&mut self) -> MemoryUsage
pub fn memory_usage(&mut self) -> MemoryUsage
The current stream’s device memory usage.
Sourcepub fn memory_report(&mut self) -> MemoryReport
pub fn memory_report(&mut self) -> MemoryReport
Structured per-pool report of the current stream’s device memory.
Sourcepub fn memory_cleanup(&mut self)
pub fn memory_cleanup(&mut self)
Release everything the current stream is holding that nothing still needs.
Sourcepub fn flush_drops(&mut self)
pub fn flush_drops(&mut self)
Flush the current stream’s drop queue, freeing what the device is known to be done with.
Deferred while the stream records a graph — the flush records a fence on the capturing stream, which corrupts the recording — and the window drains the queue itself when it closes. The rule lives here, on the one path a server has to the queue, so no call site can rebuild the flush without the guard.
Sourcepub fn allocation_mode(&mut self, mode: MemoryAllocationMode)
pub fn allocation_mode(&mut self, mode: MemoryAllocationMode)
Set the MemoryAllocationMode for the current stream.
Sourcepub fn install_memory_pools(
&mut self,
config: MemoryConfiguration,
props: &MemoryDeviceProperties,
) -> Result<(), InstallMemoryPoolsError>
pub fn install_memory_pools( &mut self, config: MemoryConfiguration, props: &MemoryDeviceProperties, ) -> Result<(), InstallMemoryPoolsError>
Rebuild the current stream’s device pools with a new layout, keeping the old one when something is still live in them.
§Errors
InstallMemoryPoolsError::PoolsInUse when the rebuild was refused.
Sourcepub fn reserve(&mut self, size: u64) -> Result<ManagedMemoryHandle, IoError>
pub fn reserve(&mut self, size: u64) -> Result<ManagedMemoryHandle, IoError>
Allocate size bytes of device memory on the current stream.
§Errors
IoError::BufferTooBig when no device could ever fit it, and
whatever the allocator reports when a reclaim-and-retry still cannot.
Sourcepub fn empty(&mut self, size: u64) -> Result<Handle, IoError>
pub fn empty(&mut self, size: u64) -> Result<Handle, IoError>
Allocate size bytes of device memory and a handle naming it.
§Errors
Whatever the allocation or the bind reports.
Sourcepub fn bind(
&mut self,
reserved: ManagedMemoryHandle,
new: ManagedMemoryHandle,
) -> Result<(), IoError>
pub fn bind( &mut self, reserved: ManagedMemoryHandle, new: ManagedMemoryHandle, ) -> Result<(), IoError>
Sourcepub fn reserve_cpu(&mut self, size: usize, origin: Option<StreamId>) -> Bytes
pub fn reserve_cpu(&mut self, size: usize, origin: Option<StreamId>) -> Bytes
size bytes of host memory, pinned when the pool can serve it.
Pinned pages transfer by DMA without a bounce, but they are scarce, so an exhausted pool falls back to the heap rather than failing: this always answers with a buffer of the size asked for.
Sourcepub fn read_async(
&mut self,
descriptors: Vec<CopyDescriptor>,
) -> impl Future<Output = Result<Vec<Bytes>, ServerError>> + Send + use<D>
pub fn read_async( &mut self, descriptors: Vec<CopyDescriptor>, ) -> impl Future<Output = Result<Vec<Bytes>, ServerError>> + Send + use<D>
Copy each descriptor’s device memory back to the host, resolving once the copies have landed.
The copies are enqueued before the future is returned; awaiting it waits on the fence that follows them.
§Errors
IoError::UnsupportedStrides for a layout the driver cannot copy,
and whatever the fence reports when the stream itself failed.
Sourcepub fn write_to_cpu(
&mut self,
descriptor: CopyDescriptor,
bytes: &mut Bytes,
stream_id: Option<StreamId>,
) -> Result<(), IoError>
pub fn write_to_cpu( &mut self, descriptor: CopyDescriptor, bytes: &mut Bytes, stream_id: Option<StreamId>, ) -> Result<(), IoError>
Enqueue a copy of descriptor’s device memory into bytes.
§Errors
IoError::UnsupportedStrides for a layout that is not pitched
row-major, IoError::StorageHandleNotFound for a binding that names no live
allocation, and the driver’s refusal to copy.
Sourcepub fn write_to_gpu(
&mut self,
descriptor: CopyDescriptor,
data: Bytes,
) -> Result<(), IoError>
pub fn write_to_gpu( &mut self, descriptor: CopyDescriptor, data: Bytes, ) -> Result<(), IoError>
Enqueue a copy of data into the device memory descriptor names.
§Errors
IoError::UnsupportedStrides for a layout that is not pitched
row-major, IoError::StorageHandleNotFound for a binding that names no live
allocation, and the driver’s refusal to copy.
Sourcepub fn create_with_data(&mut self, data: &[u8]) -> Result<Handle, IoError>
pub fn create_with_data(&mut self, data: &[u8]) -> Result<Handle, IoError>
Allocate device memory for data and enqueue the copy into it.
§Errors
Whatever the allocation or the copy reports.
Sourcepub fn sync(&mut self) -> DynFut<Result<(), ServerError>>
pub fn sync(&mut self) -> DynFut<Result<(), ServerError>>
Wait for everything already enqueued on the current stream to finish.
§Errors
The fault the barrier reveals, when the stream itself failed.
Sourcepub fn kernel(
&mut self,
kernel: KernelId,
count: (u32, u32, u32),
args: &mut D::LaunchArgs,
) -> Result<(), LaunchError>
pub fn kernel( &mut self, kernel: KernelId, count: (u32, u32, u32), args: &mut D::LaunchArgs, ) -> Result<(), LaunchError>
Enqueue an already-compiled kernel on the current stream.
§Errors
The driver’s refusal to enqueue the launch, returned whether or not a profile is open. An open profile is not a reason to hold the failure here: the caller’s write scope is what claims the buffers the launch never wrote, and the caller invalidates every open profile on the same path, so keeping it would lose the claim and duplicate the report.
Auto Trait Implementations§
impl<'a, D> !RefUnwindSafe for Command<'a, D>
impl<'a, D> !UnwindSafe for Command<'a, D>
impl<'a, D> Freeze for Command<'a, D>
impl<'a, D> Send for Command<'a, D>
impl<'a, D> Sync for Command<'a, D>
impl<'a, D> Unpin for Command<'a, D>
impl<'a, D> UnsafeUnpin for Command<'a, D>where
&'a mut <D as Driver>::Context: UnsafeUnpin,
ResolvedStreams<'a, <D as Driver>::Backend>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more