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>
impl<'a> Command<'a>
Sourcepub fn input(&mut self, name: &str, tensor: &'a Tensor) -> Result<()>
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.
Sourcepub fn extract(&mut self, name: &str) -> Result<usize>
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.
Sourcepub fn wait(self) -> Result<Vec<Tensor>>
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.