mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-02 14:57:43 +03:00
Merge commit '99c36092bea198c90fd00f6eea83c728e497ff35' into unix_preload
This commit is contained in:
73
Cargo.lock
generated
73
Cargo.lock
generated
@ -1847,6 +1847,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"cuda_macros",
|
||||
"cuda_types",
|
||||
"zluda_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1874,7 +1875,53 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump"
|
||||
name = "zluda_fft"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cuda_macros",
|
||||
"cuda_types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_inject"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"detours-sys",
|
||||
"tempfile",
|
||||
"winapi",
|
||||
"zluda_ml",
|
||||
"zluda_redirect",
|
||||
"zluda_trace",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_ml"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cuda_macros",
|
||||
"cuda_types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_redirect"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"detours-sys",
|
||||
"wchar",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_sparse"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cuda_macros",
|
||||
"cuda_types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_trace"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1896,12 +1943,12 @@ dependencies = [
|
||||
"unwrap_or",
|
||||
"wchar",
|
||||
"winapi",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
"zstd-safe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_blas"
|
||||
name = "zluda_trace_blas"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1912,11 +1959,11 @@ dependencies = [
|
||||
"libloading",
|
||||
"paste",
|
||||
"unwrap_or",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_blaslt"
|
||||
name = "zluda_trace_blaslt"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1927,11 +1974,11 @@ dependencies = [
|
||||
"libloading",
|
||||
"paste",
|
||||
"unwrap_or",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_common"
|
||||
name = "zluda_trace_common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1943,7 +1990,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_dnn"
|
||||
name = "zluda_trace_dnn"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1954,11 +2001,11 @@ dependencies = [
|
||||
"libloading",
|
||||
"paste",
|
||||
"unwrap_or",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_fft"
|
||||
name = "zluda_trace_fft"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1969,11 +2016,11 @@ dependencies = [
|
||||
"libloading",
|
||||
"paste",
|
||||
"unwrap_or",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zluda_dump_sparse"
|
||||
name = "zluda_trace_sparse"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cglue",
|
||||
@ -1984,7 +2031,7 @@ dependencies = [
|
||||
"libloading",
|
||||
"paste",
|
||||
"unwrap_or",
|
||||
"zluda_dump_common",
|
||||
"zluda_trace_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
14
Cargo.toml
14
Cargo.toml
@ -23,13 +23,13 @@ members = [
|
||||
"zluda_blaslt",
|
||||
"zluda_common",
|
||||
"zluda_dnn",
|
||||
"zluda_dump",
|
||||
"zluda_dump_blas",
|
||||
"zluda_dump_blaslt",
|
||||
"zluda_dump_common",
|
||||
"zluda_dump_dnn",
|
||||
"zluda_dump_fft",
|
||||
"zluda_dump_sparse",
|
||||
"zluda_trace",
|
||||
"zluda_trace_blas",
|
||||
"zluda_trace_blaslt",
|
||||
"zluda_trace_common",
|
||||
"zluda_trace_dnn",
|
||||
"zluda_trace_fft",
|
||||
"zluda_trace_sparse",
|
||||
"zluda_fft",
|
||||
"zluda_inject",
|
||||
"zluda_ml",
|
||||
|
@ -284,7 +284,9 @@ pub struct cublasComputeType_t(pub ::core::ffi::c_uint);
|
||||
pub struct cublasContext {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub type cublasHandle_t = *mut cublasContext;
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub struct cublasHandle_t(pub *mut cublasContext);
|
||||
pub type cublasLogCallback = ::core::option::Option<
|
||||
unsafe extern "C" fn(msg: *const ::core::ffi::c_char),
|
||||
>;
|
||||
|
@ -332,10 +332,10 @@ dark_api! {
|
||||
}
|
||||
}
|
||||
|
||||
// Purely for internal use by ZLUDA dump
|
||||
// Purely for internal use by ZLUDA trace
|
||||
dark_api! {
|
||||
zluda_dump;
|
||||
"{0B7A5827-AF98-46AB-A951-22D19BDF5C08}" => ZLUDA_DUMP_INTERNAL[1] {
|
||||
zluda_trace;
|
||||
"{0B7A5827-AF98-46AB-A951-22D19BDF5C08}" => ZLUDA_TRACE_INTERNAL[1] {
|
||||
#[noformat]
|
||||
[0] = logged_call(
|
||||
fn_name: cglue::slice::CSliceRef<'static, u8>,
|
||||
|
@ -348,11 +348,7 @@ impl crate::CudaDisplay for cuda_types::cublas::cublasHandle_t {
|
||||
_index: usize,
|
||||
writer: &mut (impl std::io::Write + ?Sized),
|
||||
) -> std::io::Result<()> {
|
||||
if self.is_null() {
|
||||
writer.write_all(b"NULL")
|
||||
} else {
|
||||
write!(writer, "{:p}", *self)
|
||||
}
|
||||
write!(writer, "{:p}", self.0)
|
||||
}
|
||||
}
|
||||
pub fn write_cublasCreate_v2(
|
||||
|
@ -385,7 +385,7 @@ pub(crate) unsafe fn get_proc_address_v2(
|
||||
flags: cuda_types::cuda::cuuint64_t,
|
||||
symbol_status: Option<&mut cuda_types::cuda::CUdriverProcAddressQueryResult>,
|
||||
) -> CUresult {
|
||||
// This implementation is mostly the same as cuGetProcAddress_v2 in zluda_dump. We may want to factor out the duplication at some point.
|
||||
// This implementation is mostly the same as cuGetProcAddress_v2 in zluda_trace. We may want to factor out the duplication at some point.
|
||||
fn raw_match(name: &[u8], flag: u64, version: i32) -> *mut ::core::ffi::c_void {
|
||||
use crate::*;
|
||||
include!("../../../zluda_bindgen/src/process_table.rs")
|
||||
|
@ -105,6 +105,15 @@ pub(crate) fn get_function(
|
||||
unsafe { hipModuleGetFunction(hfunc, hmod.base, name) }
|
||||
}
|
||||
|
||||
pub(crate) fn get_global_v2(
|
||||
dptr: *mut hipDeviceptr_t,
|
||||
bytes: *mut usize,
|
||||
hmod: &Module,
|
||||
name: *const ::core::ffi::c_char,
|
||||
) -> hipError_t {
|
||||
unsafe { hipModuleGetGlobal(dptr, bytes, hmod.base, name) }
|
||||
}
|
||||
|
||||
pub(crate) fn get_loading_mode(mode: &mut cuda_types::cuda::CUmoduleLoadingMode) -> CUresult {
|
||||
*mode = cuda_types::cuda::CUmoduleLoadingMode::CU_MODULE_EAGER_LOADING;
|
||||
Ok(())
|
||||
|
@ -1,4 +1,4 @@
|
||||
// TODO: remove duplication with zluda_dump
|
||||
// TODO: remove duplication with zluda_trace
|
||||
#[link(name = "pthread")]
|
||||
unsafe extern "C" {
|
||||
fn pthread_self() -> std::os::unix::thread::RawPthread;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// TODO: remove duplication with zluda_dump
|
||||
// TODO: remove duplication with zluda_trace
|
||||
#[link(name = "kernel32")]
|
||||
unsafe extern "system" {
|
||||
fn GetCurrentThreadId() -> u32;
|
||||
|
@ -112,6 +112,7 @@ cuda_macros::cuda_function_declarations!(
|
||||
cuMemsetD32_v2,
|
||||
cuMemsetD8_v2,
|
||||
cuModuleGetFunction,
|
||||
cuModuleGetGlobal_v2,
|
||||
cuModuleGetLoadingMode,
|
||||
cuModuleLoadData,
|
||||
cuModuleUnload,
|
||||
|
@ -658,6 +658,7 @@ fn generate_cublas(crate_root: &PathBuf) {
|
||||
.allowlist_var("^CUBLAS_.*")
|
||||
.must_use_type("cublasStatus_t")
|
||||
.constified_enum("cublasStatus_t")
|
||||
.new_type_alias(r"^cublasHandle_t$")
|
||||
.allowlist_recursively(false)
|
||||
.clang_args(["-I/usr/local/cuda/include", "-x", "c++"])
|
||||
.generate()
|
||||
|
@ -10,6 +10,7 @@ name = "cublas"
|
||||
[dependencies]
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_common = { path = "../zluda_common" }
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
|
@ -14,6 +14,20 @@ macro_rules! unimplemented {
|
||||
}
|
||||
|
||||
macro_rules! implemented {
|
||||
($($abi:literal fn $fn_name:ident( $($arg_id:ident : $arg_type:ty),* ) -> $ret_type:ty;)*) => {
|
||||
$(
|
||||
#[cfg_attr(not(test), no_mangle)]
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
cuda_macros::cublas_normalize_fn!( crate::r#impl::$fn_name ) ($(zluda_common::FromCuda::<_, cublasError_t>::from_cuda(&$arg_id)?),*)?;
|
||||
Ok(())
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! implemented_and_always_succeeds {
|
||||
($($abi:literal fn $fn_name:ident( $($arg_id:ident : $arg_type:ty),* ) -> $ret_type:ty;)*) => {
|
||||
$(
|
||||
#[cfg_attr(not(test), no_mangle)]
|
||||
@ -28,7 +42,8 @@ macro_rules! implemented {
|
||||
|
||||
cuda_macros::cublas_function_declarations!(
|
||||
unimplemented,
|
||||
implemented
|
||||
implemented <= [],
|
||||
implemented_and_always_succeeds
|
||||
<= [
|
||||
cublasGetStatusName,
|
||||
cublasGetStatusString,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use cuda_types::cuda::*;
|
||||
use cuda_types::{cublas::*, cuda::*};
|
||||
use hip_runtime_sys::*;
|
||||
use std::{
|
||||
ffi::CStr,
|
||||
@ -16,6 +16,11 @@ impl CudaErrorType for CUerror {
|
||||
const NOT_SUPPORTED: Self = Self::NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
impl CudaErrorType for cublasError_t {
|
||||
const INVALID_VALUE: Self = Self::INVALID_VALUE;
|
||||
const NOT_SUPPORTED: Self = Self::NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/// Used to try to convert CUDA API values into our internal representation.
|
||||
///
|
||||
/// Similar to [`TryFrom`], but we can implement this for primitive types. We also provide conversions from pointers to references.
|
||||
@ -123,7 +128,9 @@ from_cuda_nop!(
|
||||
CUuuid,
|
||||
CUlibrary,
|
||||
CUmodule,
|
||||
CUcontext
|
||||
CUcontext,
|
||||
cublasHandle_t,
|
||||
cublasStatus_t
|
||||
);
|
||||
from_cuda_transmute!(
|
||||
CUuuid => hipUUID,
|
||||
|
@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "zluda_dump_sparse"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump_sparse"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcusparse.so",
|
||||
"dump/libcusparse.so.12"
|
||||
]
|
@ -17,7 +17,7 @@ detours-sys = { path = "../detours-sys" }
|
||||
[dev-dependencies]
|
||||
# all of those are used in integration tests
|
||||
zluda_redirect = { path = "../zluda_redirect" }
|
||||
zluda_dump = { path = "../zluda_dump" }
|
||||
zluda_trace = { path = "../zluda_trace" }
|
||||
zluda_ml = { path = "../zluda_ml" }
|
||||
|
||||
[package.metadata.zluda]
|
||||
|
@ -3,49 +3,49 @@ use std::{env, io, path::PathBuf, process::Command};
|
||||
|
||||
#[test]
|
||||
fn direct_cuinit() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("direct_cuinit")
|
||||
run_process_and_check_for_zluda_trace("direct_cuinit")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_cuinit_early() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("do_cuinit_early")
|
||||
run_process_and_check_for_zluda_trace("do_cuinit_early")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_cuinit_late() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("do_cuinit_late")
|
||||
run_process_and_check_for_zluda_trace("do_cuinit_late")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_cuinit_late_clr() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("do_cuinit_late_clr")
|
||||
run_process_and_check_for_zluda_trace("do_cuinit_late_clr")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indirect_cuinit() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("indirect_cuinit")
|
||||
run_process_and_check_for_zluda_trace("indirect_cuinit")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subprocess() -> io::Result<()> {
|
||||
run_process_and_check_for_zluda_dump("subprocess")
|
||||
run_process_and_check_for_zluda_trace("subprocess")
|
||||
}
|
||||
|
||||
fn run_process_and_check_for_zluda_dump(name: &'static str) -> io::Result<()> {
|
||||
fn run_process_and_check_for_zluda_trace(name: &'static str) -> io::Result<()> {
|
||||
let zluda_with_exe = PathBuf::from(env!("CARGO_BIN_EXE_zluda_with"));
|
||||
let mut zluda_dump_dll = zluda_with_exe.parent().unwrap().to_path_buf();
|
||||
zluda_dump_dll.push("zluda_dump.dll");
|
||||
let mut zluda_trace_dll = zluda_with_exe.parent().unwrap().to_path_buf();
|
||||
zluda_trace_dll.push("zluda_trace.dll");
|
||||
let helpers_dir = env!("HELPERS_OUT_DIR");
|
||||
let exe_under_test = format!("{}{}{}.exe", helpers_dir, std::path::MAIN_SEPARATOR, name);
|
||||
let mut test_cmd = Command::new(&zluda_with_exe);
|
||||
let test_cmd = test_cmd
|
||||
.arg("--nvcuda")
|
||||
.arg(&zluda_dump_dll)
|
||||
.arg(&zluda_trace_dll)
|
||||
.arg("--")
|
||||
.arg(&exe_under_test);
|
||||
let test_output = test_cmd.output()?;
|
||||
assert!(test_output.status.success());
|
||||
let stderr_text = String::from_utf8(test_output.stderr).unwrap();
|
||||
assert!(stderr_text.contains("ZLUDA_DUMP"));
|
||||
assert!(stderr_text.contains("ZLUDA_TRACE"));
|
||||
Ok(())
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ cuda_types = { path = "../cuda_types" }
|
||||
linux_symlinks = [
|
||||
"libnvidia-ml.so",
|
||||
"libnvidia-ml.so.1",
|
||||
"dump/libnvidia-ml.so",
|
||||
"dump/libnvidia-ml.so.1",
|
||||
"trace/libnvidia-ml.so",
|
||||
"trace/libnvidia-ml.so.1",
|
||||
]
|
||||
|
@ -1,17 +1,17 @@
|
||||
[package]
|
||||
name = "zluda_dump"
|
||||
name = "zluda_trace"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump"
|
||||
name = "zluda_trace"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
ptx = { path = "../ptx" }
|
||||
ptx_parser = { path = "../ptx_parser" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
regex = "1.4"
|
||||
@ -38,8 +38,8 @@ libc = "0.2"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcuda.so",
|
||||
"dump/libcuda.so.1",
|
||||
"dump_nvidia/libcuda.so",
|
||||
"dump_nvidia/libcuda.so.1",
|
||||
"trace/libcuda.so",
|
||||
"trace/libcuda.so.1",
|
||||
"trace_nvidia/libcuda.so",
|
||||
"trace_nvidia/libcuda.so.1",
|
||||
]
|
@ -141,11 +141,11 @@ macro_rules! override_fn_full {
|
||||
}
|
||||
}
|
||||
|
||||
static INTERNAL_TABLE: ::dark_api::zluda_dump::CudaDarkApiGlobalTable =
|
||||
::dark_api::zluda_dump::CudaDarkApiGlobalTable::new::<InternalTableImpl>();
|
||||
static INTERNAL_TABLE: ::dark_api::zluda_trace::CudaDarkApiGlobalTable =
|
||||
::dark_api::zluda_trace::CudaDarkApiGlobalTable::new::<InternalTableImpl>();
|
||||
struct InternalTableImpl;
|
||||
|
||||
impl ::dark_api::zluda_dump::CudaDarkApi for InternalTableImpl {
|
||||
impl ::dark_api::zluda_trace::CudaDarkApi for InternalTableImpl {
|
||||
unsafe extern "system" fn logged_call(
|
||||
fn_name: cglue::slice::CSliceRef<'static, u8>,
|
||||
args: ::dark_api::FnFfiRef<::dark_api::ByteVecFfi>,
|
||||
@ -166,7 +166,7 @@ impl ::dark_api::zluda_dump::CudaDarkApi for InternalTableImpl {
|
||||
}
|
||||
|
||||
static EXPORT_TABLE: ::dark_api::cuda::CudaDarkApiGlobalTable =
|
||||
::dark_api::cuda::CudaDarkApiGlobalTable::new::<DarkApiDump>();
|
||||
::dark_api::cuda::CudaDarkApiGlobalTable::new::<DarkApiTrace>();
|
||||
|
||||
macro_rules! dark_api_fn_redirect_log {
|
||||
(
|
||||
@ -178,7 +178,7 @@ macro_rules! dark_api_fn_redirect_log {
|
||||
unsafe extern "system" fn $fn_(
|
||||
$($arg_id: $arg_type),*
|
||||
) -> $ret_type {
|
||||
use zluda_dump_common::ReprUsize;
|
||||
use zluda_trace_common::ReprUsize;
|
||||
let original_fn = {
|
||||
let dark_api = DARK_API_STATE.lock().unwrap();
|
||||
let (original_table, _) = dark_api
|
||||
@ -233,7 +233,7 @@ macro_rules! dark_api_fn_redirect_log_post {
|
||||
unsafe extern "system" fn $fn_(
|
||||
$($arg_id: $arg_type),*
|
||||
) -> $ret_type {
|
||||
use zluda_dump_common::ReprUsize;
|
||||
use zluda_trace_common::ReprUsize;
|
||||
let original_fn = {
|
||||
let dark_api = DARK_API_STATE.lock().unwrap();
|
||||
let (original_table, _) = dark_api
|
||||
@ -278,9 +278,9 @@ macro_rules! dark_api_fn_redirect_log_post {
|
||||
};
|
||||
}
|
||||
|
||||
struct DarkApiDump;
|
||||
struct DarkApiTrace;
|
||||
|
||||
impl DarkApiDump {
|
||||
impl DarkApiTrace {
|
||||
fn get_module_from_cubin_post(
|
||||
module: *mut cuda_types::cuda::CUmodule,
|
||||
fatbinc_wrapper: *const cuda_types::dark_api::FatbincWrapper,
|
||||
@ -375,7 +375,7 @@ impl DarkApiDump {
|
||||
}
|
||||
}
|
||||
|
||||
impl ::dark_api::cuda::CudaDarkApi for DarkApiDump {
|
||||
impl ::dark_api::cuda::CudaDarkApi for DarkApiTrace {
|
||||
dark_api_fn_redirect_log! {
|
||||
CUDART_INTERFACE {
|
||||
[2] = cudart_interface_fn2(
|
||||
@ -900,7 +900,7 @@ impl GlobalState2 {
|
||||
|
||||
// This function is at the core of the logging mechanism.
|
||||
// How it works:
|
||||
// When user calls a CUDA function, we want to log the call and its arguments. So in a dump
|
||||
// When user calls a CUDA function, we want to log the call and its arguments. So in a trace
|
||||
// library every public CUDA function will call this function like so:
|
||||
// cuMemAlloc_v2(args) -> under_lock("cuMemAlloc_v2", Some(args), ...)
|
||||
// That sounds simple enough, but there are some exotic requirements we have to fulfill:
|
||||
@ -908,11 +908,11 @@ impl GlobalState2 {
|
||||
// functions. We need to be able to log all of these calls hierarchically
|
||||
// * Thread-safety: CUDA functions can be called from multiple threads
|
||||
// * Error-handling: If we fail internally for whatever reason (e.g. we can't load the CUDA
|
||||
// library, the dump directory is not writable, etc.), we need to log this
|
||||
// library, the trace directory is not writable, etc.), we need to log this
|
||||
// error no matter what
|
||||
// Because of that the function is split into three phases:
|
||||
// * Pre-call:
|
||||
// We need to load the settings (location of the CUDA libary, dump directory, etc.), write the
|
||||
// We need to load the settings (location of the CUDA libary, trace directory, etc.), write the
|
||||
// function name and its arguments to logging buffer. This whole phase is covered by a drop
|
||||
// guard which will flush the log buffer in case of panic
|
||||
// * Call:
|
||||
@ -1281,15 +1281,15 @@ impl Settings {
|
||||
}
|
||||
|
||||
fn read_and_init_dump_dir() -> Result<Option<PathBuf>, Box<dyn Error>> {
|
||||
let dir = match env::var("ZLUDA_DUMP_DIR") {
|
||||
let dir = match env::var("ZLUDA_LOG_DIR") {
|
||||
Ok(dir) => dir,
|
||||
Err(env::VarError::NotPresent) => return Ok(None),
|
||||
Err(err) => return Err(Box::new(err) as Box<_>),
|
||||
};
|
||||
Ok(Some(Self::create_dump_directory(dir)?))
|
||||
Ok(Some(Self::create_trace_directory(dir)?))
|
||||
}
|
||||
|
||||
fn create_dump_directory(dir: String) -> io::Result<PathBuf> {
|
||||
fn create_trace_directory(dir: String) -> io::Result<PathBuf> {
|
||||
let mut main_dir = PathBuf::from(dir);
|
||||
let current_exe = env::current_exe()?;
|
||||
let file_name_base = current_exe.file_name().unwrap().to_string_lossy();
|
@ -14,7 +14,7 @@ use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::str::Utf8Error;
|
||||
|
||||
const LOG_PREFIX: &[u8] = b"[ZLUDA_DUMP] ";
|
||||
const LOG_PREFIX: &[u8] = b"[ZLUDA_TRACE] ";
|
||||
|
||||
pub(crate) struct Writer {
|
||||
// Fallible emitter is an optional emitter to the file system, we might lack
|
||||
@ -346,7 +346,7 @@ impl Display for ErrorEntry {
|
||||
ErrorEntry::CreatedDumpDirectory(dir) => {
|
||||
write!(
|
||||
f,
|
||||
"Created dump directory {} ",
|
||||
"Created trace directory {} ",
|
||||
dir.as_os_str().to_string_lossy()
|
||||
)
|
||||
}
|
@ -27,12 +27,12 @@ pub unsafe fn get_proc_address(handle: *mut c_void, func: &CStr) -> *mut c_void
|
||||
macro_rules! os_log {
|
||||
($format:tt) => {
|
||||
{
|
||||
eprintln!("[ZLUDA_DUMP] {}", format!($format));
|
||||
eprintln!("[ZLUDA_TRACE] {}", format!($format));
|
||||
}
|
||||
};
|
||||
($format:tt, $($obj: expr),+) => {
|
||||
{
|
||||
eprintln!("[ZLUDA_DUMP] {}", format!($format, $($obj,)+));
|
||||
eprintln!("[ZLUDA_TRACE] {}", format!($format, $($obj,)+));
|
||||
}
|
||||
};
|
||||
}
|
@ -104,10 +104,10 @@ macro_rules! os_log {
|
||||
pub fn __log_impl(s: String) {
|
||||
let log_to_stderr = std::io::stderr().as_raw_handle() != ptr::null_mut();
|
||||
if log_to_stderr {
|
||||
eprintln!("[ZLUDA_DUMP] {}", s);
|
||||
eprintln!("[ZLUDA_TRACE] {}", s);
|
||||
} else {
|
||||
let mut win_str = String::with_capacity("[ZLUDA_DUMP] ".len() + s.len() + 2);
|
||||
win_str.push_str("[ZLUDA_DUMP] ");
|
||||
let mut win_str = String::with_capacity("[ZLUDA_TRACE] ".len() + s.len() + 2);
|
||||
win_str.push_str("[ZLUDA_TRACE] ");
|
||||
win_str.push_str(&s);
|
||||
win_str.push_str("\n\0");
|
||||
unsafe { OutputDebugStringA(win_str.as_ptr() as *const _) };
|
@ -198,7 +198,7 @@ impl StateTracker {
|
||||
}
|
||||
}
|
||||
|
||||
// This structs writes out information about CUDA execution to the dump dir
|
||||
// This structs writes out information about CUDA execution to the trace dir
|
||||
struct DumpWriter {
|
||||
dump_dir: Option<PathBuf>,
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "zluda_dump_fft"
|
||||
name = "zluda_trace_blas"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump_fft"
|
||||
name = "zluda_trace_blas"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
@ -13,7 +13,7 @@ format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
@ -21,6 +21,6 @@ cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcufft.so",
|
||||
"dump/libcufft.so.11"
|
||||
"trace/libcublas.so",
|
||||
"trace/libcublas.so.12"
|
||||
]
|
@ -17,12 +17,12 @@ macro_rules! unimplemented {
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
use ::zluda_dump_common::ReprUsize;
|
||||
use ::zluda_trace_common::ReprUsize;
|
||||
let internal_error_untyped: usize = <$ret_type as ReprUsize>::INTERNAL_ERROR;
|
||||
let internal_error: $ret_type = ReprUsize::from_usize(internal_error_untyped);
|
||||
let maybe_fn_ptr = (&*LIBRARY).as_ref().and_then(|lib| lib.get::<unsafe extern $abi fn ( $($arg_type),* ) -> $ret_type>(concat!( stringify!($fn_name), "\0").as_bytes()).ok());
|
||||
let fn_ptr = unwrap_or::unwrap_some_or!(maybe_fn_ptr, return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_dump_common::get_export_table(), return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_trace_common::get_export_table(), return internal_error);
|
||||
let format_args = dark_api::FnFfiWrapper(|| {
|
||||
let mut writer = Vec::new();
|
||||
let formatter = paste::paste! { ::format:: [< write_ $fn_name>] };
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "zluda_dump_blaslt"
|
||||
name = "zluda_trace_blaslt"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump_blaslt"
|
||||
name = "zluda_trace_blaslt"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
@ -13,7 +13,7 @@ format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
@ -21,6 +21,6 @@ cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcublasLt.so",
|
||||
"dump/libcublasLt.so.12"
|
||||
"trace/libcublasLt.so",
|
||||
"trace/libcublasLt.so.12"
|
||||
]
|
@ -17,12 +17,12 @@ macro_rules! unimplemented {
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
use ::zluda_dump_common::ReprUsize;
|
||||
use ::zluda_trace_common::ReprUsize;
|
||||
let internal_error_untyped: usize = <$ret_type as ReprUsize>::INTERNAL_ERROR;
|
||||
let internal_error: $ret_type = ReprUsize::from_usize(internal_error_untyped);
|
||||
let maybe_fn_ptr = (&*LIBRARY).as_ref().and_then(|lib| lib.get::<unsafe extern $abi fn ( $($arg_type),* ) -> $ret_type>(concat!( stringify!($fn_name), "\0").as_bytes()).ok());
|
||||
let fn_ptr = unwrap_or::unwrap_some_or!(maybe_fn_ptr, return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_dump_common::get_export_table(), return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_trace_common::get_export_table(), return internal_error);
|
||||
let format_args = dark_api::FnFfiWrapper(|| {
|
||||
let mut writer = Vec::new();
|
||||
let formatter = paste::paste! { ::format:: [< write_ $fn_name>] };
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "zluda_dump_common"
|
||||
name = "zluda_trace_common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -7,21 +7,21 @@ use cuda_types::{
|
||||
use dark_api::ByteVecFfi;
|
||||
use std::{ffi::c_void, num::NonZero, ptr, sync::LazyLock};
|
||||
|
||||
pub fn get_export_table() -> Option<::dark_api::zluda_dump::ZludaDumpInternal> {
|
||||
pub fn get_export_table() -> Option<::dark_api::zluda_trace::ZludaTraceInternal> {
|
||||
static CU_GET_EXPORT_TABLE: LazyLock<
|
||||
Result<
|
||||
unsafe extern "system" fn(*mut *const ::core::ffi::c_void, *const CUuuid) -> CUresult,
|
||||
libloading::Error,
|
||||
>,
|
||||
> = LazyLock::new(|| unsafe { get_dump_table_impl() });
|
||||
> = LazyLock::new(|| unsafe { get_export_table_impl() });
|
||||
let cu_get_export_table = CU_GET_EXPORT_TABLE.as_ref().ok()?;
|
||||
let mut ptr = ptr::null();
|
||||
unsafe { (cu_get_export_table)(&mut ptr, &::dark_api::zluda_dump::ZludaDumpInternal::GUID) }
|
||||
unsafe { (cu_get_export_table)(&mut ptr, &::dark_api::zluda_trace::ZludaTraceInternal::GUID) }
|
||||
.ok()?;
|
||||
Some(unsafe { ::dark_api::zluda_dump::ZludaDumpInternal::new(ptr) })
|
||||
Some(unsafe { ::dark_api::zluda_trace::ZludaTraceInternal::new(ptr) })
|
||||
}
|
||||
|
||||
unsafe fn get_dump_table_impl() -> Result<
|
||||
unsafe fn get_export_table_impl() -> Result<
|
||||
unsafe extern "system" fn(*mut *const ::core::ffi::c_void, *const CUuuid) -> CUresult,
|
||||
libloading::Error,
|
||||
> {
|
||||
@ -86,6 +86,7 @@ pub(crate) mod os {
|
||||
|
||||
pub fn open_driver() -> Result<libloading::Library, libloading::Error> {
|
||||
os::windows::Library::open_already_loaded("nvcuda").map(Into::into)
|
||||
<<<<<<< HEAD:zluda_dump_common/src/lib.rs
|
||||
}
|
||||
|
||||
pub unsafe fn dlopen_local_noredirect(
|
||||
@ -105,6 +106,8 @@ pub(crate) mod os {
|
||||
}
|
||||
Err(_) => libloading::Library::new(path),
|
||||
}
|
||||
=======
|
||||
>>>>>>> 99c36092bea198c90fd00f6eea83c728e497ff35:zluda_trace_common/src/lib.rs
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "zluda_dump_dnn"
|
||||
name = "zluda_trace_dnn"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump_dnn"
|
||||
name = "zluda_trace_dnn"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
@ -13,7 +13,7 @@ format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
@ -21,6 +21,6 @@ cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcudnn.so",
|
||||
"dump/libcudnn.so.9"
|
||||
"trace/libcudnn.so",
|
||||
"trace/libcudnn.so.9"
|
||||
]
|
@ -17,12 +17,12 @@ macro_rules! unimplemented {
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
use ::zluda_dump_common::ReprUsize;
|
||||
use ::zluda_trace_common::ReprUsize;
|
||||
let internal_error_untyped: usize = <$ret_type as ReprUsize>::INTERNAL_ERROR;
|
||||
let internal_error: $ret_type = ReprUsize::from_usize(internal_error_untyped);
|
||||
let maybe_fn_ptr = (&*LIBRARY).as_ref().and_then(|lib| lib.get::<unsafe extern $abi fn ( $($arg_type),* ) -> $ret_type>(concat!( stringify!($fn_name), "\0").as_bytes()).ok());
|
||||
let fn_ptr = unwrap_or::unwrap_some_or!(maybe_fn_ptr, return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_dump_common::get_export_table(), return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_trace_common::get_export_table(), return internal_error);
|
||||
let format_args = dark_api::FnFfiWrapper(|| {
|
||||
let mut writer = Vec::new();
|
||||
let formatter = paste::paste! { ::format:: [< write_ $fn_name>] };
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "zluda_dump_blas"
|
||||
name = "zluda_trace_fft"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_dump_blas"
|
||||
name = "zluda_trace_fft"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
@ -13,7 +13,7 @@ format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_dump_common = { path = "../zluda_dump_common" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
@ -21,6 +21,6 @@ cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"dump/libcublas.so",
|
||||
"dump/libcublas.so.12"
|
||||
"trace/libcufft.so",
|
||||
"trace/libcufft.so.11"
|
||||
]
|
@ -17,12 +17,12 @@ macro_rules! unimplemented {
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
use ::zluda_dump_common::ReprUsize;
|
||||
use ::zluda_trace_common::ReprUsize;
|
||||
let internal_error_untyped: usize = <$ret_type as ReprUsize>::INTERNAL_ERROR;
|
||||
let internal_error: $ret_type = ReprUsize::from_usize(internal_error_untyped);
|
||||
let maybe_fn_ptr = (&*LIBRARY).as_ref().and_then(|lib| lib.get::<unsafe extern $abi fn ( $($arg_type),* ) -> $ret_type>(concat!( stringify!($fn_name), "\0").as_bytes()).ok());
|
||||
let fn_ptr = unwrap_or::unwrap_some_or!(maybe_fn_ptr, return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_dump_common::get_export_table(), return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_trace_common::get_export_table(), return internal_error);
|
||||
let format_args = dark_api::FnFfiWrapper(|| {
|
||||
let mut writer = Vec::new();
|
||||
let formatter = paste::paste! { ::format:: [< write_ $fn_name>] };
|
26
zluda_trace_sparse/Cargo.toml
Normal file
26
zluda_trace_sparse/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "zluda_trace_sparse"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "zluda_trace_sparse"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
format = { path = "../format" }
|
||||
dark_api = { path = "../dark_api" }
|
||||
cuda_macros = { path = "../cuda_macros" }
|
||||
cuda_types = { path = "../cuda_types" }
|
||||
zluda_trace_common = { path = "../zluda_trace_common" }
|
||||
libloading = "0.8"
|
||||
paste = "1.0"
|
||||
unwrap_or = "1.0.1"
|
||||
cglue = "0.3.5"
|
||||
|
||||
[package.metadata.zluda]
|
||||
linux_symlinks = [
|
||||
"trace/libcusparse.so",
|
||||
"trace/libcusparse.so.12"
|
||||
]
|
@ -17,12 +17,12 @@ macro_rules! unimplemented {
|
||||
#[allow(improper_ctypes)]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub unsafe extern $abi fn $fn_name ( $( $arg_id : $arg_type),* ) -> $ret_type {
|
||||
use ::zluda_dump_common::ReprUsize;
|
||||
use ::zluda_trace_common::ReprUsize;
|
||||
let internal_error_untyped: usize = <$ret_type as ReprUsize>::INTERNAL_ERROR;
|
||||
let internal_error: $ret_type = ReprUsize::from_usize(internal_error_untyped);
|
||||
let maybe_fn_ptr = (&*LIBRARY).as_ref().and_then(|lib| lib.get::<unsafe extern $abi fn ( $($arg_type),* ) -> $ret_type>(concat!( stringify!($fn_name), "\0").as_bytes()).ok());
|
||||
let fn_ptr = unwrap_or::unwrap_some_or!(maybe_fn_ptr, return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_dump_common::get_export_table(), return internal_error);
|
||||
let export_table = unwrap_or::unwrap_some_or!(::zluda_trace_common::get_export_table(), return internal_error);
|
||||
let format_args = dark_api::FnFfiWrapper(|| {
|
||||
let mut writer = Vec::new();
|
||||
let formatter = paste::paste! { ::format:: [< write_ $fn_name>] };
|
Reference in New Issue
Block a user