Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
updated-dependencies:
- dependency-name: github.com/NVIDIA/go-nvlib
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
  • Loading branch information
dependabot[bot] authored and elezar committed May 21, 2024
1 parent 99e08b5 commit 8903fac
Show file tree
Hide file tree
Showing 17 changed files with 732 additions and 337 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/nvidia-container-toolkit
go 1.20

require (
github.com/NVIDIA/go-nvlib v0.3.0
github.com/NVIDIA/go-nvlib v0.4.0
github.com/NVIDIA/go-nvml v0.12.0-6
github.com/fsnotify/fsnotify v1.7.0
github.com/opencontainers/runtime-spec v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/NVIDIA/go-nvlib v0.3.0 h1:vd7jSOthJTqzqIWZrv317xDr1+Mnjoy5X4N69W9YwQM=
github.com/NVIDIA/go-nvlib v0.3.0/go.mod h1:NasUuId9hYFvwzuOHCu9F2X6oTU2tG0JHTfbJYuDAbA=
github.com/NVIDIA/go-nvlib v0.4.0 h1:dvuqjjSamBODFuxttPg4H/xtNVQRZOSlwFtuNKybcGI=
github.com/NVIDIA/go-nvlib v0.4.0/go.mod h1:87z49ULPr4GWPSGfSIp3taU4XENRYN/enIg88MzcL4k=
github.com/NVIDIA/go-nvml v0.12.0-6 h1:FJYc2KrpvX+VOC/8QQvMiQMmZ/nPMRpdJO/Ik4xfcr0=
github.com/NVIDIA/go-nvml v0.12.0-6/go.mod h1:8Llmj+1Rr+9VGGwZuRer5N/aCjxGuR5nPb/9ebBiIEQ=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
Expand Down
15 changes: 3 additions & 12 deletions internal/info/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)

// infoInterface provides an alias for mocking.
//
//go:generate moq -stub -out info-interface_mock.go . infoInterface
type infoInterface interface {
info.Interface
// UsesNVGPUModule indicates whether the system is using the nvgpu kernel module
UsesNVGPUModule() (bool, string)
}

type resolver struct {
logger logger.Interface
info infoInterface
info info.PropertyExtractor
}

// ResolveAutoMode determines the correct mode for the platform if set to "auto"
Expand Down Expand Up @@ -74,13 +65,13 @@ func (r resolver) resolveMode(mode string, image image.CUDA) (rmode string) {
return "cdi"
}

isTegra, reason := r.info.IsTegraSystem()
isTegra, reason := r.info.HasTegraFiles()
r.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)

hasNVML, reason := r.info.HasNvml()
r.logger.Debugf("Has NVML? %v: %v", hasNVML, reason)

usesNVGPUModule, reason := r.info.UsesNVGPUModule()
usesNVGPUModule, reason := r.info.UsesOnlyNVGPUModule()
r.logger.Debugf("Uses nvgpu kernel module? %v: %v", usesNVGPUModule, reason)

if (isTegra && !hasNVML) || usesNVGPUModule {
Expand Down
7 changes: 4 additions & 3 deletions internal/info/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package info
import (
"testing"

"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"github.com/opencontainers/runtime-spec/specs-go"
testlog "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -202,14 +203,14 @@ func TestResolveAutoMode(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
info := &infoInterfaceMock{
info := &info.PropertyExtractorMock{
HasNvmlFunc: func() (bool, string) {
return tc.info["nvml"], "nvml"
},
IsTegraSystemFunc: func() (bool, string) {
HasTegraFilesFunc: func() (bool, string) {
return tc.info["tegra"], "tegra"
},
UsesNVGPUModuleFunc: func() (bool, string) {
UsesOnlyNVGPUModuleFunc: func() (bool, string) {
return tc.info["nvgpu"], "nvgpu"
},
}
Expand Down
194 changes: 0 additions & 194 deletions internal/info/info-interface_mock.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/nvcdi/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (l *nvcdilib) resolveMode() (rmode string) {
isNvml, reason := l.infolib.HasNvml()
l.logger.Debugf("Is NVML-based system? %v: %v", isNvml, reason)

isTegra, reason := l.infolib.IsTegraSystem()
isTegra, reason := l.infolib.HasTegraFiles()
l.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)

if isTegra && !isNvml {
Expand Down
31 changes: 22 additions & 9 deletions pkg/nvcdi/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"testing"

"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
testlog "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -87,9 +88,15 @@ func TestResolveMode(t *testing.T) {
for i, tc := range testCases {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
l := nvcdilib{
logger: logger,
mode: tc.mode,
infolib: infoMock{hasDXCore: tc.hasDXCore, isTegra: tc.isTegra, hasNVML: tc.hasNVML},
logger: logger,
mode: tc.mode,
infolib: infoMock{
PropertyExtractor: &info.PropertyExtractorMock{
HasDXCoreFunc: func() (bool, string) { return tc.hasDXCore, "" },
HasNvmlFunc: func() (bool, string) { return tc.hasNVML, "" },
HasTegraFilesFunc: func() (bool, string) { return tc.isTegra, "" },
},
},
}

require.Equal(t, tc.expected, l.resolveMode())
Expand All @@ -98,19 +105,25 @@ func TestResolveMode(t *testing.T) {
}

type infoMock struct {
hasDXCore bool
isTegra bool
hasNVML bool
info.PropertyExtractor
}

func (i infoMock) ResolvePlatform() info.Platform {
return "not-implemented"
}

func (i infoMock) HasDXCore() (bool, string) {
return i.hasDXCore, ""
return i.PropertyExtractor.HasDXCore()
}

func (i infoMock) HasNvml() (bool, string) {
return i.hasNVML, ""
return i.PropertyExtractor.HasNvml()
}

func (i infoMock) IsTegraSystem() (bool, string) {
return i.isTegra, ""
return i.PropertyExtractor.HasTegraFiles()
}

func (i infoMock) HasTegraFiles() (bool, string) {
return i.PropertyExtractor.HasTegraFiles()
}
41 changes: 41 additions & 0 deletions vendor/github.com/NVIDIA/go-nvlib/pkg/nvlib/info/api.go

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

Loading

0 comments on commit 8903fac

Please sign in to comment.