-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: PiotrProkop <[email protected]>
005170c
to
4871684
Compare
There was a problem hiding this 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.
pkg/nvml/cgo_helpers_static.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@klueska did you had a chance to take a look at it?
where
|
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
b240786
to
615aa61
Compare
@@ -668,6 +667,7 @@ type Interface interface { | |||
VgpuTypeGetName(VgpuTypeId) (string, Return) | |||
VgpuTypeGetNumDisplayHeads(VgpuTypeId) (int, Return) | |||
VgpuTypeGetResolution(VgpuTypeId, int) (uint32, uint32, Return) | |||
Extensions() ExtendedInterface |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
This PR adds new
VgpuTypeIdToUint32
helper function that allows to retrieve underlyinguint32
representation ofnvmlVgpuTypeId
:this makes it easier to programmatically create vgpus , for example:
where
<typeID>
is this underlyinguint32
.In previous versions of
go-nvml
I could just do type conversion touint32
directly asdevice.GetSupportedVgpus()
was returning:instead of Interface.