Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
70 lines
2.5 KiB
Rust
70 lines
2.5 KiB
Rust
//! Shared helpers of the closed-kernel tests: they read parameter kinds from the checked-in .cu sources and from the
|
|
//! Entry tables so submodules can assert that every Rust signature matches its CUDA entry and every sealed PTX its pin.
|
|
|
|
use super::*;
|
|
use crate::s_gemv_legacy as sg;
|
|
|
|
/// `count_params`: parameter kinds of `extern "C" __global__ ... name(...)` in a `.cu` text.
|
|
fn kinds_in(source: &str, name: &str) -> Vec<&'static str> {
|
|
let at = source.find(&format!(" {name}(")).unwrap_or_else(|| panic!("{name} not in source"));
|
|
let rest = &source[at + name.len() + 2..];
|
|
let close = rest.find(") {").expect("parameter list end");
|
|
rest[..close]
|
|
.split(',')
|
|
.map(|param| {
|
|
let p = param.trim();
|
|
if p.contains('*') {
|
|
"ptr"
|
|
} else if p.starts_with("long long") || p.starts_with("uint64_t") {
|
|
"i64"
|
|
} else if p.starts_with("int ") {
|
|
"i32"
|
|
} else if p.starts_with("float ") {
|
|
"f32"
|
|
} else {
|
|
panic!("unrecognised parameter `{p}` of {name}")
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
/// The S-form entries are generated by macros: expand the two argument macros to find their parameter kinds.
|
|
fn macro_kinds(source: &str, macro_name: &str) -> Vec<&'static str> {
|
|
let at = source.find(&format!("#define {macro_name} ")).expect("macro");
|
|
let body = source[at..].lines().take(3).collect::<Vec<_>>().join(" ").replace('\\', " ");
|
|
let params = body.split_once(macro_name).unwrap().1.trim_start();
|
|
// the macro text ends at its last parameter ("int has_offset"); stop before the next `#define`
|
|
let params = params.split("#define").next().unwrap();
|
|
params
|
|
.split(',')
|
|
.map(|p| {
|
|
let p = p.trim();
|
|
if p.contains('*') {
|
|
"ptr"
|
|
} else if p.starts_with("long long") {
|
|
"i64"
|
|
} else if p.starts_with("int ") {
|
|
"i32"
|
|
} else {
|
|
panic!("unrecognised macro parameter `{p}`")
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn arg_kinds(entry: &Entry) -> Vec<&'static str> {
|
|
entry
|
|
.args
|
|
.iter()
|
|
.map(|a| match a {
|
|
Arg::Ptr | Arg::PtrOpt => "ptr",
|
|
Arg::I32 => "i32",
|
|
Arg::I64 => "i64",
|
|
Arg::F32 => "f32",
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
mod flash_and_poison_signatures_match;
|
|
mod sealed_assets_match_their_pins;
|