Skip to content

Commit 06457b0

Browse files
Merge pull request volcano-sh#4779 from kiritoxkiriko/fix/vnpu-hami-bug
Fix: vNPU HAMi mode may not work with multi-type NPUs cluster
2 parents 1fab5f7 + 16b4a3b commit 06457b0

3 files changed

Lines changed: 85 additions & 5 deletions

File tree

pkg/scheduler/api/node_info.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ func (ni *NodeInfo) setNodeOthersResource(node *v1.Node) {
374374
ignored_list = append(ignored_list, devices.GetIgnoredDevices()...)
375375
}
376376
}
377-
IgnoredDevicesList.Set(ignored_list)
377+
klog.V(5).Infof("ignored_list is %v", ignored_list)
378+
IgnoredDevicesList.AppendList(
379+
ignored_list,
380+
)
381+
klog.V(5).Infof("ignoredDevicesList is %v", IgnoredDevicesList.List())
378382
}
379383

380384
// setNode sets kubernetes node object to nodeInfo object without assertion

pkg/scheduler/api/shared_device_pool.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package api
1818

1919
import (
20+
"slices"
2021
"sync"
2122

2223
v1 "k8s.io/api/core/v1"
@@ -104,7 +105,45 @@ func (l *ignoredDevicesList) Set(deviceLists ...[]string) {
104105
defer l.Unlock()
105106
l.ignoredDevices = l.ignoredDevices[:0]
106107
for _, devices := range deviceLists {
107-
l.ignoredDevices = append(l.ignoredDevices, devices...)
108+
for _, device := range devices {
109+
if device == "" {
110+
continue
111+
}
112+
if exists := slices.Contains(l.ignoredDevices, device); exists {
113+
continue
114+
}
115+
l.ignoredDevices = append(l.ignoredDevices, device)
116+
}
117+
}
118+
}
119+
120+
func (l *ignoredDevicesList) Append(devices ...string) {
121+
l.Lock()
122+
defer l.Unlock()
123+
for _, device := range devices {
124+
if device == "" {
125+
continue
126+
}
127+
if exists := slices.Contains(l.ignoredDevices, device); exists {
128+
continue
129+
}
130+
l.ignoredDevices = append(l.ignoredDevices, device)
131+
}
132+
}
133+
134+
func (l *ignoredDevicesList) AppendList(devicesLists ...[]string) {
135+
l.Lock()
136+
defer l.Unlock()
137+
for _, devices := range devicesLists {
138+
for _, device := range devices {
139+
if device == "" {
140+
continue
141+
}
142+
if exists := slices.Contains(l.ignoredDevices, device); exists {
143+
continue
144+
}
145+
l.ignoredDevices = append(l.ignoredDevices, device)
146+
}
108147
}
109148
}
110149

@@ -117,3 +156,11 @@ func (l *ignoredDevicesList) Range(f func(i int, device string) bool) {
117156
}
118157
}
119158
}
159+
160+
func (l *ignoredDevicesList) List() []string {
161+
l.RLock()
162+
defer l.RUnlock()
163+
devices := make([]string, len(l.ignoredDevices))
164+
copy(devices, l.ignoredDevices)
165+
return devices
166+
}

pkg/scheduler/api/shared_device_pool_test.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ func Test_ignoredDevicesList_Set_BasicUsage(t *testing.T) {
5656

5757
func Test_ignoredDevicesList_Range_BasicUsage(t *testing.T) {
5858
lst := ignoredDevicesList{}
59-
lst.Set([]string{"volcano.sh/vgpu-memory", "volcano.sh/vgpu-memory-percentage", "volcano.sh/vgpu-cores"})
59+
expected := []string{"volcano.sh/vgpu-memory", "volcano.sh/vgpu-memory-percentage", "volcano.sh/vgpu-cores"}
60+
lst.Set(expected)
6061

6162
t.Run("read and copy values from the ignoredDevicesList", func(t *testing.T) {
62-
ignoredDevices := make([]string, 0, len(lst.ignoredDevices))
63+
var ignoredDevices []string
6364
lst.Range(func(_ int, device string) bool {
6465
ignoredDevices = append(ignoredDevices, device)
6566
return true
6667
})
67-
assert.Equal(t, lst.ignoredDevices, ignoredDevices)
68+
assert.Equal(t, expected, ignoredDevices)
6869
})
6970

7071
t.Run("break iteration through the ignoredDevicesList", func(t *testing.T) {
@@ -140,3 +141,31 @@ func Test_ignoredDevicesList_NoRace(t *testing.T) {
140141
}
141142
wg.Wait()
142143
}
144+
145+
func Test_ignoredDevicesList_Set_DeduplicateAndOrder(t *testing.T) {
146+
lst := ignoredDevicesList{}
147+
lst.Set(
148+
[]string{"volcano.sh/vgpu-memory", "volcano.sh/vgpu-memory"},
149+
[]string{"", "volcano.sh/vgpu-cores", "volcano.sh/vgpu-memory"},
150+
)
151+
152+
assert.Equal(t, []string{"volcano.sh/vgpu-memory", "volcano.sh/vgpu-cores"}, lst.List())
153+
}
154+
155+
func Test_ignoredDevicesList_Append_PreservesOrder(t *testing.T) {
156+
lst := ignoredDevicesList{}
157+
lst.Set([]string{"volcano.sh/vgpu-memory"})
158+
lst.Append("volcano.sh/vgpu-memory", "volcano.sh/vgpu-cores", "")
159+
160+
assert.Equal(t, []string{"volcano.sh/vgpu-memory", "volcano.sh/vgpu-cores"}, lst.List())
161+
}
162+
163+
func Test_ignoredDevicesList_List_ReturnsCopy(t *testing.T) {
164+
lst := ignoredDevicesList{}
165+
lst.Set([]string{"volcano.sh/vgpu-memory"})
166+
167+
copyList := lst.List()
168+
copyList[0] = "changed"
169+
170+
assert.Equal(t, []string{"volcano.sh/vgpu-memory"}, lst.List())
171+
}

0 commit comments

Comments
 (0)