vGPU Utilization and Accounting#

This chapter describes operations that are associated with vGPU Utilization and Accounting.

Functions#

nvmlReturn_t nvmlDeviceGetVgpuInstancesUtilizationInfo(nvmlDevice_t device, nvmlVgpuInstancesUtilizationInfo_t *vgpuUtilInfo)

Retrieves recent utilization for vGPU instances running on a physical GPU (device).

nvmlReturn_t nvmlDeviceGetVgpuProcessUtilization(nvmlDevice_t device, unsigned long long lastSeenTimeStamp, unsigned int *vgpuProcessSamplesCount, nvmlVgpuProcessUtilizationSample_t *utilizationSamples)

Retrieves current utilization for processes running on vGPUs on a physical GPU (device).

nvmlReturn_t nvmlDeviceGetVgpuProcessesUtilizationInfo(nvmlDevice_t device, nvmlVgpuProcessesUtilizationInfo_t *vgpuProcUtilInfo)

Retrieves recent utilization for processes running on vGPU instances on a physical GPU (device).

nvmlReturn_t nvmlDeviceGetVgpuUtilization(nvmlDevice_t device, unsigned long long lastSeenTimeStamp, nvmlValueType_t *sampleValType, unsigned int *vgpuInstanceSamplesCount, nvmlVgpuInstanceUtilizationSample_t *utilizationSamples)

Retrieves current utilization for vGPUs on a physical GPU (device).

nvmlReturn_t nvmlVgpuInstanceClearAccountingPids(nvmlVgpuInstance_t vgpuInstance)

Clears accounting information of the vGPU instance that have already terminated.

nvmlReturn_t nvmlVgpuInstanceGetAccountingMode(nvmlVgpuInstance_t vgpuInstance, nvmlEnableState_t *mode)

Queries the state of per process accounting mode on vGPU.

nvmlReturn_t nvmlVgpuInstanceGetAccountingPids(nvmlVgpuInstance_t vgpuInstance, unsigned int *count, unsigned int *pids)

Queries list of processes running on vGPU that can be queried for accounting stats.

nvmlReturn_t nvmlVgpuInstanceGetAccountingStats(nvmlVgpuInstance_t vgpuInstance, unsigned int pid, nvmlAccountingStats_t *stats)

Queries process's accounting stats.

nvmlReturn_t nvmlVgpuInstanceGetLicenseInfo_v2(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuLicenseInfo_t *licenseInfo)

Query the license information of the vGPU instance.

Functions#

nvmlReturn_t nvmlDeviceGetVgpuInstancesUtilizationInfo(
nvmlDevice_t device,
nvmlVgpuInstancesUtilizationInfo_t *vgpuUtilInfo,
)#

Retrieves recent utilization for vGPU instances running on a physical GPU (device).

For Kepler or newer fully supported devices.

Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, video decoder, jpeg decoder, and OFA for vGPU instances running on a device. Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at by vgpuUtilInfo->vgpuUtilArray. One utilization sample structure is returned per vGPU instance, and includes the CPU timestamp at which the samples were recorded. Individual utilization values are returned as “unsigned int” values in nvmlValue_t unions. The function sets the caller-supplied vgpuUtilInfo->sampleValType to NVML_VALUE_TYPE_UNSIGNED_INT to indicate the returned value type.

To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with vgpuUtilInfo->vgpuUtilArray set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current vGPU instance count in vgpuUtilInfo->vgpuInstanceCount, or NVML_SUCCESS if the current vGPU instance count is zero. The caller should allocate a buffer of size vgpuUtilInfo->vgpuInstanceCount * sizeof(nvmlVgpuInstanceUtilizationInfo_t). Invoke the function again with the allocated buffer passed in vgpuUtilInfo->vgpuUtilArray, and vgpuUtilInfo->vgpuInstanceCount set to the number of entries the buffer is sized for.

On successful return, the function updates vgpuUtilInfo->vgpuInstanceCount with the number of vGPU utilization sample structures that were actually written. This may differ from a previously read value as vGPU instances are created or destroyed.

vgpuUtilInfo->lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 to read utilization based on all the samples maintained by the driver’s internal sample buffer. Set vgpuUtilInfo->lastSeenTimeStamp to a timeStamp retrieved from a previous query to read utilization since the previous query.

Parameters:
  • device – The identifier for the target device

  • vgpuUtilInfo – Pointer to the caller-provided structure of nvmlVgpuInstancesUtilizationInfo_t

Returns:

nvmlReturn_t nvmlDeviceGetVgpuProcessUtilization(
nvmlDevice_t device,
unsigned long long lastSeenTimeStamp,
unsigned int *vgpuProcessSamplesCount,
nvmlVgpuProcessUtilizationSample_t *utilizationSamples,
)#

Retrieves current utilization for processes running on vGPUs on a physical GPU (device).

For Maxwell or newer fully supported devices.

Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for processes running on vGPU instances active on a device. Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at by utilizationSamples. One utilization sample structure is returned per process running on vGPU instances, that had some non-zero utilization during the last sample period. It includes the CPU timestamp at which the samples were recorded. Individual utilization values are returned as “unsigned int” values.

To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with utilizationSamples set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current vGPU instance count in vgpuProcessSamplesCount. The caller should allocate a buffer of size vgpuProcessSamplesCount * sizeof(nvmlVgpuProcessUtilizationSample_t). Invoke the function again with the allocated buffer passed in utilizationSamples, and vgpuProcessSamplesCount set to the number of entries the buffer is sized for.

On successful return, the function updates vgpuSubProcessSampleCount with the number of vGPU sub process utilization sample structures that were actually written. This may differ from a previously read value depending on the number of processes that are active in any given sample period.

lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 to read utilization based on all the samples maintained by the driver’s internal sample buffer. Set lastSeenTimeStamp to a timeStamp retrieved from a previous query to read utilization since the previous query.

Parameters:
  • device – The identifier for the target device

  • lastSeenTimeStamp – Return only samples with timestamp greater than lastSeenTimeStamp.

  • vgpuProcessSamplesCount – Pointer to caller-supplied array size, and returns number of processes running on vGPU instances

  • utilizationSamples – Pointer to caller-supplied buffer in which vGPU sub process utilization samples are returned

Returns:

nvmlReturn_t nvmlDeviceGetVgpuProcessesUtilizationInfo(
nvmlDevice_t device,
nvmlVgpuProcessesUtilizationInfo_t *vgpuProcUtilInfo,
)#

Retrieves recent utilization for processes running on vGPU instances on a physical GPU (device).

For Maxwell or newer fully supported devices.

Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, video decoder, jpeg decoder, and OFA for processes running on vGPU instances active on a device. Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at by vgpuProcUtilInfo->vgpuProcUtilArray. One utilization sample structure is returned per process running on vGPU instances, that had some non-zero utilization during the last sample period. It includes the CPU timestamp at which the samples were recorded. Individual utilization values are returned as “unsigned int” values.

To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with vgpuProcUtilInfo->vgpuProcUtilArray set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current processes’ count running on vGPU instances in vgpuProcUtilInfo->vgpuProcessCount. The caller should allocate a buffer of size vgpuProcUtilInfo->vgpuProcessCount * sizeof(nvmlVgpuProcessUtilizationSample_t). Invoke the function again with the allocated buffer passed in vgpuProcUtilInfo->vgpuProcUtilArray, and vgpuProcUtilInfo->vgpuProcessCount set to the number of entries the buffer is sized for.

On successful return, the function updates vgpuProcUtilInfo->vgpuProcessCount with the number of vGPU sub process utilization sample structures that were actually written. This may differ from a previously read value depending on the number of processes that are active in any given sample period.

vgpuProcUtilInfo->lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 to read utilization based on all the samples maintained by the driver’s internal sample buffer. Set vgpuProcUtilInfo->lastSeenTimeStamp to a timeStamp retrieved from a previous query to read utilization since the previous query.

Parameters:
  • device – The identifier for the target device

  • vgpuProcUtilInfo – Pointer to the caller-provided structure of nvmlVgpuProcessesUtilizationInfo_t

Returns:

nvmlReturn_t nvmlDeviceGetVgpuUtilization(
nvmlDevice_t device,
unsigned long long lastSeenTimeStamp,
nvmlValueType_t *sampleValType,
unsigned int *vgpuInstanceSamplesCount,
nvmlVgpuInstanceUtilizationSample_t *utilizationSamples,
)#

Retrieves current utilization for vGPUs on a physical GPU (device).

For Kepler or newer fully supported devices.

Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for vGPU instances running on a device. Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at by utilizationSamples. One utilization sample structure is returned per vGPU instance, and includes the CPU timestamp at which the samples were recorded. Individual utilization values are returned as “unsigned int” values in nvmlValue_t unions. The function sets the caller-supplied sampleValType to NVML_VALUE_TYPE_UNSIGNED_INT to indicate the returned value type.

To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with utilizationSamples set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current vGPU instance count in vgpuInstanceSamplesCount, or NVML_SUCCESS if the current vGPU instance count is zero. The caller should allocate a buffer of size vgpuInstanceSamplesCount * sizeof(nvmlVgpuInstanceUtilizationSample_t). Invoke the function again with the allocated buffer passed in utilizationSamples, and vgpuInstanceSamplesCount set to the number of entries the buffer is sized for.

On successful return, the function updates vgpuInstanceSampleCount with the number of vGPU utilization sample structures that were actually written. This may differ from a previously read value as vGPU instances are created or destroyed.

lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 to read utilization based on all the samples maintained by the driver’s internal sample buffer. Set lastSeenTimeStamp to a timeStamp retrieved from a previous query to read utilization since the previous query.

Parameters:
  • device – The identifier for the target device

  • lastSeenTimeStamp – Return only samples with timestamp greater than lastSeenTimeStamp.

  • sampleValType – Pointer to caller-supplied buffer to hold the type of returned sample values

  • vgpuInstanceSamplesCount – Pointer to caller-supplied array size, and returns number of vGPU instances

  • utilizationSamples – Pointer to caller-supplied buffer in which vGPU utilization samples are returned

Returns:

nvmlReturn_t nvmlVgpuInstanceClearAccountingPids(
nvmlVgpuInstance_t vgpuInstance,
)#

Clears accounting information of the vGPU instance that have already terminated.

For Maxwell or newer fully supported devices. Requires root/admin permissions.

Note

Accounting Mode needs to be on. See nvmlVgpuInstanceGetAccountingMode.

Note

Only compute and graphics applications stats are reported and can be cleared since monitoring applications stats don’t contribute to GPU utilization.

Parameters:

vgpuInstance – The identifier of the target vGPU instance

Returns:

nvmlReturn_t nvmlVgpuInstanceGetAccountingMode(
nvmlVgpuInstance_t vgpuInstance,
nvmlEnableState_t *mode,
)#

Queries the state of per process accounting mode on vGPU.

For Maxwell or newer fully supported devices.

Parameters:
  • vgpuInstance – The identifier of the target vGPU instance

  • mode – Reference in which to return the current accounting mode

Returns:

nvmlReturn_t nvmlVgpuInstanceGetAccountingPids(
nvmlVgpuInstance_t vgpuInstance,
unsigned int *count,
unsigned int *pids,
)#

Queries list of processes running on vGPU that can be queried for accounting stats.

The list of processes returned can be in running or terminated state.

For Maxwell or newer fully supported devices.

To just query the maximum number of processes that can be queried, call this function with *count = 0 and pids=NULL. The return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if list is empty.

For more details see nvmlVgpuInstanceGetAccountingStats.

Note

In case of PID collision some processes might not be accessible before the circular buffer is full.

Parameters:
  • vgpuInstance – The identifier of the target vGPU instance

  • count – Reference in which to provide the pids array size, and to return the number of elements ready to be queried

  • pids – Reference in which to return list of process ids

Returns:

nvmlReturn_t nvmlVgpuInstanceGetAccountingStats(
nvmlVgpuInstance_t vgpuInstance,
unsigned int pid,
nvmlAccountingStats_t *stats,
)#

Queries process’s accounting stats.

For Maxwell or newer fully supported devices.

Accounting stats capture GPU utilization and other statistics across the lifetime of a process, and can be queried during life time of the process or after its termination. The time field in nvmlAccountingStats_t is reported as 0 during the lifetime of the process and updated to actual running time after its termination. Accounting stats are kept in a circular buffer, newly created processes overwrite information about old processes.

See nvmlAccountingStats_t for description of each returned metric. List of processes that can be queried can be retrieved from nvmlVgpuInstanceGetAccountingPids.

Note

Accounting Mode needs to be on. See nvmlVgpuInstanceGetAccountingMode.

Note

Only compute and graphics applications stats can be queried. Monitoring applications stats can’t be queried since they don’t contribute to GPU utilization.

Note

In case of pid collision stats of only the latest process (that terminated last) will be reported

Parameters:
  • vgpuInstance – The identifier of the target vGPU instance

  • pid – Process Id of the target process to query stats for

  • stats – Reference in which to return the process’s accounting stats

Returns:

nvmlReturn_t nvmlVgpuInstanceGetLicenseInfo_v2(
nvmlVgpuInstance_t vgpuInstance,
nvmlVgpuLicenseInfo_t *licenseInfo,
)#

Query the license information of the vGPU instance.

For Maxwell or newer fully supported devices.

Parameters:
  • vgpuInstance – Identifier of the target vGPU instance

  • licenseInfo – Pointer to vGPU license information structure

Returns: