Special case for dumping from NV CUDA

This commit is contained in:
Andrzej Janik 2024-04-26 23:16:50 +00:00
commit 660a789e72
3 changed files with 44 additions and 30 deletions

View file

@ -92,13 +92,16 @@ If you are dumping original CUDA use:
### Linux ### Linux
Known bug: when dumping from original CUDA you should remove (or rename) all the files in `<ZLUDA_DIRECTORY>/dump` except `libcuda.so` and `libcuda.so.1`. If dumping from ZLUDA use it like this:
Use it like this:
``` ```
LD_LIBRARY_PATH="<ZLUDA_DIRECTORY>/dump:$LD_LIBRARY_PATH" <APPLICATION> <APPLICATION_ARGUMENTS> LD_LIBRARY_PATH="<ZLUDA_DIRECTORY>/dump:$LD_LIBRARY_PATH" <APPLICATION> <APPLICATION_ARGUMENTS>
``` ```
If dumping from NVIDIA CUDA use it like this:
```
LD_LIBRARY_PATH="<ZLUDA_DIRECTORY>/dump_nvidia:$LD_LIBRARY_PATH" <APPLICATION> <APPLICATION_ARGUMENTS>
```
### Result ### Result
If all went well you should see lines like this in the console output and in the log file specified by `ZLUDA_DUMP_DIR`: If all went well you should see lines like this in the console output and in the log file specified by `ZLUDA_DUMP_DIR`:

View file

@ -113,6 +113,8 @@ struct Project {
linux_names: Vec<String>, linux_names: Vec<String>,
#[serde(default)] #[serde(default)]
dump_names: Vec<String>, dump_names: Vec<String>,
#[serde(default)]
dump_nvidia_names: Vec<String>,
} }
#[derive(Clone, Copy, Default, PartialEq, Debug)] #[derive(Clone, Copy, Default, PartialEq, Debug)]
@ -260,13 +262,16 @@ mod os {
use crate::Workspace; use crate::Workspace;
use cargo_metadata::camino::Utf8PathBuf; use cargo_metadata::camino::Utf8PathBuf;
use flate2::{write::GzEncoder, Compression}; use flate2::{write::GzEncoder, Compression};
use std::fs::File; use std::{fs::File, time::{Duration, SystemTime}};
pub(crate) fn create_dump_dir_and_symlinks(workspace: &Workspace) { pub(crate) fn create_dump_dir_and_symlinks(workspace: &Workspace) {
use std::fs; use std::fs;
let mut dump_dir = workspace.target_directory.clone(); let mut dump_dir = workspace.target_directory.clone();
dump_dir.push("dump"); dump_dir.push("dump");
fs::create_dir_all(&dump_dir).unwrap(); fs::create_dir_all(&dump_dir).unwrap();
let mut dump_nvidia_dir = dump_dir.clone();
dump_nvidia_dir.set_file_name("dump_nvidia");
fs::create_dir_all(&dump_nvidia_dir).unwrap();
for project in workspace.projects.iter() { for project in workspace.projects.iter() {
let dst = format!( let dst = format!(
"{}{}{}", "{}{}{}",
@ -285,6 +290,9 @@ mod os {
for src_file in project.dump_names.iter() { for src_file in project.dump_names.iter() {
force_symlink(&dump_dst, &dump_dir, src_file); force_symlink(&dump_dst, &dump_dir, src_file);
} }
for src_file in project.dump_nvidia_names.iter() {
force_symlink(&dump_dst, &dump_nvidia_dir, src_file);
}
} }
} }
@ -317,6 +325,7 @@ mod os {
let gz_file = File::create(target_file).unwrap(); let gz_file = File::create(target_file).unwrap();
let gz = GzEncoder::new(gz_file, Compression::default()); let gz = GzEncoder::new(gz_file, Compression::default());
let mut tar = tar::Builder::new(gz); let mut tar = tar::Builder::new(gz);
let time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap_or(Duration::ZERO);
for project in workspace.projects { for project in workspace.projects {
if project.skip_zip { if project.skip_zip {
continue; continue;
@ -329,50 +338,44 @@ mod os {
project.kind.suffix() project.kind.suffix()
)) ))
.unwrap(); .unwrap();
let file_in_archive_path = format!( let file_name = format!(
"zluda/{}{}{}", "{}{}{}",
project.kind.prefix(), project.kind.prefix(),
project.target_name, project.target_name,
project.kind.suffix() project.kind.suffix()
); );
tar.append_file( tar.append_file(format!("zluda/{file_name}"), &mut src_file)
format!(
"zluda/{}{}{}",
project.kind.prefix(),
project.target_name,
project.kind.suffix()
),
&mut src_file,
)
.unwrap();
for linux_name in project.linux_names.iter() {
let mut header = tar::Header::new_gnu();
header.set_entry_type(tar::EntryType::Symlink);
tar.append_link(
&mut header,
format!("zluda/{}", linux_name),
&file_in_archive_path,
)
.unwrap(); .unwrap();
for linux_name in project.linux_names.iter() {
let mut header = tar_header_symlink(time);
tar.append_link(&mut header, format!("zluda/{}", linux_name), &file_name)
.unwrap();
if project.skip_dump_link { if project.skip_dump_link {
continue; continue;
} }
let mut header = tar::Header::new_gnu(); let mut header = tar_header_symlink(time);
header.set_entry_type(tar::EntryType::Symlink);
tar.append_link( tar.append_link(
&mut header, &mut header,
format!("zluda/dump/{}", linux_name), format!("zluda/dump/{}", linux_name),
&file_in_archive_path, format!("../{file_name}"),
) )
.unwrap(); .unwrap();
} }
for dump_name in project.dump_names.iter() { for dump_name in project.dump_names.iter() {
let mut header = tar::Header::new_gnu(); let mut header = tar_header_symlink(time);
header.set_entry_type(tar::EntryType::Symlink);
tar.append_link( tar.append_link(
&mut header, &mut header,
format!("zluda/dump/{}", dump_name), format!("zluda/dump/{}", dump_name),
&file_in_archive_path, format!("../{file_name}"),
)
.unwrap();
}
for dump_name in project.dump_nvidia_names.iter() {
let mut header = tar_header_symlink(time);
tar.append_link(
&mut header,
format!("zluda/dump_nvidia/{}", dump_name),
format!("../{file_name}"),
) )
.unwrap(); .unwrap();
} }
@ -380,6 +383,13 @@ mod os {
tar.finish().unwrap(); tar.finish().unwrap();
0 0
} }
fn tar_header_symlink(time: Duration) -> tar::Header {
let mut header = tar::Header::new_gnu();
header.set_mtime(time.as_secs());
header.set_entry_type(tar::EntryType::Symlink);
header
}
} }
#[cfg(windows)] #[cfg(windows)]

View file

@ -44,3 +44,4 @@ rand = "0.8.5"
# Nominally debug_only, but useful for power users # Nominally debug_only, but useful for power users
[package.metadata.zluda] [package.metadata.zluda]
dump_names = ["libcuda.so", "libcuda.so.1"] dump_names = ["libcuda.so", "libcuda.so.1"]
dump_nvidia_names = ["libcuda.so", "libcuda.so.1"]