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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gen/nvml/generateapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var GeneratableInterfaces = []GeneratableInterfacePoperties{
{
Type: "nvmlVgpuTypeId",
Interface: "VgpuTypeId",
Exclude: []string{"ID"},
},
}

Expand Down Expand Up @@ -239,7 +240,18 @@ func generateInterface(sourceDir string, input GeneratableInterfacePoperties) (s
return "", err
}

// We separate the methods into two sets to ensure that extensions are always included last.
var generatedMethods []*ast.FuncDecl
var extensions []*ast.FuncDecl
for _, method := range methods {
if method.Name.Name == "Extensions" {
extensions = append(extensions, method)
continue
}
generatedMethods = append(generatedMethods, method)
}

for _, method := range append(generatedMethods, extensions...) {
formatted := fmt.Sprintf("\t%s\n", formatMethodSignature(method))
signature.WriteString(formatted)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/nvml/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type ExtendedInterface interface {
LookupSymbol(string) error
}

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

// libraryOptions hold the paramaters than can be set by a LibraryOption
type libraryOptions struct {
path string
Expand Down
68 changes: 68 additions & 0 deletions pkg/nvml/mock/extendedvgputypeid.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pkg/nvml/vgpu_extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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.

return vgpuTypeId
}

// 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.

if vgpuTypeId == nil {
return 0
}
return uint32(*vgpuTypeId)
}
3 changes: 2 additions & 1 deletion pkg/nvml/zz_generated.api.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ type Interface interface {
EventSetCreate() (EventSet, Return)
EventSetFree(EventSet) Return
EventSetWait(EventSet, uint32) (EventData, Return)
Extensions() ExtendedInterface
GetExcludedDeviceCount() (int, Return)
GetExcludedDeviceInfoByIndex(int) (ExcludedDeviceInfo, Return)
GetVgpuCompatibility(*VgpuMetadata, *VgpuPgpuMetadata) (VgpuPgpuCompatibility, Return)
Expand Down Expand Up @@ -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 ...

}

// Device represents the interface for the nvmlDevice type.
Expand Down Expand Up @@ -1004,4 +1004,5 @@ type VgpuTypeId interface {
GetNumDisplayHeads() (int, Return)
GetResolution(int) (uint32, uint32, Return)
GetSupportedPlacements(Device) (VgpuPlacementList, Return)
Extensions() ExtendedVgpuTypeId
}
Loading