File tree Expand file tree Collapse file tree 4 files changed +34
-6
lines changed
Expand file tree Collapse file tree 4 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -35,5 +35,6 @@ import (
3535
3636func main () {
3737 device_plugin .PGPUAlias = os .Getenv ("P_GPU_ALIAS" )
38+ device_plugin .NVSwitchAlias = os .Getenv ("NVSWITCH_ALIAS" )
3839 device_plugin .InitiateDevicePlugin ()
3940}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ var nvpciLib nvpci.Interface
6464var startDevicePlugin = startDevicePluginFunc
6565var stop = make (chan struct {})
6666var PGPUAlias string
67+ var NVSwitchAlias string
6768
6869func 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 )
Original file line number Diff line number Diff 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})
You can’t perform that action at this time.
0 commit comments