Skip to content

Commit 53f039a

Browse files
authored
Merge pull request #28 from zvonkok/nvswitch-alias
nvswitch: Add NVSWITCH_ALIAS
2 parents b14436b + 68066df commit 53f039a

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ import (
3535

3636
func main() {
3737
device_plugin.PGPUAlias = os.Getenv("P_GPU_ALIAS")
38+
device_plugin.NVSwitchAlias = os.Getenv("NVSWITCH_ALIAS")
3839
device_plugin.InitiateDevicePlugin()
3940
}

go.sum

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,28 @@ github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU
293293
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
294294
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
295295
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
296+
github.com/opencontainers/runtime-spec v1.3.0 h1:YZupQUdctfhpZy3TM39nN9Ika5CBWT5diQ8ibYCRkxg=
297+
github.com/opencontainers/runtime-spec v1.3.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
298+
github.com/opencontainers/runtime-tools v0.9.1-0.20251114084447-edf4cb3d2116 h1:tAKu3NkKWZYpqBSOJKwTxT1wIGueiF7gcmcNgr5pNTY=
299+
github.com/opencontainers/runtime-tools v0.9.1-0.20251114084447-edf4cb3d2116/go.mod h1:DKDEfzxvRkoQ6n9TGhxQgg2IM1lY4aM0eaQP4e3oElw=
300+
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=
301+
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
302+
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
303+
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
304+
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
305+
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
306+
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
307+
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
308+
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
309+
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
310+
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
311+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
312+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
313+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
314+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
315+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
296316
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
297317
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
298-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
299-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
300318
github.com/polyfloyd/go-errorlint v1.7.1 h1:RyLVXIbosq1gBdk/pChWA8zWYLsq9UEw7a1L5TVMCnA=
301319
github.com/polyfloyd/go-errorlint v1.7.1/go.mod h1:aXjNb1x2TNhoLsk26iv1yl7a+zTnXPhwEMtEXukiLR8=
302320
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=

pkg/device_plugin/cdi.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func GenerateCDISpec() error {
6868

6969
// Generate NVSwitch CDI spec if we have NVSwitch devices
7070
if len(nvSwitchDeviceIDs) > 0 {
71-
if err := generateCDISpecForClass(cdiNVSwitchClass, true); err != nil {
71+
nvSwitchClass := cdiNVSwitchClass
72+
if NVSwitchAlias != "" {
73+
nvSwitchClass = NVSwitchAlias
74+
}
75+
if err := generateCDISpecForClass(nvSwitchClass, true); err != nil {
7276
return fmt.Errorf("failed to generate NVSwitch CDI spec: %w", err)
7377
}
7478
}

pkg/device_plugin/device_plugin.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var nvpciLib nvpci.Interface
6464
var startDevicePlugin = startDevicePluginFunc
6565
var stop = make(chan struct{})
6666
var PGPUAlias string
67+
var NVSwitchAlias string
6768

6869
func InitiateDevicePlugin() {
6970
// Initialize nvpci library if not already set (allows injection for testing)
@@ -99,14 +100,15 @@ func createDevicePlugins() {
99100
})
100101
}
101102

102-
// Determine device name - NVSwitches always use their actual name,
103-
// GPUs can use PGPUAlias if set
103+
// Determine device name - use alias if set, otherwise use actual device name
104104
var deviceName string
105105
if isNVSwitchDeviceID(deviceID) {
106-
// NVSwitches always use their actual device name
107-
deviceName = getDeviceNameForID(deviceID)
106+
if NVSwitchAlias != "" {
107+
deviceName = NVSwitchAlias
108+
} else {
109+
deviceName = getDeviceNameForID(deviceID)
110+
}
108111
} else if PGPUAlias != "" {
109-
// GPUs can use the alias
110112
deviceName = PGPUAlias
111113
} else {
112114
deviceName = getDeviceNameForID(deviceID)

pkg/device_plugin/device_plugin_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,26 @@ var _ = Describe("Device Plugin", func() {
286286
result := getDeviceNameForID("abcd")
287287
Expect(result).To(Equal(""))
288288
})
289+
290+
It("formats device names with special characters through formatDeviceName", func() {
291+
iommuMap = map[string][]NvidiaPCIDevice{
292+
"1": {
293+
{
294+
Address: "0000:01:00.0",
295+
DeviceID: 0x2330,
296+
DeviceName: "NVIDIA H100 PCIe [Hopper]",
297+
IommuGroup: 1,
298+
},
299+
},
300+
}
301+
result := getDeviceNameForID("2330")
302+
Expect(result).To(Equal("NVIDIA_H100_PCIE_HOPPER"))
303+
})
304+
305+
It("returns empty string when iommuMap is empty", func() {
306+
iommuMap = map[string][]NvidiaPCIDevice{}
307+
result := getDeviceNameForID("1b80")
308+
Expect(result).To(Equal(""))
309+
})
289310
})
290311
})

vendor/modules.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ github.com/onsi/gomega/matchers/support/goraph/edge
643643
github.com/onsi/gomega/matchers/support/goraph/node
644644
github.com/onsi/gomega/matchers/support/goraph/util
645645
github.com/onsi/gomega/types
646+
# github.com/opencontainers/runtime-spec v1.3.0
647+
## explicit
648+
github.com/opencontainers/runtime-spec/specs-go
649+
# github.com/opencontainers/runtime-tools v0.9.1-0.20251114084447-edf4cb3d2116
650+
## explicit; go 1.21
651+
github.com/opencontainers/runtime-tools/generate
652+
github.com/opencontainers/runtime-tools/generate/seccomp
653+
github.com/opencontainers/runtime-tools/validate/capabilities
646654
# github.com/pelletier/go-toml v1.9.5
647655
## explicit; go 1.12
648656
github.com/pelletier/go-toml

0 commit comments

Comments
 (0)