NVML Process Utilization & Encoder Capacity

Hello,
I am using the NVML tools to monitor the usage of the video encoders of Nvidia GPUs.
I am having trouble with two NVML functions:

The first one is the Function “nvmlDeviceGetProcessUtilization” which I use this way:

int nvmlReturn_t11;
*nvmlProcessUtilizationSample_t *utilizationtabl = NULL; *
unsigned int processSamplesCount = 0;
unsigned long long lastSeenTimeStamp = 0;

nvmlReturn_t11 = nvmlDeviceGetProcessUtilization(device, utilizationtabl, &processSamplesCount, lastSeenTimeStamp);

cout << "\nnvmlReturn_t11: " << nvmlReturn_t11 << “\n” << "processSamplesCount: " << processSamplesCount << “\n” << "lastSeenTimeStamp: " << lastSeenTimeStamp << endl;

I get the following results after compiling:

nvmlReturn_t11: 7
processSamplesCount: 100
lastSeenTimeStamp: 0

These results, if I am correct indicate a memory allocation issue. The thing is that I am pretty sure I followed the NVML documentation instructions on how to use this function. The result I was expecting was a “processSamplesCount” giving the amout of process treated by the GPU, and with this amount I would have been able to allocate an array of the size of this amount, containing each Utilization samples. Like that:

utilizationtabl= new nvmlProcessUtilizationSample_t[processSamplesCount];

And then another use of the function “nvmlDeviceGetProcessUtilization”:

nvmlReturn_t11 = nvmlDeviceGetProcessUtilization(device, utilizationtabl, &processSamplesCount, lastSeenTimeStamp);

I managed to make the function work by allocating a fixed array size to “utilizationtabl” but it is not an optimized way to do it:

int nvmlReturn_t11;
nvmlProcessUtilizationSample_t utilizationtabl[500];
unsigned int processSamplesCount = 500;
unsigned long long lastSeenTimeStamp = 0;

nvmlReturn_t11 = nvmlDeviceGetProcessUtilization(device, utilizationtabl, &processSamplesCount, lastSeenTimeStamp);

cout << "\nnvmlReturn_t11: " << nvmlReturn_t11 << “\n” << "processSamplesCount: " << processSamplesCount << “\n” << "lastSeenTimeStamp: " << lastSeenTimeStamp << endl;

for (int i =0;i< processSamplesCount;i++)
{
cout << "\ndecUtil: " << utilizationtabl[i].decUtil << "\nencUtil: " << utilizationtabl[i].encUtil << "\nmemUtil: " <<
utilizationtabl[i].memUtil << "\nsmUtil: " << utilizationtabl[i].smUtil << "\ntimeStamp: " <<
utilizationtabl[i].timeStamp << endl;
}

With the following results after compiling. They seem to be correct and match my expectations, the last block of info corresponding to an encoding using the Nvidia encoder:

nvmlReturn_t11: 0
processSamplesCount: 4
lastSeenTimeStamp: 0

decUtil: 0
encUtil: 0
memUtil: 0
smUtil: 0
timeStamp: 1602881978048786

decUtil: 0
encUtil: 0
memUtil: 0
smUtil: 0
timeStamp: 1602881964439529

decUtil: 0
encUtil: 0
memUtil: 0
smUtil: 0
timeStamp: 1602881981189537

decUtil: 0
encUtil: 48
memUtil: 4
smUtil: 9
timeStamp: 1602881981189537

Second issue:
For the same purpose, I am using the function “nvmlDeviceGetEncoderCapacity” this way:

int nvmlReturn_t5;
int nvmlReturn_t6;
unsigned int encoderCapacityh264 = 0;
unsigned int encoderCapacityh265 = 0;

nvmlReturn_t5 = nvmlDeviceGetEncoderCapacity(device, NVML_ENCODER_QUERY_H264, &encoderCapacityh264);
nvmlReturn_t6 = nvmlDeviceGetEncoderCapacity(device, NVML_ENCODER_QUERY_HEVC, &encoderCapacityh265);
cout << "nvmlReturn_t5: " << nvmlReturn_t5 << “\n” << "encoderCapacityh264 " << encoderCapacityh264 << “\n” << "nvmlReturn_t6: " << nvmlReturn_t6 << “\n” << "encoderCapacityh265 " << encoderCapacityh265 << std::endl;

The variables “encoderCapacityh264” and “encoderCapacityh265” are supposed to give as a result the current capacity the encoder concerned have left.
I get the following results:

nvmlReturn_t5: 0
encoderCapacityh264 100
nvmlReturn_t6: 0
encoderCapacityh265 100

These results mean that there is no error, and that neither of these two encoders are used (they have 100% of their capacity left). Of course, I am having the issue while encoding, the same way I did with the previous function, which was properly showing that the encoders were used.

For information, to use the encoders of the Nvidia GPUs I am simply using the following ffmpeg command:

ffmpeg -i input.mp4 -an -c:v hevc_nvenc test.mp4

And my Graphic card is a Nvidia GeForce GTX 1070.

Thanking you in advance,
Nicolas Proy.