ruxla_testing/lib.rs
1//! The test harness of ruxla.
2//!
3//! Following PyTorch's OpInfo, each primitive declares test samples
4//! ([`OpInfo`]): parameters and arguments for the element types to test. A
5//! shared harness then runs the same checks on every primitive:
6//!
7//! - [`check_op`] evaluates each sample with the interpreter and with the
8//! native backend's operations ([`ruxla_core::eval_native`]), which must
9//! agree bit for bit (both use `ruxla-kernels`);
10//! - [`check_op_xla`] lowers each sample to StableHLO, runs it with XLA
11//! through a PJRT plugin, and compares it with the interpreter, for every
12//! element type the primitive accepts. XLA is the independent reference;
13//! - [`check_op_vmap`] batches each sample with `vmap` and compares the
14//! batched function with a loop over examples ([`check_vmap`]);
15//! - [`random_function`] makes random well-typed programs, to compare the
16//! three on combinations of primitives.
17//!
18//! # Examples
19//!
20//! ```
21//! use ruxla_testing::{check_op, op_infos};
22//!
23//! let add = op_infos().into_iter().find(|info| info.name() == "add").unwrap();
24//! assert!(check_op(&add, 0).is_empty());
25//! ```
26
27mod ad;
28mod fuzz;
29mod opinfo;
30mod ops;
31mod ops_linalg;
32mod rng;
33mod vmap;
34
35pub use ad::{AdReport, check_function_ad, check_op_ad};
36pub use fuzz::random_function;
37pub use opinfo::{
38 Failure, OpInfo, Sample, SamplesFn, XlaReport, check_op, check_op_xla, compare,
39 pjrt_cpu_client, run_with_xla, single_equation, tolerance, values_close, xla_tolerance,
40};
41pub use ops::op_infos;
42pub use rng::{Domain, Rng, edge_values, from_values};
43pub use vmap::{
44 check_op_vmap, check_op_vmap_xla, check_vmap, check_vmap_xla, check_vmap_xla_only, stack,
45};