I am writing a code to measure the power usage of an NVIDIA Tesla K20 GPU (Kepler architecture) periodically using the NVML API.
Variables:
nvmlReturn_t result;
nvmlEnableState_t pmmode;
nvmlDevice_t nvmlDeviceID;
unsigned int powerInt;
Basic code:
result = nvmlDeviceGetPowerManagementMode(nvmlDeviceID, &pmmode);
if (pmmode == NVML_FEATURE_ENABLED) {
result = nvmlDeviceGetPowerUsage(nvmlDeviceID, &powerInt);
}
My issue is that nvmlDeviceGetPowerManagementMode
is always returning NVML_ERROR_INVALID_ARGUMENT
. I checked this.
The NVML API Documentation says that NVML_ERROR_INVALID_ARGUMENT
is returned when either nvmlDeviceID
is invalid or pmmode
is NULL
.
nvmlDeviceID
is definitely valid because I am able to query its properties which match with my GPU. But I don't see why I should set the value of pmmode
to anything, because the documentation says that it is a Reference in which to return the current power management mode
. For the record, I tried assigning an enable value to it, but the result was still the same.
I am clearly doing something wrong because other users of the system have written their own libraries using this function, and they face no problem. I am unable to contact them. What should I fix to get this function to work correctly?