mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime - Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after) - Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
185 lines
5.9 KiB
Rust
185 lines
5.9 KiB
Rust
//! Real CUDA Driver API acceptance workload; the caller records driver identity.
|
|
//! A pass on the original driver is only a baseline, not replacement parity.
|
|
use std::{
|
|
ffi::{c_char, c_int, c_uint, c_void, CString},
|
|
ptr,
|
|
};
|
|
type Handle = *mut c_void;
|
|
#[link(name = "cuda")]
|
|
unsafe extern "C" {
|
|
fn cuInit(flags: c_uint) -> c_int;
|
|
fn cuDriverGetVersion(version: *mut c_int) -> c_int;
|
|
fn cuDeviceGetByPCIBusId(device: *mut c_int, bus: *const c_char) -> c_int;
|
|
fn cuCtxCreate_v2(context: *mut Handle, flags: c_uint, device: c_int) -> c_int;
|
|
fn cuCtxDestroy_v2(context: Handle) -> c_int;
|
|
fn cuModuleLoad(module: *mut Handle, file: *const c_char) -> c_int;
|
|
fn cuModuleUnload(module: Handle) -> c_int;
|
|
fn cuModuleGetFunction(function: *mut Handle, module: Handle, name: *const c_char) -> c_int;
|
|
fn cuMemAlloc_v2(address: *mut u64, bytes: usize) -> c_int;
|
|
fn cuMemFree_v2(address: u64) -> c_int;
|
|
fn cuMemsetD8_v2(address: u64, value: u8, bytes: usize) -> c_int;
|
|
fn cuLaunchKernel(
|
|
function: Handle,
|
|
gx: c_uint,
|
|
gy: c_uint,
|
|
gz: c_uint,
|
|
bx: c_uint,
|
|
by: c_uint,
|
|
bz: c_uint,
|
|
shared: c_uint,
|
|
stream: Handle,
|
|
parameters: *mut Handle,
|
|
extra: *mut Handle,
|
|
) -> c_int;
|
|
fn cuCtxSynchronize() -> c_int;
|
|
fn cuMemcpyDtoH_v2(destination: Handle, source: u64, bytes: usize) -> c_int;
|
|
}
|
|
fn checked(call: &str, status: c_int) -> Result<(), String> {
|
|
if status == 0 {
|
|
Ok(())
|
|
} else {
|
|
Err(format!("{call}: CUDA status {status}"))
|
|
}
|
|
}
|
|
#[derive(Default)]
|
|
struct Resources {
|
|
context: Handle,
|
|
module: Handle,
|
|
allocation: u64,
|
|
}
|
|
impl Resources {
|
|
fn close(&mut self) -> Result<(), String> {
|
|
let mut failures = Vec::new();
|
|
unsafe {
|
|
if self.allocation != 0 {
|
|
let code = cuMemFree_v2(self.allocation);
|
|
if code == 0 {
|
|
self.allocation = 0;
|
|
} else {
|
|
failures.push(format!("cuMemFree: {code}"));
|
|
}
|
|
}
|
|
if !self.module.is_null() {
|
|
let code = cuModuleUnload(self.module);
|
|
if code == 0 {
|
|
self.module = ptr::null_mut();
|
|
} else {
|
|
failures.push(format!("cuModuleUnload: {code}"));
|
|
}
|
|
}
|
|
if !self.context.is_null() {
|
|
let code = cuCtxDestroy_v2(self.context);
|
|
if code == 0 {
|
|
self.context = ptr::null_mut();
|
|
self.module = ptr::null_mut();
|
|
self.allocation = 0;
|
|
} else {
|
|
failures.push(format!("cuCtxDestroy: {code}"));
|
|
}
|
|
}
|
|
}
|
|
if failures.is_empty() {
|
|
Ok(())
|
|
} else {
|
|
Err(failures.join(", "))
|
|
}
|
|
}
|
|
}
|
|
impl Drop for Resources {
|
|
fn drop(&mut self) {
|
|
if let Err(error) = self.close() {
|
|
eprintln!("cleanup: {error}");
|
|
}
|
|
}
|
|
}
|
|
fn run() -> Result<(), String> {
|
|
let args: Vec<_> = std::env::args().collect();
|
|
if args.len() != 4 {
|
|
return Err("usage: native-hello CUBIN PCI_BUS_ID SEED_U32".into());
|
|
}
|
|
let cubin = CString::new(args[1].as_str()).map_err(|e| e.to_string())?;
|
|
let bus = CString::new(args[2].as_str()).map_err(|e| e.to_string())?;
|
|
let mut seed: u32 = args[3].parse().map_err(|e| format!("seed: {e}"))?;
|
|
let mut version = 0;
|
|
let mut device = 0;
|
|
let mut resources = Resources::default();
|
|
let mut output = [0u32; 64];
|
|
let mut count = output.len() as u32;
|
|
unsafe {
|
|
checked("cuInit", cuInit(0))?;
|
|
checked("cuDriverGetVersion", cuDriverGetVersion(&mut version))?;
|
|
checked(
|
|
"cuDeviceGetByPCIBusId",
|
|
cuDeviceGetByPCIBusId(&mut device, bus.as_ptr()),
|
|
)?;
|
|
checked(
|
|
"cuCtxCreate",
|
|
cuCtxCreate_v2(&mut resources.context, 0, device),
|
|
)?;
|
|
checked(
|
|
"cuModuleLoad",
|
|
cuModuleLoad(&mut resources.module, cubin.as_ptr()),
|
|
)?;
|
|
let mut function = ptr::null_mut();
|
|
checked(
|
|
"cuModuleGetFunction",
|
|
cuModuleGetFunction(&mut function, resources.module, c"native_hello".as_ptr()),
|
|
)?;
|
|
checked(
|
|
"cuMemAlloc",
|
|
cuMemAlloc_v2(&mut resources.allocation, size_of_val(&output)),
|
|
)?;
|
|
checked(
|
|
"cuMemsetD8",
|
|
cuMemsetD8_v2(resources.allocation, 0xaa, size_of_val(&output)),
|
|
)?;
|
|
let mut parameters = [
|
|
ptr::from_mut(&mut resources.allocation).cast(),
|
|
ptr::from_mut(&mut seed).cast(),
|
|
ptr::from_mut(&mut count).cast(),
|
|
];
|
|
checked(
|
|
"cuLaunchKernel",
|
|
cuLaunchKernel(
|
|
function,
|
|
1,
|
|
1,
|
|
1,
|
|
count,
|
|
1,
|
|
1,
|
|
0,
|
|
ptr::null_mut(),
|
|
parameters.as_mut_ptr(),
|
|
ptr::null_mut(),
|
|
),
|
|
)?;
|
|
checked("cuCtxSynchronize", cuCtxSynchronize())?;
|
|
checked(
|
|
"cuMemcpyDtoH",
|
|
cuMemcpyDtoH_v2(
|
|
output.as_mut_ptr().cast(),
|
|
resources.allocation,
|
|
size_of_val(&output),
|
|
),
|
|
)?;
|
|
}
|
|
for (index, actual) in output.iter().enumerate() {
|
|
let expected = seed ^ (index as u32).wrapping_mul(0x9e37_79b9);
|
|
if *actual != expected {
|
|
return Err(format!(
|
|
"output[{index}]={actual:#x}, expected {expected:#x}"
|
|
));
|
|
}
|
|
}
|
|
resources.close()?;
|
|
println!("{{\"passed\":true,\"driver_api_version\":{version},\"seed\":{seed},\"verified_words\":{},\"context_destroyed\":true}}", output.len());
|
|
Ok(())
|
|
}
|
|
fn main() {
|
|
if let Err(error) = run() {
|
|
eprintln!("{error}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|