diff options
| author | skallweitNV <64953474+skallweitNV@users.noreply.github.com> | 2022-11-03 16:58:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-03 11:58:49 -0400 |
| commit | 8f9d58416934cbf850f0f01e5fefbdfe1b02d4d6 (patch) | |
| tree | 3d376e772dcaeb7d0ef55d091fe49e33a6f57fb1 /tools/gfx/cuda | |
| parent | 203b5d7a5014d7f140345567e065cbf57b57b819 (diff) | |
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 <jsmall@nvidia.com>
Diffstat (limited to 'tools/gfx/cuda')
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.cpp | 23 | ||||
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.h | 5 |
2 files changed, 27 insertions, 1 deletions
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<AdapterInfo>& 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<cuda::DeviceImpl> result = new cuda::DeviceImpl(); @@ -80,6 +96,13 @@ returnComPtr(outDevice, result); return SLANG_OK; } #else + +Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters) +{ + SLANG_UNUSED(outAdapters); + return SLANG_FAIL; +} + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { SLANG_UNUSED(desc); diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h index 001e3946a..92ac4f4ed 100644 --- a/tools/gfx/cuda/cuda-helper-functions.h +++ b/tools/gfx/cuda/cuda-helper-functions.h @@ -3,12 +3,13 @@ #include "slang-gfx.h" #include "cuda-base.h" +#include "../../../source/core/slang-list.h" namespace gfx { -#ifdef GFX_ENABLE_CUDA using namespace Slang; +#ifdef GFX_ENABLE_CUDA namespace cuda { SLANG_FORCE_INLINE bool _isError(CUresult result) { return result != 0; } @@ -101,6 +102,8 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, } // namespace cuda #endif +Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters); + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice); } // namespace gfx |
