|
4 | 4 | #include "cuda-shader-object-layout.h"
|
5 | 5 | #include "cuda-utils.h"
|
6 | 6 |
|
| 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 | + |
7 | 11 | namespace rhi::cuda {
|
8 | 12 |
|
9 | 13 | ComputePipelineImpl::ComputePipelineImpl(Device* device, const ComputePipelineDesc& desc)
|
@@ -40,7 +44,49 @@ Result DeviceImpl::createComputePipeline2(const ComputePipelineDesc& desc, IComp
|
40 | 44 | pipeline->m_program = program;
|
41 | 45 | pipeline->m_rootObjectLayout = program->m_rootObjectLayout;
|
42 | 46 |
|
| 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 |
43 | 88 | SLANG_CUDA_RETURN_ON_FAIL_REPORT(cuModuleLoadData(&pipeline->m_module, module.code->getBufferPointer()), this);
|
| 89 | +#endif // SLANG_RHI_CUDA_DEBUG_MODULE_LOAD |
44 | 90 | pipeline->m_kernelName = module.entryPointName;
|
45 | 91 | SLANG_CUDA_RETURN_ON_FAIL_REPORT(
|
46 | 92 | cuModuleGetFunction(&pipeline->m_function, pipeline->m_module, pipeline->m_kernelName.data()),
|
|
0 commit comments