Skip to content

Commit

Permalink
Update to incorporate go-nvml updates to expose interface types
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Apr 12, 2024
1 parent 60ec0c0 commit 8d39bd7
Show file tree
Hide file tree
Showing 76 changed files with 29,089 additions and 6,914 deletions.
2 changes: 1 addition & 1 deletion cmd/nvidia-mig-parted/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

hooks "github.com/NVIDIA/mig-parted/api/hooks/v1"
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/assert"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"

"sigs.k8s.io/yaml"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/nvidia-mig-parted/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

Check failure on line 27 in cmd/nvidia-mig-parted/assert/assert.go

View workflow job for this annotation

GitHub Actions / check

File is not `gofmt`-ed with `-s` (gofmt)
v1 "github.com/NVIDIA/mig-parted/api/spec/v1"
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/util"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/mig-parted/pkg/types"

"sigs.k8s.io/yaml"
Expand Down
2 changes: 1 addition & 1 deletion cmd/nvidia-mig-parted/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

checkpoint "github.com/NVIDIA/mig-parted/api/checkpoint/v1"
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/util"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/mig-parted/pkg/mig/state"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/nvidia-mig-parted/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
cli "github.com/urfave/cli/v2"

v1 "github.com/NVIDIA/mig-parted/api/spec/v1"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"

Check failure on line 30 in cmd/nvidia-mig-parted/export/export.go

View workflow job for this annotation

GitHub Actions / check

File is not `goimports`-ed with -local github.com/NVIDIA/mig-parted (goimports)
yaml "gopkg.in/yaml.v2"
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/nvidia-mig-parted/util/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os/exec"
"strings"

"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"

Check failure on line 24 in cmd/nvidia-mig-parted/util/device.go

View workflow job for this annotation

GitHub Actions / check

File is not `goimports`-ed with -local github.com/NVIDIA/mig-parted (goimports)
"github.com/NVIDIA/mig-parted/pkg/types"

"github.com/NVIDIA/go-nvlib/pkg/nvpci"
Expand Down Expand Up @@ -87,7 +87,7 @@ func nvmlGetGPUDeviceIDs() ([]types.DeviceID, error) {
var ids []types.DeviceID
err = pciVisitGPUs(func(gpu *nvpci.NvidiaPCIDevice) error {
_, ret := nvmlLib.DeviceGetHandleByPciBusId(gpu.Address)
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return nil
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func nvmlGetGPUPciBusIds() ([]string, error) {
}

_, ret := nvmlLib.DeviceGetHandleByPciBusId(gpu.Address)
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/nvidia-mig-parted/util/nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

log "github.com/sirupsen/logrus"

"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)

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

ret := nvmlLib.Init()
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return false, fmt.Errorf("error initializing NVML: %v", ret)
}
defer func() {
ret := nvmlLib.Shutdown()
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
log.Warnf("error shutting down NVML: %v", ret)
}
}()

sversion, ret := nvmlLib.SystemGetNVMLVersion()
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return false, fmt.Errorf("error getting getting version: %v", ret)
}

Expand All @@ -86,7 +86,7 @@ func NvmlInit(nvmlLib nvml.Interface) error {
nvmlLib = nvml.New()
}
ret := nvmlLib.Init()
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return ret
}
return nil
Expand All @@ -97,7 +97,7 @@ func TryNvmlShutdown(nvmlLib nvml.Interface) {
nvmlLib = nvml.New()
}
ret := nvmlLib.Shutdown()
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
log.Warnf("error shutting down NVML: %v", ret)
}
}
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module github.com/NVIDIA/mig-parted

go 1.20
go 1.21

toolchain go1.22.1

replace github.com/NVIDIA/go-nvlib => github.com/klueska/go-nvlib v0.0.0-20240412211930-153699bb9310

require (
github.com/NVIDIA/go-nvlib v0.2.0
github.com/NVIDIA/go-nvml v0.12.0-3
github.com/google/uuid v1.6.0
github.com/NVIDIA/go-nvml v0.12.0-4
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.1
Expand All @@ -29,6 +32,7 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
15 changes: 11 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/NVIDIA/go-nvlib v0.2.0 h1:roq+SDstbP1fcy2XVH7wB2Gz2/Ud7Q+NGQYOcVITVrA=
github.com/NVIDIA/go-nvlib v0.2.0/go.mod h1:kFuLNTyD1tF6FbRFlk+/EdUW5BrkE+v1Y3A3/9zKSjA=
github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE=
github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA=
github.com/NVIDIA/go-nvml v0.12.0-4 h1:BvPjnjJr6qje0zov57Md7TwEA8i/12kZeUQIpyWzTEE=
github.com/NVIDIA/go-nvml v0.12.0-4/go.mod h1:8Llmj+1Rr+9VGGwZuRer5N/aCjxGuR5nPb/9ebBiIEQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand All @@ -19,6 +17,7 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -33,6 +32,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
Expand All @@ -43,8 +43,11 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klueska/go-nvlib v0.0.0-20240412211930-153699bb9310 h1:wQJmRXCO75TlHrcPkKZXPrD1wyjBYneTTiH8qXE5KsI=
github.com/klueska/go-nvlib v0.0.0-20240412211930-153699bb9310/go.mod h1:NasUuId9hYFvwzuOHCu9F2X6oTU2tG0JHTfbJYuDAbA=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -59,10 +62,13 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
Expand Down Expand Up @@ -122,6 +128,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
22 changes: 11 additions & 11 deletions internal/nvlib/mig/mig.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package mig
import (
"fmt"

"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)

type Interface struct {
Expand Down Expand Up @@ -52,10 +52,10 @@ func (i Interface) GpuInstance(gi nvml.GpuInstance) GpuInstance {

func (device Device) AssertMigEnabled() error {
mode, _, ret := device.GetMigMode()
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
if ret == nvml.ERROR_NOT_SUPPORTED {
return fmt.Errorf("MIG not supported")
}
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return fmt.Errorf("error getting MIG mode: %v", ret)
}
if mode != nvml.DEVICE_MIG_ENABLE {
Expand All @@ -67,18 +67,18 @@ func (device Device) AssertMigEnabled() error {
func (device Device) WalkGpuInstances(f func(nvml.GpuInstance, int, nvml.GpuInstanceProfileInfo) error) error {
for i := 0; i < nvml.GPU_INSTANCE_PROFILE_COUNT; i++ {
giProfileInfo, ret := device.GetGpuInstanceProfileInfo(i)
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
if ret == nvml.ERROR_NOT_SUPPORTED {
continue
}
if ret.Value() == nvml.ERROR_INVALID_ARGUMENT {
if ret == nvml.ERROR_INVALID_ARGUMENT {
continue
}
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return fmt.Errorf("error getting GPU instance profile info for '%v': %v", i, ret)
}

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

Expand All @@ -96,18 +96,18 @@ func (gi GpuInstance) WalkComputeInstances(f func(ci nvml.ComputeInstance, ciPro
for j := 0; j < nvml.COMPUTE_INSTANCE_PROFILE_COUNT; j++ {
for k := 0; k < nvml.COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT; k++ {
ciProfileInfo, ret := gi.GetComputeInstanceProfileInfo(j, k)
if ret.Value() == nvml.ERROR_NOT_SUPPORTED {
if ret == nvml.ERROR_NOT_SUPPORTED {
continue
}
if ret.Value() == nvml.ERROR_INVALID_ARGUMENT {
if ret == nvml.ERROR_INVALID_ARGUMENT {
continue
}
if ret.Value() != nvml.SUCCESS {
if ret != nvml.SUCCESS {
return fmt.Errorf("error getting Compute instance profile info for '(%v, %v)': %v", j, k, ret)
}

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

Expand Down
2 changes: 1 addition & 1 deletion internal/nvlib/nvlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package nvlib

import (
"github.com/NVIDIA/mig-parted/internal/nvlib/mig"

Check failure on line 20 in internal/nvlib/nvlib.go

View workflow job for this annotation

GitHub Actions / check

File is not `gofmt`-ed with `-s` (gofmt)
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)

type Interface struct {
Expand Down
85 changes: 0 additions & 85 deletions internal/nvml/consts.go

This file was deleted.

Loading

0 comments on commit 8d39bd7

Please sign in to comment.