Skip to content

Commit 2f087e9

Browse files
authored
Merge pull request #55 from klueska/update-go-nvml
Update to incorporate go-nvml updates to expose interface types
2 parents 76371de + f821741 commit 2f087e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+29378
-6919
lines changed

cmd/nvidia-mig-parted/apply/apply.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"github.com/sirupsen/logrus"
2525
cli "github.com/urfave/cli/v2"
2626

27+
"github.com/NVIDIA/go-nvml/pkg/nvml"
28+
2729
hooks "github.com/NVIDIA/mig-parted/api/hooks/v1"
2830
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/assert"
29-
"github.com/NVIDIA/mig-parted/internal/nvml"
3031

3132
"sigs.k8s.io/yaml"
3233
)

cmd/nvidia-mig-parted/assert/assert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import (
2525
"github.com/sirupsen/logrus"
2626
cli "github.com/urfave/cli/v2"
2727

28+
"github.com/NVIDIA/go-nvml/pkg/nvml"
29+
2830
v1 "github.com/NVIDIA/mig-parted/api/spec/v1"
2931
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/util"
30-
"github.com/NVIDIA/mig-parted/internal/nvml"
3132
"github.com/NVIDIA/mig-parted/pkg/types"
3233

3334
"sigs.k8s.io/yaml"

cmd/nvidia-mig-parted/checkpoint/checkpoint.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import (
2525
"github.com/sirupsen/logrus"
2626
cli "github.com/urfave/cli/v2"
2727

28+
"github.com/NVIDIA/go-nvml/pkg/nvml"
29+
2830
checkpoint "github.com/NVIDIA/mig-parted/api/checkpoint/v1"
2931
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/util"
30-
"github.com/NVIDIA/mig-parted/internal/nvml"
3132
"github.com/NVIDIA/mig-parted/pkg/mig/state"
3233
)
3334

cmd/nvidia-mig-parted/export/export.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import (
2525
"github.com/sirupsen/logrus"
2626
cli "github.com/urfave/cli/v2"
2727

28+
"github.com/NVIDIA/go-nvml/pkg/nvml"
29+
2830
v1 "github.com/NVIDIA/mig-parted/api/spec/v1"
29-
"github.com/NVIDIA/mig-parted/internal/nvml"
3031

3132
yaml "gopkg.in/yaml.v2"
3233
)

cmd/nvidia-mig-parted/util/device.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"os/exec"
2222
"strings"
2323

24-
"github.com/NVIDIA/mig-parted/internal/nvml"
25-
"github.com/NVIDIA/mig-parted/pkg/types"
26-
2724
"github.com/NVIDIA/go-nvlib/pkg/nvpci"
25+
"github.com/NVIDIA/go-nvml/pkg/nvml"
26+
27+
"github.com/NVIDIA/mig-parted/pkg/types"
2828
)
2929

3030
func GetGPUDeviceIDs() ([]types.DeviceID, error) {
@@ -87,7 +87,7 @@ func nvmlGetGPUDeviceIDs() ([]types.DeviceID, error) {
8787
var ids []types.DeviceID
8888
err = pciVisitGPUs(func(gpu *nvpci.NvidiaPCIDevice) error {
8989
_, ret := nvmlLib.DeviceGetHandleByPciBusId(gpu.Address)
90-
if ret.Value() != nvml.SUCCESS {
90+
if ret != nvml.SUCCESS {
9191
return nil
9292
}
9393

@@ -126,7 +126,7 @@ func nvmlGetGPUPciBusIds() ([]string, error) {
126126
}
127127

128128
_, ret := nvmlLib.DeviceGetHandleByPciBusId(gpu.Address)
129-
if ret.Value() != nvml.SUCCESS {
129+
if ret != nvml.SUCCESS {
130130
return nil
131131
}
132132

cmd/nvidia-mig-parted/util/nvml.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
log "github.com/sirupsen/logrus"
2626

27-
"github.com/NVIDIA/mig-parted/internal/nvml"
27+
"github.com/NVIDIA/go-nvml/pkg/nvml"
2828
)
2929

3030
const (
@@ -49,18 +49,18 @@ func IsNVMLVersionSupported() (bool, error) {
4949
nvmlLib := nvml.New()
5050

5151
ret := nvmlLib.Init()
52-
if ret.Value() != nvml.SUCCESS {
52+
if ret != nvml.SUCCESS {
5353
return false, fmt.Errorf("error initializing NVML: %v", ret)
5454
}
5555
defer func() {
5656
ret := nvmlLib.Shutdown()
57-
if ret.Value() != nvml.SUCCESS {
57+
if ret != nvml.SUCCESS {
5858
log.Warnf("error shutting down NVML: %v", ret)
5959
}
6060
}()
6161

6262
sversion, ret := nvmlLib.SystemGetNVMLVersion()
63-
if ret.Value() != nvml.SUCCESS {
63+
if ret != nvml.SUCCESS {
6464
return false, fmt.Errorf("error getting getting version: %v", ret)
6565
}
6666

@@ -86,7 +86,7 @@ func NvmlInit(nvmlLib nvml.Interface) error {
8686
nvmlLib = nvml.New()
8787
}
8888
ret := nvmlLib.Init()
89-
if ret.Value() != nvml.SUCCESS {
89+
if ret != nvml.SUCCESS {
9090
return ret
9191
}
9292
return nil
@@ -97,7 +97,7 @@ func TryNvmlShutdown(nvmlLib nvml.Interface) {
9797
nvmlLib = nvml.New()
9898
}
9999
ret := nvmlLib.Shutdown()
100-
if ret.Value() != nvml.SUCCESS {
100+
if ret != nvml.SUCCESS {
101101
log.Warnf("error shutting down NVML: %v", ret)
102102
}
103103
}

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ go 1.21
55
toolchain go1.22.2
66

77
require (
8-
github.com/NVIDIA/go-nvlib v0.2.0
9-
github.com/NVIDIA/go-nvml v0.12.0-3
10-
github.com/google/uuid v1.6.0
8+
github.com/NVIDIA/go-nvlib v0.3.0
9+
github.com/NVIDIA/go-nvml v0.12.0-5
1110
github.com/sirupsen/logrus v1.9.3
1211
github.com/stretchr/testify v1.9.0
1312
github.com/urfave/cli/v2 v2.27.1
@@ -31,6 +30,7 @@ require (
3130
github.com/google/gnostic-models v0.6.8 // indirect
3231
github.com/google/go-cmp v0.6.0 // indirect
3332
github.com/google/gofuzz v1.2.0 // indirect
33+
github.com/google/uuid v1.6.0 // indirect
3434
github.com/imdario/mergo v0.3.6 // indirect
3535
github.com/josharian/intern v1.0.0 // indirect
3636
github.com/json-iterator/go v1.1.12 // indirect

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
github.com/NVIDIA/go-nvlib v0.2.0 h1:roq+SDstbP1fcy2XVH7wB2Gz2/Ud7Q+NGQYOcVITVrA=
2-
github.com/NVIDIA/go-nvlib v0.2.0/go.mod h1:kFuLNTyD1tF6FbRFlk+/EdUW5BrkE+v1Y3A3/9zKSjA=
3-
github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE=
4-
github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA=
1+
github.com/NVIDIA/go-nvlib v0.3.0 h1:vd7jSOthJTqzqIWZrv317xDr1+Mnjoy5X4N69W9YwQM=
2+
github.com/NVIDIA/go-nvlib v0.3.0/go.mod h1:NasUuId9hYFvwzuOHCu9F2X6oTU2tG0JHTfbJYuDAbA=
3+
github.com/NVIDIA/go-nvml v0.12.0-5 h1:4DYsngBqJEAEj+/RFmBZ43Q3ymoR3tyS0oBuJk12Fag=
4+
github.com/NVIDIA/go-nvml v0.12.0-5/go.mod h1:8Llmj+1Rr+9VGGwZuRer5N/aCjxGuR5nPb/9ebBiIEQ=
55
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
66
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
77
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=

internal/nvlib/mig/mig.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package mig
1919
import (
2020
"fmt"
2121

22-
"github.com/NVIDIA/mig-parted/internal/nvml"
22+
"github.com/NVIDIA/go-nvml/pkg/nvml"
2323
)
2424

2525
type Interface struct {
@@ -52,10 +52,10 @@ func (i Interface) GpuInstance(gi nvml.GpuInstance) GpuInstance {
5252

5353
func (device Device) AssertMigEnabled() error {
5454
mode, _, ret := device.GetMigMode()
55-
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
55+
if ret == nvml.ERROR_NOT_SUPPORTED {
5656
return fmt.Errorf("MIG not supported")
5757
}
58-
if ret.Value() != nvml.SUCCESS {
58+
if ret != nvml.SUCCESS {
5959
return fmt.Errorf("error getting MIG mode: %v", ret)
6060
}
6161
if mode != nvml.DEVICE_MIG_ENABLE {
@@ -67,18 +67,18 @@ func (device Device) AssertMigEnabled() error {
6767
func (device Device) WalkGpuInstances(f func(nvml.GpuInstance, int, nvml.GpuInstanceProfileInfo) error) error {
6868
for i := 0; i < nvml.GPU_INSTANCE_PROFILE_COUNT; i++ {
6969
giProfileInfo, ret := device.GetGpuInstanceProfileInfo(i)
70-
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
70+
if ret == nvml.ERROR_NOT_SUPPORTED {
7171
continue
7272
}
73-
if ret.Value() == nvml.ERROR_INVALID_ARGUMENT {
73+
if ret == nvml.ERROR_INVALID_ARGUMENT {
7474
continue
7575
}
76-
if ret.Value() != nvml.SUCCESS {
76+
if ret != nvml.SUCCESS {
7777
return fmt.Errorf("error getting GPU instance profile info for '%v': %v", i, ret)
7878
}
7979

8080
gis, ret := device.GetGpuInstances(&giProfileInfo)
81-
if ret.Value() != nvml.SUCCESS {
81+
if ret != nvml.SUCCESS {
8282
return fmt.Errorf("error getting GPU instances for profile '%v': %v", i, ret)
8383
}
8484

@@ -96,18 +96,18 @@ func (gi GpuInstance) WalkComputeInstances(f func(ci nvml.ComputeInstance, ciPro
9696
for j := 0; j < nvml.COMPUTE_INSTANCE_PROFILE_COUNT; j++ {
9797
for k := 0; k < nvml.COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT; k++ {
9898
ciProfileInfo, ret := gi.GetComputeInstanceProfileInfo(j, k)
99-
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
99+
if ret == nvml.ERROR_NOT_SUPPORTED {
100100
continue
101101
}
102-
if ret.Value() == nvml.ERROR_INVALID_ARGUMENT {
102+
if ret == nvml.ERROR_INVALID_ARGUMENT {
103103
continue
104104
}
105-
if ret.Value() != nvml.SUCCESS {
105+
if ret != nvml.SUCCESS {
106106
return fmt.Errorf("error getting Compute instance profile info for '(%v, %v)': %v", j, k, ret)
107107
}
108108

109109
cis, ret := gi.GetComputeInstances(&ciProfileInfo)
110-
if ret.Value() != nvml.SUCCESS {
110+
if ret != nvml.SUCCESS {
111111
return fmt.Errorf("error getting Compute instances for profile '(%v, %v)': %v", j, k, ret)
112112
}
113113

internal/nvlib/nvlib.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
package nvlib
1818

1919
import (
20+
"github.com/NVIDIA/go-nvml/pkg/nvml"
21+
2022
"github.com/NVIDIA/mig-parted/internal/nvlib/mig"
21-
"github.com/NVIDIA/mig-parted/internal/nvml"
2223
)
2324

2425
type Interface struct {

internal/nvml/consts.go

-85
This file was deleted.

0 commit comments

Comments
 (0)