Skip to main content

Command

Struct Command 

Source
pub struct Command<'a> { /* private fields */ }
Expand description

A recording owner. Outputs remain inaccessible until blocking completion. Dropping or forgetting this owner cannot expose unfinished output storage. The pinned native API does not provide nonblocking submit or fence polling.

Recording retains a network borrow until completion or cancellation.

ⓘ
use ncnn_rust::{gpu::Allocator, Net};
fn cannot_clear(allocator: &Allocator, net: &mut Net) {
    let command = allocator.command(net).unwrap();
    net.clear();
    command.wait().unwrap();
}

Implementations§

Source§

impl<'a> Command<'a>

Source

pub fn input(&mut self, name: &str, tensor: &'a Tensor) -> Result<()>

Records one resident input for this command.

The tensor must belong to the same device as the allocator, and inputs have to be recorded before the first extract. A rejected recording leaves the command in a failed state that only dropping it resolves.

Source

pub fn extract(&mut self, name: &str) -> Result<usize>

Records an output and returns its index in the completed output vector.

The output storage belongs to the allocator from this call on, so it counts towards Allocator::tensor_bytes before any work is submitted. Recording an output closes input recording for this command.

Source

pub fn wait(self) -> Result<Vec<Tensor>>

Submits recorded work and blocks for native fence completion.

The returned tensors are completed and safe to read through Tensor::download or Tensor::guard. A native recording failure cancels the command instead of submitting it, so a failed record never reaches the device.

Trait Implementations§

Source§

impl Drop for Command<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Command<'a>

§

impl<'a> !Send for Command<'a>

§

impl<'a> !Sync for Command<'a>

§

impl<'a> !UnwindSafe for Command<'a>

§

impl<'a> Freeze for Command<'a>

§

impl<'a> Unpin for Command<'a>

§

impl<'a> UnsafeUnpin for Command<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.