Skip to content

Commit

Permalink
Add internal method to get device handle
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Lezar <elezar@nvidia.com>
  • Loading branch information
elezar committed May 8, 2024
1 parent f41271c commit c4f6455
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 7 additions & 4 deletions gen/nvml/generateapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type GeneratableInterfacePoperties struct {
Type string
Interface string
Exclude []string
IncludePrivate []string
PackageMethodsAliasedFrom string
}

Expand All @@ -47,8 +48,9 @@ var GeneratableInterfaces = []GeneratableInterfacePoperties{
PackageMethodsAliasedFrom: "libnvml",
},
{
Type: "nvmlDevice",
Interface: "Device",
Type: "nvmlDevice",
Interface: "Device",
IncludePrivate: []string{"nvmlDeviceHandle"},
},
{
Type: "nvmlGpuInstance",
Expand Down Expand Up @@ -340,8 +342,9 @@ func extractMethods(sourceFile string, sourceContent []byte, input GeneratableIn
continue
}

// Ignore non-public methods
if !isPublic(funcDecl.Name.Name) {
// Ignore non-public methods unless these are forced.
forced := slices.Contains(input.Include, funcDecl.Name.Name)
if !forced && !isPublic(funcDecl.Name.Name) {
continue
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/nvml/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
"unsafe"
)

// nvmlDeviceHandle provides an explicit function to return the underlying nvmlDevice handle.
func (d nvmlDevice) nvmlDeviceHandle() *nvmlDevice {
return &d
}

// EccBitType
type EccBitType = MemoryErrorType

Expand Down Expand Up @@ -219,8 +224,13 @@ func (l *library) DeviceGetTopologyCommonAncestor(device1 Device, device2 Device
}

func (device1 nvmlDevice) GetTopologyCommonAncestor(device2 Device) (GpuTopologyLevel, Return) {
other := device2.nvmlDeviceHandle()
if other == nil {
return 0, ERROR_INVALID_ARGUMENT
}

var pathInfo GpuTopologyLevel
ret := nvmlDeviceGetTopologyCommonAncestor(device1, device2.(nvmlDevice), &pathInfo)
ret := nvmlDeviceGetTopologyCommonAncestor(device1, other, &pathInfo)

Check failure on line 233 in pkg/nvml/device.go

View workflow job for this annotation

GitHub Actions / build

cannot use other (variable of type *nvmlDevice) as nvmlDevice value in argument to nvmlDeviceGetTopologyCommonAncestor
return pathInfo, ret
}

Expand Down
1 change: 1 addition & 0 deletions pkg/nvml/zz_generated.api.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ type Device interface {
SetVirtualizationMode(GpuVirtualizationMode) Return
ValidateInforom() Return
VgpuTypeGetMaxInstances(VgpuTypeId) (int, Return)
nvmlDeviceHandle() *nvmlDevice
}

// GpuInstance represents the interface for the nvmlGpuInstance type.
Expand Down

0 comments on commit c4f6455

Please sign in to comment.