#[cfg(feature = "cpu")]
fn main() {
use rlx_ir::*;
use rlx_runtime::{BufferHandle, Device, Session};
let mut g = Graph::new("counter");
let state = g.input("state", Shape::new(&[4], DType::F32));
let delta = g.input("delta", Shape::new(&[4], DType::F32));
let out = g.binary(
op::BinaryOp::Add,
state,
delta,
Shape::new(&[4], DType::F32),
);
g.set_outputs(vec![out]);
let session = Session::new(Device::Cpu);
let mut compiled = session.compile(g);
let _kv = BufferHandle::new("state", &[4], DType::F32);
let mut state_data = vec![0.0f32; 4];
compiled.bind_handle("state", &state_data);
compiled.bind_handle("out0", &state_data);
println!("Iteration | state");
println!("----------+----------------");
for step in 0..5 {
let delta = vec![1.0f32; 4];
let out = compiled.run(&[("delta", &delta)]);
state_data = out[0].clone();
compiled.bind_handle("state", &state_data);
println!("step {:3} | {:?}", step, state_data);
}
assert_eq!(state_data, vec![5.0; 4]);
println!("\n✓ persistent state survives across run() calls");
println!("✓ each run reads bound handle as input, output flows to next iter");
let read_back = compiled.read_handle("state").expect("handle should exist");
println!("\nread_handle(\"state\") = {:?}", read_back);
assert_eq!(read_back, state_data);
}
#[cfg(not(feature = "cpu"))]
fn main() {
eprintln!("requires --features cpu");
}