From 3639e71dfcb7e5284949a98d1fefddda118338be Mon Sep 17 00:00:00 2001 From: jarcherNV Date: Fri, 15 Aug 2025 15:16:04 -0700 Subject: Update cuda context creation to support cuda 13 (#8181) Update cuda context creation to support both cuda 12 and cuda 13. --- tools/gfx/cuda/cuda-device.cpp | 3 ++- tools/gfx/cuda/cuda-helper-functions.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp index 129ea793f..be190babf 100644 --- a/tools/gfx/cuda/cuda-device.cpp +++ b/tools/gfx/cuda/cuda-device.cpp @@ -180,8 +180,9 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc) SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&m_device, m_deviceIndex)); + // Use version-aware context creation that works with both CUDA 12 and CUDA 13 SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL( - cuCtxCreate(&m_context->m_context, 0, m_device), + createCudaContext(&m_context->m_context, 0, m_device), reportType); { diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h index 8474e830d..2b2614bb0 100644 --- a/tools/gfx/cuda/cuda-helper-functions.h +++ b/tools/gfx/cuda/cuda-helper-functions.h @@ -99,6 +99,19 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, AdapterLUID getAdapterLUID(int deviceIndex); +// Version-aware cuCtxCreate wrapper that works with both CUDA 12 and CUDA 13 +inline CUresult createCudaContext(CUcontext* pctx, unsigned int flags, CUdevice dev) +{ +#if CUDA_VERSION >= 13000 + // CUDA 13+ requires CUctxCreateParams + CUctxCreateParams ctxCreateParams = {}; + return cuCtxCreate(pctx, &ctxCreateParams, flags, dev); +#else + // CUDA 12 and earlier use the old signature + return cuCtxCreate(pctx, flags, dev); +#endif +} + } // namespace cuda #endif -- cgit v1.2.3