ExecutionContext

Struct ExecutionContext 

Source
pub struct ExecutionContext { /* private fields */ }
Expand description

Execution context for NPU operations.

Implementations§

Source§

impl ExecutionContext

Source

pub fn new(device: Arc<NpuDevice>) -> Self

Create a new execution context.

Examples found in repository?
examples/full_inference_pipeline.rs (line 155)
149fn execute_inference() {
150    println!("4. Inference Execution");
151
152    let device = Arc::new(NpuDevice::new());
153    match device.initialize() {
154        Ok(_) => {
155            let ctx = ExecutionContext::new(device);
156            
157            let input = Tensor::random(&[1, 224, 224, 3]);
158            let weights = Tensor::random(&[1, 1, 3, 64]);
159
160            println!("   Input: {:?}", input.shape());
161            println!("   Weights: {:?}", weights.shape());
162
163            match ctx.execute_conv1x1(&input.data, &weights.data) {
164                Ok(output) => {
165                    println!("   ✓ Conv1x1 executed");
166                    println!("   Output: {:?}", output.shape());
167                    println!("   Throughput: {:.4} GOPS\n", ctx.get_current_throughput_gops());
168                }
169                Err(e) => println!("   ✗ Execution failed: {}\n", e),
170            }
171        }
172        Err(e) => println!("   ✗ Device init failed: {}\n", e),
173    }
174}
Source

pub fn execute_matmul( &self, a: &ArrayD<f32>, b: &ArrayD<f32>, ) -> Result<ArrayD<f32>>

Execute matrix multiplication operation.

Source

pub fn execute_batched_matmul( &self, a: &ArrayD<f32>, b: &ArrayD<f32>, ) -> Result<ArrayD<f32>>

Execute batched matrix multiplication.

Source

pub fn execute_conv1x1( &self, input: &ArrayD<f32>, kernel: &ArrayD<f32>, ) -> Result<ArrayD<f32>>

Execute 1x1 convolution.

Examples found in repository?
examples/full_inference_pipeline.rs (line 163)
149fn execute_inference() {
150    println!("4. Inference Execution");
151
152    let device = Arc::new(NpuDevice::new());
153    match device.initialize() {
154        Ok(_) => {
155            let ctx = ExecutionContext::new(device);
156            
157            let input = Tensor::random(&[1, 224, 224, 3]);
158            let weights = Tensor::random(&[1, 1, 3, 64]);
159
160            println!("   Input: {:?}", input.shape());
161            println!("   Weights: {:?}", weights.shape());
162
163            match ctx.execute_conv1x1(&input.data, &weights.data) {
164                Ok(output) => {
165                    println!("   ✓ Conv1x1 executed");
166                    println!("   Output: {:?}", output.shape());
167                    println!("   Throughput: {:.4} GOPS\n", ctx.get_current_throughput_gops());
168                }
169                Err(e) => println!("   ✗ Execution failed: {}\n", e),
170            }
171        }
172        Err(e) => println!("   ✗ Device init failed: {}\n", e),
173    }
174}
Source

pub fn get_current_throughput_gops(&self) -> f64

Get current throughput in GOPS.

Examples found in repository?
examples/full_inference_pipeline.rs (line 167)
149fn execute_inference() {
150    println!("4. Inference Execution");
151
152    let device = Arc::new(NpuDevice::new());
153    match device.initialize() {
154        Ok(_) => {
155            let ctx = ExecutionContext::new(device);
156            
157            let input = Tensor::random(&[1, 224, 224, 3]);
158            let weights = Tensor::random(&[1, 1, 3, 64]);
159
160            println!("   Input: {:?}", input.shape());
161            println!("   Weights: {:?}", weights.shape());
162
163            match ctx.execute_conv1x1(&input.data, &weights.data) {
164                Ok(output) => {
165                    println!("   ✓ Conv1x1 executed");
166                    println!("   Output: {:?}", output.shape());
167                    println!("   Throughput: {:.4} GOPS\n", ctx.get_current_throughput_gops());
168                }
169                Err(e) => println!("   ✗ Execution failed: {}\n", e),
170            }
171        }
172        Err(e) => println!("   ✗ Device init failed: {}\n", e),
173    }
174}
Source

pub fn get_metrics(&self) -> PerformanceMetrics

Get performance metrics.

Source

pub fn get_device(&self) -> Arc<NpuDevice>

Get underlying device.

Auto Trait Implementations§

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 = 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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V