Six literal .cu ports get a pure admission/geometry module (every entry signature is cross-checked against the .cu text), a Linux-gated driver facade, #[ignore]d GPU smokes and zero-pin placeholder PTX. All modes are off by default; KAR's closed-launch ABI is widened to 24 arguments with a 64-bit scalar. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
73 lines
2.5 KiB
Rust
73 lines
2.5 KiB
Rust
#![allow(clippy::chunks_exact_to_as_chunks)]
|
|
//! Shared test helpers: the deterministic generator mirrored from `oracle/emulate_common.h` and hex codecs.
|
|
#![allow(dead_code)]
|
|
|
|
use serde_json::Value;
|
|
|
|
/// `Lcg` of `oracle/emulate_common.h`: 64-bit LCG, values taken from the high 32 bits.
|
|
pub struct Lcg(u64);
|
|
|
|
impl Lcg {
|
|
pub fn new(seed: u64) -> Self {
|
|
Self(seed)
|
|
}
|
|
pub fn next(&mut self) -> u32 {
|
|
self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
|
(self.0 >> 32) as u32
|
|
}
|
|
/// Uniform in [-1, 1) on a 2^-23 grid (integer -> float and the scale are exact).
|
|
pub fn unit(&mut self) -> f32 {
|
|
((self.next() >> 8) as i32 - (1 << 23)) as f32 * (1.0 / 8388608.0)
|
|
}
|
|
/// Approximately normal: the sum of four units, halved (left-to-right additions).
|
|
pub fn soft(&mut self) -> f32 {
|
|
let (a, b, c, d) = (self.unit(), self.unit(), self.unit(), self.unit());
|
|
(((a + b) + c) + d) * 0.5
|
|
}
|
|
pub fn below(&mut self, n: u32) -> u32 {
|
|
self.next() % n
|
|
}
|
|
}
|
|
|
|
pub fn fnv1a(bytes: &[u8]) -> u64 {
|
|
let mut h = 0xcbf2_9ce4_8422_2325u64;
|
|
for b in bytes {
|
|
h = (h ^ u64::from(*b)).wrapping_mul(0x0100_0000_01b3);
|
|
}
|
|
h
|
|
}
|
|
|
|
pub fn f32_bytes(v: &[f32]) -> Vec<u8> {
|
|
v.iter().flat_map(|x| x.to_le_bytes()).collect()
|
|
}
|
|
|
|
pub fn unhex(s: &str) -> Vec<u8> {
|
|
(0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("hex")).collect()
|
|
}
|
|
|
|
pub fn hex_f32(s: &str) -> Vec<f32> {
|
|
unhex(s).chunks_exact(4).map(|c| f32::from_le_bytes(c.try_into().unwrap())).collect()
|
|
}
|
|
|
|
pub fn hex_u16(s: &str) -> Vec<u16> {
|
|
unhex(s).chunks_exact(2).map(|c| u16::from_le_bytes(c.try_into().unwrap())).collect()
|
|
}
|
|
|
|
pub fn u16_bytes(v: &[u16]) -> Vec<u8> {
|
|
v.iter().flat_map(|x| x.to_le_bytes()).collect()
|
|
}
|
|
|
|
pub fn fixture(name: &str) -> Value {
|
|
let path = format!("{}/tests/fixtures/{name}", env!("CARGO_MANIFEST_DIR"));
|
|
serde_json::from_str(&std::fs::read_to_string(path).expect("fixture")).expect("json")
|
|
}
|
|
|
|
/// Compare a byte array with a fixture hex string, reporting the first difference.
|
|
pub fn assert_hex_eq(what: &str, got: &[u8], want_hex: &Value) {
|
|
let want = unhex(want_hex.as_str().unwrap_or_else(|| panic!("{what}: not a string")));
|
|
assert_eq!(got.len(), want.len(), "{what}: length");
|
|
if let Some(i) = got.iter().zip(&want).position(|(a, b)| a != b) {
|
|
panic!("{what}: first difference at byte {i}: got {:#04x}, kernel wrote {:#04x}", got[i], want[i]);
|
|
}
|
|
}
|