pub struct ExecutionContext { /* private fields */ }Expand description
Execution context for NPU operations.
Implementations§
Source§impl ExecutionContext
impl ExecutionContext
Sourcepub fn new(device: Arc<NpuDevice>) -> Self
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}Sourcepub fn execute_matmul(
&self,
a: &ArrayD<f32>,
b: &ArrayD<f32>,
) -> Result<ArrayD<f32>>
pub fn execute_matmul( &self, a: &ArrayD<f32>, b: &ArrayD<f32>, ) -> Result<ArrayD<f32>>
Execute matrix multiplication operation.
Sourcepub fn execute_batched_matmul(
&self,
a: &ArrayD<f32>,
b: &ArrayD<f32>,
) -> Result<ArrayD<f32>>
pub fn execute_batched_matmul( &self, a: &ArrayD<f32>, b: &ArrayD<f32>, ) -> Result<ArrayD<f32>>
Execute batched matrix multiplication.
Sourcepub fn execute_conv1x1(
&self,
input: &ArrayD<f32>,
kernel: &ArrayD<f32>,
) -> Result<ArrayD<f32>>
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}Sourcepub fn get_current_throughput_gops(&self) -> f64
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}Sourcepub fn get_metrics(&self) -> PerformanceMetrics
pub fn get_metrics(&self) -> PerformanceMetrics
Get performance metrics.
Sourcepub fn get_device(&self) -> Arc<NpuDevice>
pub fn get_device(&self) -> Arc<NpuDevice>
Get underlying device.
Auto Trait Implementations§
impl Freeze for ExecutionContext
impl !RefUnwindSafe for ExecutionContext
impl Send for ExecutionContext
impl Sync for ExecutionContext
impl Unpin for ExecutionContext
impl !UnwindSafe for ExecutionContext
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
Mutably borrows from an owned value. Read more