Skip to content

Commit 19b1107

Browse files
committed
[mlir][gpu] Add debug print with environment value
This work introduces `MLIR_CUDA_DEBUG` environment value and `debug_print` function to be able to debug runtimes. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D156232
1 parent f274ffc commit 19b1107

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@
5555

5656
thread_local static int32_t defaultDevice = 0;
5757

58+
const char *kDebugEnvironmentVariable = "MLIR_CUDA_DEBUG";
59+
60+
/// Helper method that checks environment value for debugging.
61+
bool isDebugEnabled() {
62+
static bool isInitialized = false;
63+
static bool isEnabled = false;
64+
if (!isInitialized)
65+
isEnabled = getenv(kDebugEnvironmentVariable) != nullptr;
66+
return isEnabled;
67+
}
68+
69+
#define debug_print(fmt, ...) \
70+
do { \
71+
if (isDebugEnabled()) \
72+
fprintf(stderr, "%s:%d:%s(): " fmt, "CudaRuntimeWrappers.cpp", __LINE__, \
73+
__func__, __VA_ARGS__); \
74+
} while (0)
75+
5876
// Make the primary context of the current default device current for the
5977
// duration
6078
// of the instance and restore the previous context on destruction.
@@ -273,6 +291,24 @@ extern "C" MLIR_CUDA_WRAPPERS_EXPORT void mgpuTensorMapEncodeTiled(
273291
tensorMap, tensorDataType, tensorRank, globalAddress, globalDim,
274292
globalStrides, boxDim, elementStrides, interleave, swizzle, l2Promotion,
275293
oobFill));
294+
debug_print("Created TMA descriptor\n Addr: %p\n"
295+
"data type : %d\n"
296+
"rank : %d\n"
297+
"globalDim[5]: %zu, %zu, %zu, %zu, %zu\n"
298+
"globalStrides[5]: %zu, %zu, %zu, %zu, %zu\n"
299+
"boxDim[5]: %u, %u, %u, %u, %u\n"
300+
"elementStrides[5]: %u, %u, %u, %u, %u\n"
301+
"interleave: %u \n"
302+
"swizzle: %u \n"
303+
"l2Promotion: %u \n"
304+
"oobFill: %u \n",
305+
(void *)&tensorMap, tensorDataType, tensorRank, globalDim[0],
306+
globalDim[1], globalDim[2], globalDim[3], globalDim[4],
307+
globalStrides[0], globalStrides[1], globalStrides[2],
308+
globalStrides[3], globalStrides[4], boxDim[0], boxDim[1],
309+
boxDim[2], boxDim[3], boxDim[4], elementStrides[0],
310+
elementStrides[1], elementStrides[2], elementStrides[3],
311+
elementStrides[4], interleave, swizzle, l2Promotion, oobFill);
276312
}
277313

278314
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void *mgpuTensorMapEncodeTiledMemref(

0 commit comments

Comments
 (0)