diff options
Diffstat (limited to 'tools/gfx/cuda/cuda-helper-functions.cpp')
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
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<AdapterInfo>& 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<AdapterInfo>& outAdapters) Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { -RefPtr<cuda::DeviceImpl> result = new cuda::DeviceImpl(); -SLANG_RETURN_ON_FAIL(result->initialize(*desc)); -returnComPtr(outDevice, result); -return SLANG_OK; + RefPtr<cuda::DeviceImpl> 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<AdapterInfo>& 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 |
