diff --git a/src/main.c b/src/main.c index 2078ae7..73d38c8 100644 --- a/src/main.c +++ b/src/main.c @@ -226,27 +226,21 @@ int main(int argc, char *argv[]) { /***** SORT NVAPI HANDLES */ { - // Array to hold NVML device serial numbers, each with up to 32 characters - char nvmlSerials[NVAPI_MAX_PHYSICAL_GPUS][32]; + // Array to hold NVML device identifiers + NvU32 nvmlIdentifiers[NVAPI_MAX_PHYSICAL_GPUS]; - // Array to hold NVAPI device serial numbers, each with up to 32 characters - char nvapiSerials[NVAPI_MAX_PHYSICAL_GPUS][32]; + // Array to hold NVAPI device identifiers + NvU32 nvapiIdentifiers[NVAPI_MAX_PHYSICAL_GPUS]; - // Step 1: Loop through each device to retrieve and store NVML and NVAPI serials + // Step 1: Loop through each device to retrieve and store NVML and NVAPI identifiers for (unsigned int i = 0; i < deviceCount; i++) { - // Get serial number for NVML device and store in nvmlSerials array - NVML_CALL(nvmlDeviceGetSerial(nvmlDevices[i], nvmlSerials[i], 32), errored); + nvmlPciInfo_t nvmlPciInfo; + NVML_CALL(nvmlDeviceGetPciInfo(nvmlDevices[i], &nvmlPciInfo), errored); + nvmlIdentifiers[i] = nvmlPciInfo.bus; - // Prepare NVAPI board info struct - NV_BOARD_INFO boardInfo = { - .version = NV_BOARD_INFO_VER, - }; - - // Get board info for NVAPI device - NVAPI_CALL(NvAPI_GPU_GetBoardInfo(nvapiDevices[i], &boardInfo), errored); - - // Copy the serial number from board info to the nvapiSerials array - strncpy(nvapiSerials[i], boardInfo.BoardNum, 32); + NvU32 nvapiBusId; + NVAPI_CALL(NvAPI_GPU_GetBusId(nvapiDevices[i], &nvapiBusId), errored); + nvapiIdentifiers[i] = nvapiBusId; } // Array to store NVAPI device handles in sorted order @@ -255,9 +249,9 @@ int main(int argc, char *argv[]) { // Step 2: Match and order NVAPI devices based on serial numbers for (unsigned int i = 0; i < deviceCount; i++) { for (unsigned int j = 0; j < deviceCount; j++) { - // Compare NVML and NVAPI serials - if (strcmp(nvmlSerials[i], nvapiSerials[j]) == 0) { - // Set sorted handle + // Compare NVML and NVAPI identifiers + if (nvmlIdentifiers[i] == nvapiIdentifiers[j]) { + // sortedNvapiDevices[i] = nvapiDevices[j]; // Exit the inner loop diff --git a/src/nvapi.c b/src/nvapi.c index 6fc10cb..2f5623a 100644 --- a/src/nvapi.c +++ b/src/nvapi.c @@ -15,7 +15,7 @@ typedef void * (*nvapi_QueryInterface_t)(int); typedef NvAPI_Status (*NvAPI_EnumPhysicalGPUs_t)(NvPhysicalGpuHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *); -typedef NvAPI_Status (*NvAPI_GPU_GetBoardInfo_t)(NvPhysicalGpuHandle, NV_BOARD_INFO *); +typedef NvAPI_Status (*NvAPI_GPU_GetBusId_t)(NvPhysicalGpuHandle, NvU32 *); typedef NvAPI_Status (*NvAPI_GPU_GetFullName_t)(NvPhysicalGpuHandle, NvAPI_ShortString); typedef NvAPI_Status (*NvAPI_GPU_SetForcePstate_t)(NvPhysicalGpuHandle, NvU32, NvU32); typedef NvAPI_Status (*NvAPI_GetErrorMessage_t)(NvAPI_Status, NvAPI_ShortString); @@ -27,7 +27,7 @@ typedef NvAPI_Status (*NvAPI_Unload_t)(); static void * lib; static NvAPI_EnumPhysicalGPUs_t _NvAPI_EnumPhysicalGPUs; -static NvAPI_GPU_GetBoardInfo_t _NvAPI_GPU_GetBoardInfo; +static NvAPI_GPU_GetBusId_t _NvAPI_GPU_GetBusId; static NvAPI_GPU_GetFullName_t _NvAPI_GPU_GetFullName; static NvAPI_GPU_SetForcePstate_t _NvAPI_GPU_SetForcePstate; static NvAPI_GetErrorMessage_t _NvAPI_GetErrorMessage; @@ -52,12 +52,12 @@ NvAPI_Status NvAPI_EnumPhysicalGPUs(NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PH return _NvAPI_EnumPhysicalGPUs(nvGPUHandle, pGpuCount); } -NvAPI_Status NvAPI_GPU_GetBoardInfo(NvPhysicalGpuHandle hPhysicalGpu, NV_BOARD_INFO * pBoardInfo) { +NvAPI_Status NvAPI_GPU_GetBusId(NvPhysicalGpuHandle hPhysicalGpu, NvU32 * pBusId) { // Ensure the function pointer is valid - NVAPI_POINTER(_NvAPI_GPU_GetBoardInfo); + NVAPI_POINTER(_NvAPI_GPU_GetBusId); // Invoke the function using the provided parameters - return _NvAPI_GPU_GetBoardInfo(hPhysicalGpu, pBoardInfo); + return _NvAPI_GPU_GetBusId(hPhysicalGpu, pBusId); } NvAPI_Status NvAPI_GPU_GetFullName(NvPhysicalGpuHandle hPhysicalGpu, NvAPI_ShortString szName) { @@ -134,7 +134,7 @@ NvAPI_Status NvAPI_Initialize() { // Retrieve the addresses of specific NvAPI functions using nvapi_QueryInterface _NvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUs_t) nvapi_QueryInterface(0xe5ac921f); - _NvAPI_GPU_GetBoardInfo = (NvAPI_GPU_GetBoardInfo_t) nvapi_QueryInterface(0x22d54523); + _NvAPI_GPU_GetBusId = (NvAPI_GPU_GetBusId_t) nvapi_QueryInterface(0x1be0b8e5); _NvAPI_GPU_GetFullName = (NvAPI_GPU_GetFullName_t) nvapi_QueryInterface(0xceee8e9f); _NvAPI_GPU_SetForcePstate = (NvAPI_GPU_SetForcePstate_t) nvapi_QueryInterface(0x025bfb10); _NvAPI_GetErrorMessage = (NvAPI_GetErrorMessage_t) nvapi_QueryInterface(0x6c2d048c);