diff options
Diffstat (limited to 'zluda_dump/src')
-rw-r--r-- | zluda_dump/src/format.rs | 628 | ||||
-rw-r--r-- | zluda_dump/src/lib.rs | 37 | ||||
-rw-r--r-- | zluda_dump/src/log.rs | 2 |
3 files changed, 622 insertions, 45 deletions
diff --git a/zluda_dump/src/format.rs b/zluda_dump/src/format.rs index df6d4f6..bee8d4c 100644 --- a/zluda_dump/src/format.rs +++ b/zluda_dump/src/format.rs @@ -1,8 +1,8 @@ +use paste::paste;
use std::{
ffi::{c_void, CStr},
- fmt::Formatter,
io::Write,
- ptr,
+ mem, ptr,
};
use crate::cuda::*;
@@ -61,9 +61,275 @@ impl FormatCudaObject for *const c_void { }
}
+impl FormatCudaObject for CUstream {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUgraphicsResource {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUdeviceptr {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self.0 as *const ()).ok();
+ }
+}
+
+impl FormatCudaObject for CUtexref {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self as *const ()).ok();
+ }
+}
+
+impl FormatCudaObject for CUmipmappedArray {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUarray {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUcontext {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUsurfref {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUgraphNode {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUgraphExec {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUevent {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUgraph {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUexternalSemaphore {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUexternalMemory {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{:p}", self).ok();
+ }
+}
+
+impl FormatCudaObject for CUhostFn {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match self.map(|x| unsafe { mem::transmute::<_, *const ()>(x) }) {
+ Some(x) => write!(f, "{:p}", x),
+ None => write!(f, "NULL"),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUoccupancyB2DSize {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match self.map(|x| unsafe { mem::transmute::<_, *const ()>(x) }) {
+ Some(x) => write!(f, "{:p}", x),
+ None => write!(f, "NULL"),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUDA_RESOURCE_DESC {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match self.resType {
+ CU_RESOURCE_TYPE_ARRAY => {
+ write!(
+ f,
+ "{{resType: CU_RESOURCE_TYPE_ARRAY, hArray: {:p}, flags: {}}}",
+ self.res.array.hArray, self.flags
+ )
+ }
+ CU_RESOURCE_TYPE_MIPMAPPED_ARRAY => {
+ write!(
+ f,
+ "{{resType: CU_RESOURCE_TYPE_MIPMAPPED_ARRAY, hMipmappedArray: {:p}, flags: {}}}",
+ self.res.mipmap.hMipmappedArray, self.flags
+ )
+ }
+ CU_RESOURCE_TYPE_LINEAR => {
+ write!(
+ f,
+ "{{resType: CU_RESOURCE_TYPE_LINEAR, devPtr: {:p}, format:",
+ self.res.linear.devPtr.0 as *const ()
+ ).ok();
+ self.res.linear.format.write_post_execution(result, f);
+ write!(
+ f,
+ ", numChannels: {}, sizeInBytes: {}}}",
+ self.res.linear.numChannels, self.res.linear.sizeInBytes,
+ )
+ }
+ CU_RESOURCE_TYPE_PITCH2D => {
+ write!(
+ f,
+ "{{resType: CU_RESOURCE_TYPE_PITCH2D, devPtr: {:p}, format:",
+ self.res.pitch2D.devPtr.0 as *const ()
+ ).ok();
+ self.res.pitch2D.format.write_post_execution(result, f);
+ write!(
+ f,
+ ", numChannels: {}, width: {}, height: {}, pitchInBytes: {}}}",
+ self.res.pitch2D.numChannels, self.res.pitch2D.width, self.res.pitch2D.height, self.res.pitch2D.pitchInBytes
+ )
+ }
+ _ => {
+ write!(f, "{{resType: {}, flags: {}}}", self.resType.0, self.flags)
+ }
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUDA_RESOURCE_VIEW_DESC {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{{format: ").ok();
+ self.format.write_post_execution(result, f);
+ write!(
+ f,
+ ", width: {}, height: {}, depth: {}, firstMipmapLevel: {}, lastMipmapLevel: {}, firstLayer: {}, lastLayer: {}}}",
+ self.width,
+ self.height,
+ self.depth,
+ self.firstMipmapLevel,
+ self.lastMipmapLevel,
+ self.firstLayer,
+ self.lastLayer
+ ).ok();
+ }
+}
+
+impl FormatCudaObject for CUDA_TEXTURE_DESC {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{{addressMode: [").ok();
+ let [addressMode_0, addressMode_1, addressMode_2] = self.addressMode;
+ addressMode_0.write_post_execution(result, f);
+ write!(f, ", ").ok();
+ addressMode_1.write_post_execution(result, f);
+ write!(f, ", ").ok();
+ addressMode_2.write_post_execution(result, f);
+ write!(
+ f,
+ "], flags: {}, maxAnisotropy: {}, mipmapFilterMode: ",
+ self.flags, self.maxAnisotropy
+ );
+ self.mipmapFilterMode.write_post_execution(result, f);
+ write!(
+ f,
+ ", mipmapLevelBias: {}, minMipmapLevelClamp: {}, maxMipmapLevelClamp: {}, borderColor: [{}, {}, {}, {}]}}",
+ self.mipmapLevelBias,
+ self.minMipmapLevelClamp,
+ self.maxMipmapLevelClamp,
+ self.borderColor[0],
+ self.borderColor[1],
+ self.borderColor[2],
+ self.borderColor[3]
+ ).ok();
+ }
+}
+
+impl FormatCudaObject for CUDA_ARRAY_DESCRIPTOR {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(
+ f,
+ "{{Width: {}, Height: {}, Format: ",
+ self.Width, self.Height
+ )
+ .ok();
+ self.Format.write_post_execution(result, f);
+ write!(f, ", NumChannels: {}}}", self.NumChannels).ok();
+ }
+}
+
+impl FormatCudaObject for CUDA_MEMCPY3D {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(
+ f,
+ "{{srcXInBytes: {}, srcY: {}, srcZ: {}, srcLOD: {}, srcMemoryType: ",
+ self.srcXInBytes, self.srcY, self.srcZ, self.srcLOD,
+ )
+ .ok();
+ self.srcMemoryType.write_post_execution(result, f);
+ write!(
+ f,
+ ", srcHost: {:p}, srcDevice: {:p}, srcArray: {:p}, srcPitch: {}, srcHeight: {}, dstXInBytes: {}, dstY: {}, dstZ: {}, dstLOD: {}, dstMemoryType: ",
+ self.srcHost,
+ self.srcDevice.0 as *const (),
+ self.srcArray,
+ self.srcPitch,
+ self.srcHeight,
+ self.dstXInBytes,
+ self.dstY,
+ self.dstZ,
+ self.dstLOD,
+ ).ok();
+ self.dstMemoryType.write_post_execution(result, f);
+ write!(
+ f,
+ ", dstHost: {:p}, dstDevice: {:p}, dstArray: {:p}, dstPitch: {}, dstHeight: {}, WidthInBytes: {}, Height: {}, Depth: {}}}",
+ self.dstHost,
+ self.dstDevice.0 as *const (),
+ self.dstArray,
+ self.dstPitch,
+ self.dstHeight,
+ self.WidthInBytes,
+ self.Height,
+ self.Depth,
+ ).ok();
+ }
+}
+
+impl FormatCudaObject for CUmemLocation {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{{type: ").ok();
+ self.type_.write_post_execution(result, f);
+ write!(f, ", id: {}}}", self.id).ok();
+ }
+}
+
impl FormatCudaObject for *const i8 {
fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
- write!(f, "\"{}\"", unsafe { CStr::from_ptr(self) }.to_str().unwrap()).ok();
+ write!(
+ f,
+ "\"{}\"",
+ unsafe { CStr::from_ptr(self) }.to_str().unwrap()
+ )
+ .ok();
}
}
@@ -73,24 +339,40 @@ impl FormatCudaObject for u32 { }
}
+impl FormatCudaObject for u64 {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{}", self).ok();
+ }
+}
+
impl FormatCudaObject for i32 {
fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
write!(f, "{}", self).ok();
}
}
+impl FormatCudaObject for f32 {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{}", self).ok();
+ }
+}
+
impl FormatCudaObject for CUdevice {
fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
write!(f, "{}", self.0).ok();
}
}
-impl FormatCudaObject for CUjit_option {
+impl FormatCudaObject for usize {
fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
- match stringify_cujit_option(self) {
- Some(text) => write!(f, "{}", text),
- None => write!(f, "{}", self.0),
- };
+ write!(f, "{}", self).ok();
+ }
+}
+
+// TODO: support it properly
+impl FormatCudaObject for CUoutput_mode {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ write!(f, "{}", self.0).ok();
}
}
@@ -101,6 +383,19 @@ impl FormatCudaObject for CUuuid { }
}
+// ENUMS
+
+/*
+impl FormatCudaObject for CUjit_option {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cujit_option(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
impl FormatCudaObject for CUdevice_attribute {
fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
match stringify_cudevice_attribute(self) {
@@ -111,21 +406,113 @@ impl FormatCudaObject for CUdevice_attribute { }
}
+impl FormatCudaObject for CUdevice_P2PAttribute {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cudevice_p2pattribute(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUarray_format {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cuarray_format(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUresourceViewFormat {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_curesourceview_format(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUaddress_mode {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cuaddress_mode(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUfilter_mode {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cufilter_mode(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUgraphExecUpdateResult {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cugraph_exec_updateresult(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUmemorytype {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cumemorytype(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+
+impl FormatCudaObject for CUmemLocationType {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match stringify_cumemorytype(self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
+}
+*/
+
macro_rules! stringify_enum {
- ($fn_name:ident, $type_:ident, [ $($variant:ident),+ ]) => {
- pub(crate) fn $fn_name(x: $type_) -> Option<&'static str> {
- match x {
- $(
- $type_::$variant => Some(stringify!($variant)),
- )+
- _ => None
+ ($type_:ident, [ $($variant:ident),+ ]) => {
+ paste! {
+ pub(crate) fn [<stringify_ $type_>](x: $type_) -> Option<&'static str> {
+ match x {
+ $(
+ $type_::$variant => Some(stringify!($variant)),
+ )+
+ _ => None
+ }
+ }
+
+ impl FormatCudaObject for $type_ {
+ fn write_post_execution(self, result: CUresult, f: &mut impl Write) {
+ match [<stringify_ $type_>](self) {
+ Some(text) => write!(f, "{}", text),
+ None => write!(f, "{}", self.0),
+ }
+ .ok();
+ }
}
}
}
}
stringify_enum! {
- stringify_cudevice_attribute,
CUdevice_attribute_enum,
[
CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
@@ -250,7 +637,6 @@ stringify_enum! { }
stringify_enum! {
- stringify_cujit_option,
CUjit_option,
[
CU_JIT_MAX_REGISTERS,
@@ -278,7 +664,6 @@ stringify_enum! { }
stringify_enum! {
- stringify_curesult,
CUresult,
[
CUDA_SUCCESS,
@@ -359,3 +744,210 @@ stringify_enum! { CUDA_ERROR_UNKNOWN
]
}
+
+stringify_enum! {
+ CUdevice_P2PAttribute,
+ [
+ CU_DEVICE_P2P_ATTRIBUTE_PERFORMANCE_RANK,
+ CU_DEVICE_P2P_ATTRIBUTE_ACCESS_SUPPORTED,
+ CU_DEVICE_P2P_ATTRIBUTE_NATIVE_ATOMIC_SUPPORTED,
+ CU_DEVICE_P2P_ATTRIBUTE_ACCESS_ACCESS_SUPPORTED,
+ CU_DEVICE_P2P_ATTRIBUTE_CUDA_ARRAY_ACCESS_SUPPORTED
+ ]
+}
+
+stringify_enum! {
+ CUarray_format,
+ [
+ CU_AD_FORMAT_UNSIGNED_INT8,
+ CU_AD_FORMAT_UNSIGNED_INT16,
+ CU_AD_FORMAT_UNSIGNED_INT32,
+ CU_AD_FORMAT_SIGNED_INT8,
+ CU_AD_FORMAT_SIGNED_INT16,
+ CU_AD_FORMAT_SIGNED_INT32,
+ CU_AD_FORMAT_HALF,
+ CU_AD_FORMAT_FLOAT
+ ]
+}
+
+stringify_enum! {
+ CUresourceViewFormat,
+ [
+ CU_RES_VIEW_FORMAT_NONE,
+ CU_RES_VIEW_FORMAT_UINT_1X8,
+ CU_RES_VIEW_FORMAT_UINT_2X8,
+ CU_RES_VIEW_FORMAT_UINT_4X8,
+ CU_RES_VIEW_FORMAT_SINT_1X8,
+ CU_RES_VIEW_FORMAT_SINT_2X8,
+ CU_RES_VIEW_FORMAT_SINT_4X8,
+ CU_RES_VIEW_FORMAT_UINT_1X16,
+ CU_RES_VIEW_FORMAT_UINT_2X16,
+ CU_RES_VIEW_FORMAT_UINT_4X16,
+ CU_RES_VIEW_FORMAT_SINT_1X16,
+ CU_RES_VIEW_FORMAT_SINT_2X16,
+ CU_RES_VIEW_FORMAT_SINT_4X16,
+ CU_RES_VIEW_FORMAT_UINT_1X32,
+ CU_RES_VIEW_FORMAT_UINT_2X32,
+ CU_RES_VIEW_FORMAT_UINT_4X32,
+ CU_RES_VIEW_FORMAT_SINT_1X32,
+ CU_RES_VIEW_FORMAT_SINT_2X32,
+ CU_RES_VIEW_FORMAT_SINT_4X32,
+ CU_RES_VIEW_FORMAT_FLOAT_1X16,
+ CU_RES_VIEW_FORMAT_FLOAT_2X16,
+ CU_RES_VIEW_FORMAT_FLOAT_4X16,
+ CU_RES_VIEW_FORMAT_FLOAT_1X32,
+ CU_RES_VIEW_FORMAT_FLOAT_2X32,
+ CU_RES_VIEW_FORMAT_FLOAT_4X32,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC1,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC2,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC3,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC4,
+ CU_RES_VIEW_FORMAT_SIGNED_BC4,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC5,
+ CU_RES_VIEW_FORMAT_SIGNED_BC5,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC6H,
+ CU_RES_VIEW_FORMAT_SIGNED_BC6H,
+ CU_RES_VIEW_FORMAT_UNSIGNED_BC7
+ ]
+}
+
+stringify_enum! {
+ CUaddress_mode,
+ [
+ CU_TR_ADDRESS_MODE_WRAP,
+ CU_TR_ADDRESS_MODE_CLAMP,
+ CU_TR_ADDRESS_MODE_MIRROR,
+ CU_TR_ADDRESS_MODE_BORDER
+ ]
+}
+
+stringify_enum! {
+ CUfilter_mode,
+ [
+ CU_TR_FILTER_MODE_POINT,
+ CU_TR_FILTER_MODE_LINEAR
+ ]
+}
+
+stringify_enum! {
+ CUgraphExecUpdateResult,
+ [
+ CU_GRAPH_EXEC_UPDATE_SUCCESS,
+ CU_GRAPH_EXEC_UPDATE_ERROR,
+ CU_GRAPH_EXEC_UPDATE_ERROR_TOPOLOGY_CHANGED,
+ CU_GRAPH_EXEC_UPDATE_ERROR_NODE_TYPE_CHANGED,
+ CU_GRAPH_EXEC_UPDATE_ERROR_FUNCTION_CHANGED,
+ CU_GRAPH_EXEC_UPDATE_ERROR_PARAMETERS_CHANGED,
+ CU_GRAPH_EXEC_UPDATE_ERROR_NOT_SUPPORTED
+ ]
+}
+
+stringify_enum! {
+ CUmemorytype,
+ [
+ CU_MEMORYTYPE_HOST,
+ CU_MEMORYTYPE_DEVICE,
+ CU_MEMORYTYPE_ARRAY,
+ CU_MEMORYTYPE_UNIFIED
+ ]
+}
+
+stringify_enum! {
+ CUmemLocationType,
+ [
+ CU_MEM_LOCATION_TYPE_INVALID,
+ CU_MEM_LOCATION_TYPE_DEVICE
+ ]
+}
+
+stringify_enum! {
+ CUlimit,
+ [
+ CU_LIMIT_STACK_SIZE,
+ CU_LIMIT_PRINTF_FIFO_SIZE,
+ CU_LIMIT_MALLOC_HEAP_SIZE,
+ CU_LIMIT_DEV_RUNTIME_SYNC_DEPTH,
+ CU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT,
+ CU_LIMIT_MAX_L2_FETCH_GRANULARITY,
+ CU_LIMIT_PERSISTING_L2_CACHE_SIZE
+ ]
+}
+
+stringify_enum! {
+ CUpointer_attribute,
+ [
+ CU_POINTER_ATTRIBUTE_CONTEXT,
+ CU_POINTER_ATTRIBUTE_MEMORY_TYPE,
+ CU_POINTER_ATTRIBUTE_DEVICE_POINTER,
+ CU_POINTER_ATTRIBUTE_HOST_POINTER,
+ CU_POINTER_ATTRIBUTE_P2P_TOKENS,
+ CU_POINTER_ATTRIBUTE_SYNC_MEMOPS,
+ CU_POINTER_ATTRIBUTE_BUFFER_ID,
+ CU_POINTER_ATTRIBUTE_IS_MANAGED,
+ CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
+ CU_POINTER_ATTRIBUTE_IS_LEGACY_CUDA_IPC_CAPABLE,
+ CU_POINTER_ATTRIBUTE_RANGE_START_ADDR,
+ CU_POINTER_ATTRIBUTE_RANGE_SIZE,
+ CU_POINTER_ATTRIBUTE_MAPPED,
+ CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES,
+ CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE,
+ CU_POINTER_ATTRIBUTE_ACCESS_FLAGS
+ ]
+}
+
+stringify_enum! {
+ CUfunction_attribute,
+ [
+ CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
+ CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES,
+ CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES,
+ CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES,
+ CU_FUNC_ATTRIBUTE_NUM_REGS,
+ CU_FUNC_ATTRIBUTE_PTX_VERSION,
+ CU_FUNC_ATTRIBUTE_BINARY_VERSION,
+ CU_FUNC_ATTRIBUTE_CACHE_MODE_CA,
+ CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES,
+ CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT
+ ]
+}
+
+stringify_enum! {
+ CUmem_range_attribute,
+ [
+ CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY,
+ CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION,
+ CU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY,
+ CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION
+ ]
+}
+
+stringify_enum! {
+ CUfunc_cache,
+ [
+ CU_FUNC_CACHE_PREFER_NONE,
+ CU_FUNC_CACHE_PREFER_SHARED,
+ CU_FUNC_CACHE_PREFER_L1,
+ CU_FUNC_CACHE_PREFER_EQUAL
+ ]
+}
+
+stringify_enum! {
+ CUstreamCaptureMode,
+ [
+ CU_STREAM_CAPTURE_MODE_GLOBAL,
+ CU_STREAM_CAPTURE_MODE_THREAD_LOCAL,
+ CU_STREAM_CAPTURE_MODE_RELAXED
+ ]
+}
+
+stringify_enum! {
+ CUmem_advise,
+ [
+ CU_MEM_ADVISE_SET_READ_MOSTLY,
+ CU_MEM_ADVISE_UNSET_READ_MOSTLY,
+ CU_MEM_ADVISE_SET_PREFERRED_LOCATION,
+ CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION,
+ CU_MEM_ADVISE_SET_ACCESSED_BY,
+ CU_MEM_ADVISE_UNSET_ACCESSED_BY
+ ]
+}
diff --git a/zluda_dump/src/lib.rs b/zluda_dump/src/lib.rs index 1eb70e2..ecfd1ac 100644 --- a/zluda_dump/src/lib.rs +++ b/zluda_dump/src/lib.rs @@ -37,7 +37,15 @@ macro_rules! extern_redirect { let typed_fn = unsafe { std::mem::transmute::<_, extern "system" fn( $( $arg_id : $arg_type),* ) -> $ret_type>(fn_ptr) }; typed_fn($( $arg_id ),*) }; - crate::handle_cuda_function_call(stringify!($fn_name), original_fn) + let get_formatted_args = |fn_logger: &mut crate::log::FunctionLogger, result: CUresult| { + let arg_count = (count_tts!($($arg_id),*) + 1) / 2; + fn_logger.begin_writing_arguments(arg_count); + $( + fn_logger.write_single_argument(result, $arg_id); + )* + fn_logger.end_writing_arguments(); + }; + crate::handle_cuda_function_call(stringify!($fn_name), original_fn, get_formatted_args) } }; } @@ -277,32 +285,9 @@ pub struct ModuleDump { fn handle_cuda_function_call( func: &'static str, original_cuda_fn: impl FnOnce(NonNull<c_void>) -> CUresult, + print_arguments_fn: impl FnOnce(&mut crate::log::FunctionLogger, CUresult), ) -> CUresult { - let global_state_mutex = &*GLOBAL_STATE; - // We unwrap because there's really no sensible thing we could do, - // alternatively we could return a CUDA error, but I think it's fine to - // crash. This is a diagnostic utility, if the lock was poisoned we can't - // extract any useful trace or logging anyway - let mut global_state = &mut *global_state_mutex.lock().unwrap(); - let (mut logger, delayed_state) = match global_state.delayed_state { - LateInit::Success(ref mut delayed_state) => { - (global_state.log_factory.get_logger(func), delayed_state) - } - // There's no libcuda to load, so we might as well panic - LateInit::Error => panic!(), - LateInit::Unitialized => { - let (new_delayed_state, logger) = - GlobalDelayedState::new(func, &mut global_state.log_factory); - global_state.delayed_state = new_delayed_state; - (logger, global_state.delayed_state.as_mut().unwrap()) - } - }; - let name = std::ffi::CString::new(func).unwrap(); - let fn_ptr = - unsafe { os::get_proc_address(delayed_state.libcuda_handle.as_ptr(), name.as_c_str()) }; - let cu_result = original_cuda_fn(NonNull::new(fn_ptr).unwrap()); - logger.result = Some(cu_result); - cu_result + handle_cuda_function_call_with_probes(func, || (), original_cuda_fn, print_arguments_fn, |_| ()) } fn handle_cuda_function_call_with_probes<T, PostFn>( diff --git a/zluda_dump/src/log.rs b/zluda_dump/src/log.rs index ef36acd..8c226f9 100644 --- a/zluda_dump/src/log.rs +++ b/zluda_dump/src/log.rs @@ -267,7 +267,7 @@ impl<'a> FunctionLogger<'a> { self.write_buffer.write("...) -> ");
}
if let Some(result) = self.result {
- match format::stringify_curesult(result) {
+ match format::stringify_CUresult(result) {
Some(text) => self.write_buffer.write(text),
None => write!(self.write_buffer, "{}", result.0).unwrap(),
}
|