Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VgpuTypeIDToUint32 helper function #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PiotrProkop
Copy link

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.

Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @PiotrProkop.

It would be good to get @klueska to also take a look at this.

@@ -73,3 +73,7 @@ func unpackPCharString(str string) (*C.char, *struct{}) {
h := (*stringHeader)(unsafe.Pointer(&str))
return (*C.char)(h.Data), cgoAllocsUnknown
}

func VgpuTypeIdToUint32(typeId VgpuTypeId) uint32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there are exceptions, but in general we try to expose NVML-functionality in these bindings and this goes against that a bit.

Does your example not indicate the need for a String() function off interface instead of an explicit *ToUint32 function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got impression that interface for VgpuTypeId is auto generated based on NVML lib funcs, so I wanted to propose less intrusive option. String or uint32 both works for me. I wanted to show that newer go-nvml version is missing some info that was present in older version.

@PiotrProkop
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants