Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
19 lines
760 B
Rust
19 lines
760 B
Rust
//! Ownership of the dlopen'ed driver library (dlclose on Drop) and check(), which maps a non-zero CUDA result
|
|
//! code to Error::Driver; kept apart as the two primitives every driver-backed call depends on.
|
|
|
|
use super::{CuResult, Error, Library, Result};
|
|
|
|
impl Drop for Library {
|
|
fn drop(&mut self) {
|
|
// SAFETY: this is the successful dlopen handle, owned exactly once.
|
|
// All loaded functions live in Api alongside this Library. Driver
|
|
// owner borrows retain Api through all resource operations/cleanup.
|
|
unsafe {
|
|
libc::dlclose(self.0);
|
|
}
|
|
}
|
|
}
|
|
pub(super) fn check(operation: &'static str, code: CuResult) -> Result<()> {
|
|
if code == 0 { Ok(()) } else { Err(Error::Driver { operation, code }) }
|
|
}
|