use trueno::Vector;
#[test]
fn test_d051_ptx_validation_infrastructure() {
let entry_point_pattern = r"\.entry\s+\w+";
let regex = regex::Regex::new(entry_point_pattern);
assert!(regex.is_ok(), "D-051 FALSIFIED: Cannot compile PTX entry point pattern");
}
#[test]
fn test_d052_shared_memory_pattern() {
let shared_mem_pattern = r"\.shared\s+\.align\s+\d+\s+\.b\d+";
let regex = regex::Regex::new(shared_mem_pattern);
assert!(regex.is_ok(), "D-052 FALSIFIED: Cannot compile shared memory pattern");
}
#[test]
fn test_d053_barrier_sync_pattern() {
let barrier_pattern = r"bar\.sync\s+\d+";
let regex = regex::Regex::new(barrier_pattern);
assert!(regex.is_ok(), "D-053 FALSIFIED: Cannot compile barrier sync pattern");
}
#[test]
fn test_d054_attention_kernel_naming() {
let causal_pattern = r"_causal$";
let regex = regex::Regex::new(causal_pattern);
assert!(regex.is_ok(), "D-054 FALSIFIED: Cannot compile causal kernel pattern");
assert!(regex.as_ref().unwrap().is_match("attention_kernel_causal"));
assert!(!regex.as_ref().unwrap().is_match("attention_kernel"));
}
#[test]
fn test_d055_causal_suffix() {
let kernel_names = vec![
("gemm_kernel", false),
("attention_causal", true),
("attention_kernel_causal", true),
("causal_attention", false), ("softmax_kernel", false),
];
for (name, should_be_causal) in kernel_names {
let has_causal_suffix = name.ends_with("_causal") || name.ends_with("causal");
if should_be_causal {
assert!(
has_causal_suffix,
"D-055 FALSIFIED: Causal kernel {name} should have causal suffix"
);
}
}
}
#[test]
fn test_d056_softmax_stability() {
let large_values = Vector::from_slice(&[1000.0f32, 1001.0, 1002.0]);
let result = large_values.softmax();
assert!(result.is_ok(), "D-056 FALSIFIED: Softmax failed on large values");
let softmax = result.unwrap();
for (i, val) in softmax.as_slice().iter().enumerate() {
assert!(val.is_finite(), "D-056 FALSIFIED: Softmax produced non-finite value at index {i}");
}
}
#[test]
fn test_d057_layernorm_constant_input() {
let constant = vec![5.0f32; 8];
let _vec_const = Vector::from_slice(&constant);
let mean: f32 = constant.iter().sum::<f32>() / constant.len() as f32;
let centered: Vec<f32> = constant.iter().map(|x| x - mean).collect();
for (i, val) in centered.iter().enumerate() {
assert!(val.abs() < 1e-6, "D-057: Constant input should center to zero at index {i}");
}
}
#[test]
fn test_d058_quantization_range() {
let input: Vec<f32> = (0..100).map(|i| i as f32 / 100.0).collect();
for val in &input {
let scaled = val * 255.0;
assert!(
(0.0..=255.0).contains(&scaled),
"D-058 FALSIFIED: Scaled value {} out of [0,255] range",
scaled
);
let _quantized = scaled.round() as u8;
}
}
#[test]
fn test_d059_loop_branch_pattern() {
let incorrect_pattern = r"bra\s+END";
let correct_pattern = r"bra\s+LOOP_START";
let regex_incorrect = regex::Regex::new(incorrect_pattern).unwrap();
let regex_correct = regex::Regex::new(correct_pattern).unwrap();
assert!(regex_incorrect.is_match("bra END"), "D-059: Pattern should match incorrect branch");
assert!(regex_correct.is_match("bra LOOP_START"), "D-059: Pattern should match correct branch");
}
#[test]
fn test_d060_register_validation() {
const MAX_REGISTERS: u32 = 255;
let allocations = vec![32, 64, 128, 200, 255];
for alloc in allocations {
assert!(
alloc <= MAX_REGISTERS,
"D-060 FALSIFIED: Register allocation {} exceeds limit {}",
alloc,
MAX_REGISTERS
);
}
}
#[test]
fn test_d061_compute_capability() {
let valid_capabilities = vec!["sm_70", "sm_75", "sm_80", "sm_86", "sm_89", "sm_90"];
let pattern = regex::Regex::new(r"^sm_\d{2}$").unwrap();
for cap in valid_capabilities {
assert!(
pattern.is_match(cap),
"D-061 FALSIFIED: Invalid compute capability format: {}",
cap
);
}
}
#[test]
fn test_d062_grid_block_dimensions() {
const MAX_BLOCK_X: u32 = 1024;
const MAX_BLOCK_Y: u32 = 1024;
const MAX_BLOCK_Z: u32 = 64;
const MAX_THREADS_PER_BLOCK: u32 = 1024;
let test_configs = vec![
(256, 1, 1), (16, 16, 1), (8, 8, 4), (32, 32, 1), (1024, 1, 1), ];
for (x, y, z) in test_configs {
assert!(x <= MAX_BLOCK_X, "D-062 FALSIFIED: Block X {} exceeds max {}", x, MAX_BLOCK_X);
assert!(y <= MAX_BLOCK_Y, "D-062 FALSIFIED: Block Y {} exceeds max {}", y, MAX_BLOCK_Y);
assert!(z <= MAX_BLOCK_Z, "D-062 FALSIFIED: Block Z {} exceeds max {}", z, MAX_BLOCK_Z);
assert!(
x * y * z <= MAX_THREADS_PER_BLOCK,
"D-062 FALSIFIED: Total threads {} exceeds max {}",
x * y * z,
MAX_THREADS_PER_BLOCK
);
}
}
#[test]
fn test_d063_shared_memory_limit() {
const MAX_SHARED_MEMORY: usize = 48 * 1024;
let test_allocations = vec![
1024, 4096, 16384, 32768, 48 * 1024 - 1, ];
for alloc in test_allocations {
assert!(
alloc <= MAX_SHARED_MEMORY,
"D-063 FALSIFIED: Shared memory {} exceeds limit {}",
alloc,
MAX_SHARED_MEMORY
);
}
}
#[test]
fn test_d064_register_limit() {
const MAX_REGISTERS: u32 = 255;
for reg_count in [32, 64, 128, 255] {
assert!(
reg_count <= MAX_REGISTERS,
"D-064 FALSIFIED: Register count {} exceeds limit",
reg_count
);
}
}
#[test]
fn test_d065_ptx_vs_cpu_reference() {
let cpu_result = [1.0f32, 2.0, 3.0, 4.0];
let simulated_gpu_result = [1.0f32, 2.0, 3.0, 4.0];
let tolerance = 1e-5;
for (i, (cpu, gpu)) in cpu_result.iter().zip(simulated_gpu_result.iter()).enumerate() {
let diff = (cpu - gpu).abs();
assert!(
diff <= tolerance,
"D-065 FALSIFIED: PTX result differs from CPU at index {i}: {} vs {}",
gpu,
cpu
);
}
}