Update docs

This commit is contained in:
Andrzej Janik 2025-09-15 18:26:55 +00:00
commit 13e3853333
6 changed files with 8 additions and 54 deletions

View file

@ -1 +0,0 @@
21ef5f60a3a5efa17855a30f6b5c7d1968cd46ba

View file

@ -32,7 +32,7 @@ Run your application like this:
* Alternative method
```
LD_PRELOAD="<ZLUDA_DIRECTORY>/zluda_preload" <APPLICATION> <APPLICATION_ARGUMENTS>
LD_AUDIT="<ZLUDA_DIRECTORY>/zluda_ld:$LD_AUDIT" <APPLICATION> <APPLICATION_ARGUMENTS>
```
where `<ZLUDA_DIRECTORY>` is the directory which contains ZLUDA-provided `libcuda.so`: `zluda` if you downloaded a prebuilt package or `target/release` if you built from sources.

View file

@ -309,9 +309,7 @@ impl<'a, 'input> InsertMemSSAVisitor<'a, 'input> {
match remap {
RemapAction::PreLdPostSt { .. } => {}
RemapAction::LDStSpaceChange {
name,
new_space,
old_space,
name, new_space, ..
} => {
let generic_var = self
.resolver

View file

@ -1,21 +0,0 @@
This crate is a last resort Linux-specific solution.
Most of the time we can inject ourselves into a process by having users
set `LD_LIBRARY_PATH`.
Unfortunately, there is software out there which dynamically links to CUDA and
CUDA performance libraries using RPATH. On Linux, dynamic linker operates
using approximately this algorithm:
* If path contains `/` treat the name as a (possibly relative) path and just use it
* Otherwise return the first that succeeds:
* Library with this name already loaded into the process
* Try paths in `DT_RPATH` (if `DT_RUNPATH` is not present)
* Try paths in `LD_LIBRARY_PATH`
* Try paths in `DT_RUNPATH`
* Try system paths
In order to defeat `DT_RPATH` this library needs to be preloaded with `LD_PRELOAD`.
On initialization we also preload all the performance libraries. We also hijack
`dlopen` and on every call to `dlopen` that tries to open a CUDA library we
redirect it to our libraries
We also expose `zluda_dlopen_noredirect` for the purpose of tracing libraries
so they can load real underlying library and not just get redirected to themselves

View file

@ -36,8 +36,10 @@ static FILES_FOR_REDIRECT: [&'static str; 14] = [
// Global state, caching some computations that would be otherwise repeated
struct GlobalState {
/// The full paths of the file names from `FILES_FOR_REDIRECT` that will be used for redirection
// The full paths of the file names from `FILES_FOR_REDIRECT` that will be used for redirection
replacement_paths: Option<[Vec<u8>; FILES_FOR_REDIRECT.len()]>,
// List of cookies saved for each redirected file, to avoid self-redirecting
// when e.g. zluda_trace_blas (libcuda.so) tries to load the real libcublas.so
cookies: Mutex<[usize; FILES_FOR_REDIRECT.len() / 2]>,
}
@ -141,8 +143,7 @@ unsafe fn save_cookie(map: *mut link_map, cookie: *mut usize) -> Option<()> {
.get_mut(index)
.map(|saved_cookie| {
*saved_cookie = cookie as usize;
});
Some(())
})
}
// Public portion of glibc's struct link_map. Additional private fields omitted.

View file

@ -47,9 +47,8 @@ pub fn dlopen_local_noredirect<'a>(
#[cfg(unix)]
pub(crate) mod os {
use libc::{c_char, c_int};
use libloading::os;
use std::{borrow::Cow, ffi::c_void, mem};
use std::borrow::Cow;
pub fn open_driver() -> Result<libloading::Library, libloading::Error> {
unsafe {
@ -67,29 +66,7 @@ pub(crate) mod os {
pub unsafe fn dlopen_local_noredirect<'a>(
path: Cow<'a, str>,
) -> Result<libloading::Library, libloading::Error> {
fn terminate_with_nul<'a>(path: Cow<'a, str>) -> Cow<'a, str> {
let path = if !path.ends_with('\0') {
let mut path = path.into_owned();
path.push('\0');
Cow::Owned(path)
} else {
path
};
path
}
let zluda_dlopen_noredirect =
unsafe { libc::dlsym(libc::RTLD_DEFAULT, c"zluda_dlopen_noredirect".as_ptr()) };
let zluda_dlopen_noredirect = mem::transmute::<
_,
Option<unsafe extern "C" fn(*const c_char, c_int) -> *mut c_void>,
>(zluda_dlopen_noredirect);
let dlopen = zluda_dlopen_noredirect.unwrap_or(libc::dlopen);
let path = terminate_with_nul(path);
Ok(libloading::os::unix::Library::from_raw(dlopen(
path.as_ptr().cast(),
os::unix::RTLD_LOCAL | os::unix::RTLD_LAZY,
))
.into())
libloading::Library::new(&*path)
}
}