From 8f9d58416934cbf850f0f01e5fefbdfe1b02d4d6 Mon Sep 17 00:00:00 2001 From: skallweitNV <64953474+skallweitNV@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:58:49 +0100 Subject: Add gfxGetAdapters function (currently implemented for D3D12/Vulkan) (#2486) * Add gfxGetAdapters function (currently implemented for D3D12/Vulkan) * Extend to handle DirectX11 and CUDA * Use blob to return adapter list and add AdapterList helper * Replace strncpy with memcpy Co-authored-by: jsmall-nvidia --- tools/gfx/cuda/cuda-helper-functions.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (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 6325d9fc6..702caf253 100644 --- a/tools/gfx/cuda/cuda-helper-functions.cpp +++ b/tools/gfx/cuda/cuda-helper-functions.cpp @@ -72,6 +72,22 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, # endif } // namespace cuda +Result SLANG_MCALL getCUDAAdapters(List& outAdapters) +{ + int count; + cudaGetDeviceCount(&count); + for (int i = 0; i < count; i++) + { + cudaDeviceProp prop; + cudaGetDeviceProperties(&prop, i); + AdapterInfo info = {}; + memcpy(info.name, prop.name, Math::Min(strlen(prop.name), sizeof(AdapterInfo::name) - 1)); + outAdapters.add(info); + } + + return SLANG_OK; +} + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { RefPtr result = new cuda::DeviceImpl(); @@ -80,6 +96,13 @@ returnComPtr(outDevice, result); return SLANG_OK; } #else + +Result SLANG_MCALL getCUDAAdapters(List& outAdapters) +{ + SLANG_UNUSED(outAdapters); + return SLANG_FAIL; +} + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { SLANG_UNUSED(desc); -- cgit v1.2.3