summaryrefslogtreecommitdiff
path: root/tools/gfx/cuda/cuda-helper-functions.cpp
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2024-03-15 18:25:21 +0100
committerGitHub <noreply@github.com>2024-03-15 10:25:21 -0700
commit9ee88a43f4e67d9c714c27bf968401b6bf7524af (patch)
tree11c0f7b46168d7885f2ac220ae8bd8f51d40ac83 /tools/gfx/cuda/cuda-helper-functions.cpp
parentd40931cc8bde13520ea45769cf94e7cc6cc9065f (diff)
[gfx] use CUDA driver API (#3776)
Diffstat (limited to 'tools/gfx/cuda/cuda-helper-functions.cpp')
-rw-r--r--tools/gfx/cuda/cuda-helper-functions.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp
index 0a8d734d8..d478e8815 100644
--- a/tools/gfx/cuda/cuda-helper-functions.cpp
+++ b/tools/gfx/cuda/cuda-helper-functions.cpp
@@ -39,11 +39,6 @@ SlangResult _handleCUDAError(CUresult cuResult, const char* file, int line)
return info.handle();
}
-SlangResult _handleCUDAError(cudaError_t error, const char* file, int line)
-{
- return CUDAErrorInfo(file, line, cudaGetErrorName(error), cudaGetErrorString(error)).handle();
-}
-
# ifdef RENDER_TEST_OPTIX
static bool _isError(OptixResult result)
@@ -71,41 +66,41 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message,
# endif
# endif
-AdapterLUID getAdapterLUID(int device)
+AdapterLUID getAdapterLUID(int deviceIndex)
{
+ CUdevice device;
+ cuDeviceGet(&device, deviceIndex);
AdapterLUID luid = {};
-#if SLANG_WIN32 || SLANG_WIN64
- // LUID reported by CUDA is undefined i not on windows platform.
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- SLANG_ASSERT(sizeof(AdapterLUID) >= sizeof(cudaDeviceProp::luid));
- memcpy(&luid, prop.luid, sizeof(cudaDeviceProp::luid));
-#else
- SLANG_ASSERT(sizeof(AdapterLUID) >= sizeof(int));
- memcpy(&luid, &device, sizeof(int));
-#endif
+ unsigned int deviceNodeMask;
+ cuDeviceGetLuid((char*)&luid, &deviceNodeMask, device);
return luid;
}
-} // namespace cuda
-
-Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters)
+Result SLANG_MCALL getAdapters(List<AdapterInfo>& outAdapters)
{
int deviceCount;
- cudaGetDeviceCount(&deviceCount);
- for (int device = 0; device < deviceCount; device++)
+ SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetCount(&deviceCount));
+ for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
{
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
+ CUdevice device;
+ SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&device, deviceIndex));
+
AdapterInfo info = {};
- memcpy(info.name, prop.name, Math::Min(strlen(prop.name), sizeof(AdapterInfo::name) - 1));
- info.luid = cuda::getAdapterLUID(device);
+ SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetName(info.name, sizeof(info.name), device));
+ info.luid = getAdapterLUID(deviceIndex);
outAdapters.add(info);
}
return SLANG_OK;
}
+} // namespace cuda
+
+Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters)
+{
+ return cuda::getAdapters(outAdapters);
+}
+
Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice)
{
RefPtr<cuda::DeviceImpl> result = new cuda::DeviceImpl();