zero.hardware.get_gpu_info

zero.hardware.get_gpu_info(precise=False)[source]

Get statistics about GPU devices.

Includes information about memory (total, free and used) and utilization. Some figures are represented in two ways: with raw units and with percentage.

Parameters

precise (bool) – if False, all data is rounded (to Mb for memory, to % for percentages)

Returns

Information about GPU devices.

Raises

RuntimeError – if necessary cuda-related libraries are not found. Usually, it means that the function is run on a machine without GPU.

Return type

List[Dict[str, Any]]

Examples

print(get_gpu_info())

Output example (formatted for convenience):

[
    {
        'util%': 0,
        'total': 11019,
        'used': 0,
        'free': 11019,
        'used%': 0,
        'free%': 100,
    },
    {
        'util%': 0,
        'total': 11016,
        'used': 0,
        'free': 11016,
        'used%': 0,
        'free%': 100,
    },
]

Warning

The function directly collects information using the pynvml library, hence, settings like CUDA_VISIBLE_DEVICES don’t affect the result.