Skip to content

Commit 7943066

Browse files
authored
Add optional logging using cuModuleLoadDataEx (#475)
This can be enabled with SLANG_RHI_CUDA_DEBUG_MODULE_LOAD.
1 parent be168bf commit 7943066

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/cuda/cuda-pipeline.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "cuda-shader-object-layout.h"
55
#include "cuda-utils.h"
66

7+
// Enable using cuModuleLoadDataEx for loading CUDA modules.
8+
// This allows us to get logs for module loading.
9+
#define SLANG_RHI_CUDA_DEBUG_MODULE_LOAD 0
10+
711
namespace rhi::cuda {
812

913
ComputePipelineImpl::ComputePipelineImpl(Device* device, const ComputePipelineDesc& desc)
@@ -40,7 +44,49 @@ Result DeviceImpl::createComputePipeline2(const ComputePipelineDesc& desc, IComp
4044
pipeline->m_program = program;
4145
pipeline->m_rootObjectLayout = program->m_rootObjectLayout;
4246

47+
#if SLANG_RHI_CUDA_DEBUG_MODULE_LOAD
48+
// Setup buffers for info and error logs.
49+
size_t infoLogSize = 16 * 1024;
50+
size_t errorLogSize = 16 * 1024;
51+
int logVerbose = 1;
52+
auto infoLog = std::make_unique<uint8_t[]>(infoLogSize);
53+
auto errorLog = std::make_unique<uint8_t[]>(errorLogSize);
54+
55+
CUjit_option options[] = {
56+
CU_JIT_INFO_LOG_BUFFER,
57+
CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES,
58+
CU_JIT_ERROR_LOG_BUFFER,
59+
CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES,
60+
CU_JIT_LOG_VERBOSE,
61+
};
62+
void* optionValues[] = {
63+
infoLog.get(),
64+
(void*)(uintptr_t)infoLogSize,
65+
errorLog.get(),
66+
(void*)(uintptr_t)errorLogSize,
67+
(void*)(uintptr_t)logVerbose,
68+
};
69+
CUresult result = cuModuleLoadDataEx(
70+
&pipeline->m_module,
71+
module.code->getBufferPointer(),
72+
SLANG_COUNT_OF(options),
73+
options,
74+
optionValues
75+
);
76+
infoLogSize = *(unsigned int*)(&optionValues[1]);
77+
errorLogSize = *(unsigned int*)(&optionValues[3]);
78+
if (infoLogSize > 0)
79+
{
80+
printInfo("Info log from cuModuleLoadDataEx:\n%s", infoLog.get());
81+
}
82+
if (errorLogSize > 0)
83+
{
84+
printError("Error log from cuModuleLoadDataEx:\n%s", errorLog.get());
85+
}
86+
SLANG_CUDA_RETURN_ON_FAIL_REPORT(result, this);
87+
#else // SLANG_RHI_CUDA_DEBUG_MODULE_LOAD
4388
SLANG_CUDA_RETURN_ON_FAIL_REPORT(cuModuleLoadData(&pipeline->m_module, module.code->getBufferPointer()), this);
89+
#endif // SLANG_RHI_CUDA_DEBUG_MODULE_LOAD
4490
pipeline->m_kernelName = module.entryPointName;
4591
SLANG_CUDA_RETURN_ON_FAIL_REPORT(
4692
cuModuleGetFunction(&pipeline->m_function, pipeline->m_module, pipeline->m_kernelName.data()),

0 commit comments

Comments
 (0)