diff options
| author | skallweitNV <64953474+skallweitNV@users.noreply.github.com> | 2022-11-04 17:34:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-04 17:34:53 +0100 |
| commit | 015bde8d5a46f32979c00dbb1feb4b3d80729c44 (patch) | |
| tree | b95713bb080d0fbcb11d9b2519b9166e11fe5dde /tools/gfx/cuda | |
| parent | 9a3a4b08c8817905c2f608549c0e57216f8068c5 (diff) | |
Add AdapterLUID to identify GPU adapters (#2492)
* Add AdapterLUID to identify GPU adapters
* Remove adapter option in render-test
Diffstat (limited to 'tools/gfx/cuda')
| -rw-r--r-- | tools/gfx/cuda/cuda-device.cpp | 25 | ||||
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.cpp | 40 | ||||
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.h | 2 |
3 files changed, 52 insertions, 15 deletions
diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp index 32454109b..76538cfad 100644 --- a/tools/gfx/cuda/cuda-device.cpp +++ b/tools/gfx/cuda/cuda-device.cpp @@ -150,13 +150,30 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc) SLANG_RETURN_ON_FAIL(_initCuda(reportType)); - SLANG_RETURN_ON_FAIL(_findMaxFlopsDeviceIndex(&m_deviceIndex)); + if (desc.adapterLUID) + { + int deviceCount = -1; + cuDeviceGetCount(&deviceCount); + for (int deviceIndex = 0; deviceIndex < deviceCount; ++deviceIndex) + { + if (cuda::getAdapterLUID(deviceIndex) == *desc.adapterLUID) + { + m_deviceIndex = deviceIndex; + break; + } + } + if (m_deviceIndex >= deviceCount) + return SLANG_E_INVALID_ARG; + } + else + { + SLANG_RETURN_ON_FAIL(_findMaxFlopsDeviceIndex(&m_deviceIndex)); + } + SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(cudaSetDevice(m_deviceIndex), reportType); m_context = new CUDAContext(); - int count = -1; - cuDeviceGetCount(&count); SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&m_device, m_deviceIndex)); SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL( @@ -1103,7 +1120,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::readBufferResource( ISlangBlob** outBlob) { auto bufferImpl = static_cast<BufferResourceImpl*>(buffer); - + List<uint8_t> blobData; blobData.setCount((Index)size); 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 diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h index 92ac4f4ed..7417249d5 100644 --- a/tools/gfx/cuda/cuda-helper-functions.h +++ b/tools/gfx/cuda/cuda-helper-functions.h @@ -99,6 +99,8 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, # endif +AdapterLUID getAdapterLUID(int device); + } // namespace cuda #endif |
