pub struct Transaction<B: Backend> { /* private fields */ }Expand description
A transaction can read multiple tensors at once with a single operation improving compute utilization with optimized laziness.
§Example
ⓘ
let [output_data, loss_data, targets_data] = Transaction::default()
.register(output)
.register(loss)
.register(targets)
.execute()
.try_into()
.expect("Correct amount of tensor data");Implementations§
Source§impl<B: Backend> Transaction<B>
impl<B: Backend> Transaction<B>
Sourcepub fn register<const D: usize, K: BasicOps<B>>(
self,
tensor: Tensor<B, D, K>,
) -> Self
pub fn register<const D: usize, K: BasicOps<B>>( self, tensor: Tensor<B, D, K>, ) -> Self
Add a tensor to the transaction to be read.
Sourcepub fn execute(self) -> Vec<TensorData>
pub fn execute(self) -> Vec<TensorData>
Executes the transaction synchronously and returns the data in the same order in which they were registered.
Sourcepub fn try_execute(self) -> Result<Vec<TensorData>, ExecutionError>
pub fn try_execute(self) -> Result<Vec<TensorData>, ExecutionError>
Executes the transaction synchronously and returns the data in the same order in which they were registered.
§Returns
Any error that might have occurred since the last time the device was synchronized.
Sourcepub async fn execute_async(self) -> Result<Vec<TensorData>, ExecutionError>
pub async fn execute_async(self) -> Result<Vec<TensorData>, ExecutionError>
Executes the transaction asynchronously and returns the data in the same order in which they were registered.
Trait Implementations§
Auto Trait Implementations§
impl<B> Freeze for Transaction<B>
impl<B> RefUnwindSafe for Transaction<B>where
<B as Backend>::FloatTensorPrimitive: RefUnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: RefUnwindSafe,
<B as Backend>::IntTensorPrimitive: RefUnwindSafe,
<B as Backend>::BoolTensorPrimitive: RefUnwindSafe,
impl<B> Send for Transaction<B>
impl<B> Sync for Transaction<B>
impl<B> Unpin for Transaction<B>where
<B as Backend>::FloatTensorPrimitive: Unpin,
<B as Backend>::QuantizedTensorPrimitive: Unpin,
<B as Backend>::IntTensorPrimitive: Unpin,
<B as Backend>::BoolTensorPrimitive: Unpin,
impl<B> UnwindSafe for Transaction<B>where
<B as Backend>::FloatTensorPrimitive: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: UnwindSafe,
<B as Backend>::IntTensorPrimitive: UnwindSafe,
<B as Backend>::BoolTensorPrimitive: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more