Skip to content

Commit 820b450

Browse files
committed
nvswitch: Add NVSWITCH_ALIAS
Similar to P_GPU_ALIAS add NVSWTICH_ALIAS to override the name that is originally given by the DP nvidia.com/nvswitch: 4 nvidia.com/pgpu: 8 Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
1 parent 49fda68 commit 820b450

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
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
}

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
})

0 commit comments

Comments
 (0)