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 3 commits 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.

Copy link
Member

@elezar elezar Oct 15, 2024

Choose a reason for hiding this comment

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

I have looked at this a bit. What about doing something like we do for the Interface type where we have the function:

Extensions() ExtendedInterface

We could to the same for VgpuTypeId:

//go:generate moq -rm -out mock/extendedvgputypeid.go -pkg mock . ExtendedVgpuTypeId:ExtendedVgpuTypeId
type ExtendedVgpuTypeId interface {
       ID() uint32
}

I've pushed two commits with a proposal on top. Let me know what you think.

Copy link
Author

Choose a reason for hiding this comment

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

Looks good to me! Thanks for looking into this.

@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

@@ -668,6 +667,7 @@ type Interface interface {
VgpuTypeGetName(VgpuTypeId) (string, Return)
VgpuTypeGetNumDisplayHeads(VgpuTypeId) (int, Return)
VgpuTypeGetResolution(VgpuTypeId, int) (uint32, uint32, Return)
Extensions() ExtendedInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Why / how did this get generated at the bottom? The generation code sorts the functions alphabetically ...


package nvml

func (vgpuTypeId *nvmlVgpuTypeId) Extensions() ExtendedVgpuTypeId {
Copy link
Author

Choose a reason for hiding this comment

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

I think vgpuTypeId doesn't have to be a pointer receiver.

}

// ID returns the numeric representaion of the vgpuTypeId.
func (vgpuTypeId *nvmlVgpuTypeId) ID() uint32 {
Copy link
Author

Choose a reason for hiding this comment

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

I think vgpuTypeId doesn't have to be a pointer receiver.

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.

3 participants