NVIDIA / go-nvml

Go Bindings for the NVIDIA Management Library (NVML)
Apache License 2.0
310 stars 63 forks source link

Add VgpuTypeIDToUint32 helper function #129

Open PiotrProkop opened 2 months ago

PiotrProkop commented 2 months ago

This PR adds new VgpuTypeIdToUint32 helper function that allows to retrieve underlying uint32 representation of nvmlVgpuTypeId:

type nvmlVgpuTypeId uint32

this makes it easier to programmatically create vgpus , for example:

echo $(uuidgen) > /sys/bus/pci/devices/0000\:06\:00.0/mdev_supported_types/nvidia-<typeID>/create

where <typeID> is this underlying uint32.

In previous versions of go-nvml I could just do type conversion to uint32 directly as device.GetSupportedVgpus() was returning:

type VgpuTypeId uint32

instead of Interface.

PiotrProkop commented 1 month ago

@klueska did you had a chance to take a look at it? nvidia-smi also provide vgpu type id as hex value, sample output from nvidia-smi vgpu -v -c

    vGPU Type ID                          : 0x402
        Name                              : NVIDIA GeForce GTX 1060
        Class                             : Geforce
        GPU Instance Profile ID           : N/A
        Max Instances                     : 2
        Max Instances Per VM              : 1
        Multi vGPU Exclusive              : False
        vGPU Exclusive Type               : False
        vGPU Exclusive Size               : False
        Device ID                         : 0x1e3710de
        Sub System ID                     : 0x1e37180d
        FB Memory                         : 8192 MiB
        BAR1 size                         : 256 MB
        Display Heads                     : 1
        Maximum X Resolution              : 7680
        Maximum Y Resolution              : 4320
        Frame Rate Limit                  : N/A
        Placement Size                    : N/A
        Creatable Placement IDs           : N/A
        GRID License                      : GRID-vGaming,8.0

where x402 is 1026 in decimal and you can use it to create vgpus on the host by running:

echo $(uuidgen) > /sys/bus/pci/devices/<gpu_pci>/mdev_supported_types/nvidia-1026/create