From d0fead905623475fecb981356b5f5818c87b0928 Mon Sep 17 00:00:00 2001 From: Ethan Tillison Date: Fri, 14 Apr 2023 13:14:02 -0700 Subject: [PATCH] nvapi: Implement NVAPI_GetLogicalGPUFromPhysicalGPU --- src/nvapi.cpp | 18 ++++++++++++++++++ src/nvapi_interface.cpp | 1 + tests/nvapi_sysinfo_topo.cpp | 13 +++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/nvapi.cpp b/src/nvapi.cpp index 2d101585..a8807923 100644 --- a/src/nvapi.cpp +++ b/src/nvapi.cpp @@ -127,6 +127,24 @@ extern "C" { return Ok(n); } + NvAPI_Status __cdecl NvAPI_GetLogicalGPUFromPhysicalGPU(NvPhysicalGpuHandle hPhysicalGPU, NvLogicalGpuHandle* pLogicalGPU) { + constexpr auto n = __func__; + + if (nvapiAdapterRegistry == nullptr) + return ApiNotInitialized(n); + + if (hPhysicalGPU == nullptr) + return InvalidArgument(n); + + auto adapter = reinterpret_cast(hPhysicalGPU); + if (!nvapiAdapterRegistry->IsAdapter(adapter)) + return ExpectedPhysicalGpuHandle(n); + + *pLogicalGPU = reinterpret_cast(adapter); + + return Ok(n); + } + NvAPI_Status __cdecl NvAPI_GetPhysicalGPUsFromLogicalGPU(NvLogicalGpuHandle hLogicalGPU, NvPhysicalGpuHandle hPhysicalGPU[NVAPI_MAX_PHYSICAL_GPUS], NvU32* pGpuCount) { constexpr auto n = __func__; diff --git a/src/nvapi_interface.cpp b/src/nvapi_interface.cpp index ef249d0a..6047c17b 100644 --- a/src/nvapi_interface.cpp +++ b/src/nvapi_interface.cpp @@ -121,6 +121,7 @@ extern "C" { INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetGPUIDfromPhysicalGPU) INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetDisplayDriverVersion) INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetPhysicalGPUsFromDisplay) + INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetLogicalGPUFromPhysicalGPU) INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetPhysicalGPUsFromLogicalGPU) INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaDisplayHandle) INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaUnAttachedDisplayHandle) diff --git a/tests/nvapi_sysinfo_topo.cpp b/tests/nvapi_sysinfo_topo.cpp index 4d7a5f5e..ee343ecc 100644 --- a/tests/nvapi_sysinfo_topo.cpp +++ b/tests/nvapi_sysinfo_topo.cpp @@ -93,6 +93,19 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") { REQUIRE(handle == nullptr); } + SECTION("GetLogicalGPUFromPhysicalGPU succeeds") { + NvPhysicalGpuHandle handles[NVAPI_MAX_PHYSICAL_GPUS]{}; + NvU32 count; + REQUIRE(NvAPI_EnumPhysicalGPUs(handles, &count) == NVAPI_OK); + + NvLogicalGpuHandle logicalhandle; + REQUIRE(NvAPI_GetLogicalGPUFromPhysicalGPU(handles[0], &logicalhandle) == NVAPI_OK); + REQUIRE(logicalhandle == reinterpret_cast(handles[0])); + + REQUIRE(NvAPI_GetLogicalGPUFromPhysicalGPU(handles[1], &logicalhandle) == NVAPI_OK); + REQUIRE(logicalhandle == reinterpret_cast(handles[1])); + } + SECTION("GetPhysicalGPUsFromLogicalGPU succeeds") { NvLogicalGpuHandle handles[NVAPI_MAX_LOGICAL_GPUS]{}; NvU32 count;