Realm

Verify device admission in Rust

Current source-owned tutorial. API availability differs by language.

Rust

Start the walkthrough · Jump to complete source

The smallest possible smoke test for a working OA install: enumerate or select a Vulkan device, capture a minimal matrix operation into an execution plan, submit it, and print structured device and execution evidence. Exit code zero confirms the device is admitted; any runtime or dispatch failure propagates a nonzero exit. Set OA_VK_VALIDATION=1 to enable Vulkan validation layers. The output below is from the Rust run with OA 0.18.0 on Intel Iris Xe with Mesa 26.3.1.

Run in Rust

From the OASDK root, with oa-dev as a sibling checkout:

cargo run --release --example tu_core_device_canary

Pass --list-devices to print every Vulkan device OA enumerates, or --device INDEX to force a specific one.

1$ cargo run --release --example tu_core_device_canary -- --list-devices
2[0] Intel(R) Iris(R) Xe Graphics (ADL GT2) · Integrated · Vulkan 1.4.363
3[1] llvmpipe (LLVM 23.1.5, 256 bits) · Cpu · Vulkan 1.4.363
4

1. Build the runtime on the selected device

Runtime::builder().devices(...) accepts DeviceSelection::Automatic or an explicit index. Runtime::set_default installs the built runtime so the matrix:: module functions, which record on the default runtime, produce work that capture can see.

1let runtime = Runtime::builder().devices(selection).build()?;
2Runtime::set_default(runtime.clone());
3

2. Capture a minimal plan

runtime.capture records ones + full(2) → add as an execution plan rather than running it eagerly. submit returns an Event; wait completes the device work without a host readback.

1let (plan, result) = runtime.capture(|| {
2 let a = matrix::ones([64, 128])?;
3 let b = matrix::full([64, 128], 2.0_f32)?;
4 matrix::add(&a, &b)
5})?;
6runtime.submit(&plan)?.wait()?;
7

3. Inspect the diagnostics

plan.diagnostics() counts nodes and barriers in the compiled plan and read_f32 verifies the result. One matrix.add.f32 dispatch writes the output.

1OA device canary
2 nodes: 1
3 barriers: 0
4 schema: 1
5 add(Ones, full(2))[0] = 3.0
6

4. Emit the evidence report

plan.debug_report_json prints the full execution plan: compilation status, dispatch and barrier statistics, per resource byte counts, kernel selection and content hashes, and the recorded node list. The JSON is suitable for capture into an evidence bundle or a scheduler admission record.

1{
2 "schema": "oa.execution_graph.v3",
3 "name": "device_canary",
4 "compiled": true,
5 "stats": {"dispatches": 1, "barriers": 0, "kernel_fallbacks": 0, ...},
6 "nodes": [
7 {"index": 0, "operation": "oa::FnMatrix::add", "kernel": "matrix.add.f32",
8 "dtype": "float32", "groups": [32, 1, 1], "queue": "compute", ...}
9 ]
10}
11

The Python bindings do not expose execution plan capture yet, so this tutorial is Rust only.

Source

Rust example

Example

Tu_core_device_canary.rs

1// OA Tutorial: device admission canary.
2//
3// Constructs an Runtime, runs a minimal captured matrix operation, and prints
4// a structured summary of the device and execution evidence. Exit code 0
5// confirms the device is admitted; any runtime or dispatch failure exits with
6// a non-zero code through the `oa::Result` propagation.
7//
8// The JSON execution-plan report is suitable for capture into an evidence
9// bundle or a scheduler admission record. Set OA_VK_VALIDATION=1 to enable
10// Vulkan validation layers.
11//
12// Mirrors the intent of sdk/cpp/tutorials/core/tuCoreDeviceCanary.cpp.
13use oa::{DeviceSelection, Runtime, matrix};
14
15fn main() -> anyhow::Result<()> {
16 let mut selection = DeviceSelection::Automatic;
17 let mut arguments = std::env::args().skip(1);
18 while let Some(argument) = arguments.next() {
19 match argument.as_str() {
20 "--list-devices" => {
21 for device in Runtime::available_devices()? {
22 println!(
23 "[{}] {} · {:?} · Vulkan {}",
24 device.index(),
25 device.name(),
26 device.kind(),
27 device.api_version()
28 );
29 }
30 return Ok(());
31 }
32 "--device" => {
33 let index = arguments
34 .next()
35 .ok_or_else(|| anyhow::anyhow!("--device requires an index"))?;
36 selection = DeviceSelection::Index(
37 index
38 .parse()
39 .map_err(|_| anyhow::anyhow!("--device requires a nonnegative integer"))?,
40 );
41 }
42 _ => {
43 return Err(anyhow::anyhow!(
44 "unknown argument {argument}; use --list-devices or --device INDEX"
45 ));
46 }
47 }
48 }
49 let runtime = Runtime::builder().devices(selection).build().map_err(|e| {
50 eprintln!("device canary: Runtime construction failed: {e}");
51 e
52 })?;
53 Runtime::set_default(runtime.clone());
54
55 // Capture a minimal plan: ones + full(2) → add. The plan diagnostics
56 // and debug report are the device-admission evidence.
57 let (plan, result) = runtime.capture(|| {
58 let a = matrix::ones([64, 128])?;
59 let b = matrix::full([64, 128], 2.0_f32)?;
60 matrix::add(&a, &b)
61 })?;
62
63 let event = runtime.submit(&plan)?;
64 event.wait()?;
65
66 let values = result.read_f32()?;
67 let first = values.first().copied().unwrap_or(f32::NAN);
68
69 let diagnostics = plan.diagnostics();
70 let report_json = plan.debug_report_json("device_canary");
71
72 println!("OA device canary");
73 println!(" nodes: {}", diagnostics.node_count());
74 println!(" barriers: {}", diagnostics.barrier_count());
75 println!(" schema: {}", diagnostics.schema_owned_node_count());
76 println!(" add(Ones, full(2))[0] = {first:.1}");
77 println!();
78 println!("{report_json}");
79
80 assert!(
81 (first - 3.0_f32).abs() <= 1e-5,
82 "device canary arithmetic failed: expected 3.0 but got {first}"
83 );
84 assert_eq!(diagnostics.node_count(), 1, "expected one compute node");
85 Ok(())
86}
87

Run Rust tutorials from the OA SDK 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.