From 015bde8d5a46f32979c00dbb1feb4b3d80729c44 Mon Sep 17 00:00:00 2001 From: skallweitNV <64953474+skallweitNV@users.noreply.github.com> Date: Fri, 4 Nov 2022 17:34:53 +0100 Subject: Add AdapterLUID to identify GPU adapters (#2492) * Add AdapterLUID to identify GPU adapters * Remove adapter option in render-test --- tools/gfx/cuda/cuda-helper-functions.cpp | 40 +++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'tools/gfx/cuda/cuda-helper-functions.cpp') diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp index 702caf253..0a8d734d8 100644 --- a/tools/gfx/cuda/cuda-helper-functions.cpp +++ b/tools/gfx/cuda/cuda-helper-functions.cpp @@ -70,18 +70,36 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, } # endif # endif + +AdapterLUID getAdapterLUID(int device) +{ + 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 + return luid; +} + } // namespace cuda Result SLANG_MCALL getCUDAAdapters(List& outAdapters) { - int count; - cudaGetDeviceCount(&count); - for (int i = 0; i < count; i++) + int deviceCount; + cudaGetDeviceCount(&deviceCount); + for (int device = 0; device < deviceCount; device++) { cudaDeviceProp prop; - cudaGetDeviceProperties(&prop, i); + cudaGetDeviceProperties(&prop, device); AdapterInfo info = {}; memcpy(info.name, prop.name, Math::Min(strlen(prop.name), sizeof(AdapterInfo::name) - 1)); + info.luid = cuda::getAdapterLUID(device); outAdapters.add(info); } @@ -90,10 +108,10 @@ Result SLANG_MCALL getCUDAAdapters(List& outAdapters) Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { -RefPtr result = new cuda::DeviceImpl(); -SLANG_RETURN_ON_FAIL(result->initialize(*desc)); -returnComPtr(outDevice, result); -return SLANG_OK; + RefPtr result = new cuda::DeviceImpl(); + SLANG_RETURN_ON_FAIL(result->initialize(*desc)); + returnComPtr(outDevice, result); + return SLANG_OK; } #else @@ -105,9 +123,9 @@ Result SLANG_MCALL getCUDAAdapters(List& outAdapters) Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { -SLANG_UNUSED(desc); -*outDevice = nullptr; -return SLANG_FAIL; + SLANG_UNUSED(desc); + *outDevice = nullptr; + return SLANG_FAIL; } #endif -- cgit v1.2.3