Skip to content

Commit

Permalink
nvapi: Implement NVAPI_GetLogicalGPUFromPhysicalGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
nvetillison authored and jp7677 committed Apr 20, 2023
1 parent 8a5f8b5 commit d0fead9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/nvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NvapiAdapter*>(hPhysicalGPU);
if (!nvapiAdapterRegistry->IsAdapter(adapter))
return ExpectedPhysicalGpuHandle(n);

*pLogicalGPU = reinterpret_cast<NvLogicalGpuHandle>(adapter);

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GetPhysicalGPUsFromLogicalGPU(NvLogicalGpuHandle hLogicalGPU, NvPhysicalGpuHandle hPhysicalGPU[NVAPI_MAX_PHYSICAL_GPUS], NvU32* pGpuCount) {
constexpr auto n = __func__;

Expand Down
1 change: 1 addition & 0 deletions src/nvapi_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/nvapi_sysinfo_topo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NvLogicalGpuHandle>(handles[0]));

REQUIRE(NvAPI_GetLogicalGPUFromPhysicalGPU(handles[1], &logicalhandle) == NVAPI_OK);
REQUIRE(logicalhandle == reinterpret_cast<NvLogicalGpuHandle>(handles[1]));
}

SECTION("GetPhysicalGPUsFromLogicalGPU succeeds") {
NvLogicalGpuHandle handles[NVAPI_MAX_LOGICAL_GPUS]{};
NvU32 count;
Expand Down

0 comments on commit d0fead9

Please sign in to comment.