Engine and device introduction
Source-owned programs from the current OA SDK. Rust and Python examples follow their respective public APIs.
Rust · Python
Example
Tu_core_engine_intro.rs
1use oa::{Engine, matrix};23fn main() -> oa::Result<()> {4 let engine = Engine::new()?;56 println!("OA engine");78 // Domain operations record into the engine's private eager session. No9 // public graph or context object is required. The matrix values are10 // returned immediately as semantic handles.11 let a = matrix::ones([64, 128])?;12 let b = matrix::full([64, 128], 2.0_f32)?;13 let output = matrix::add(&a, &b)?;1415 // `engine.checkpoint()` submits all pending eager work and returns an16 // Event without blocking the host. Calling it is optional — host17 // observation (read_f32 below) also flushes and waits.18 let checkpoint = engine.checkpoint()?;19 checkpoint.wait()?;2021 // `read_f32` is the explicit device-to-host boundary. It flushes any22 // remaining eager work, waits for the result, and copies to a Vec.23 let values = output.read_f32()?;24 let first = values.first().copied().unwrap_or(f32::NAN);2526 println!(" add(Ones, full(2))[0] = {first:.1}");27 println!(" shape: {:?}", output.shape());28 println!(" elements: {}", values.len());2930 assert!(31 (first - 3.0_f32).abs() <= 1e-5,32 "unexpected value: expected 3.0 but got {first}"33 );34 assert_eq!(output.shape(), [64, 128]);35 assert_eq!(values.len(), 64 * 128);36 Ok(())37}38
Run Rust tutorials from the OA checkout with cargo run --release --example <name>. Run Python with the environment containing the OA native extension. Consult each program's arguments and capability checks before running it.