Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pkg/scheduler/policy/gpu_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type DeviceListsScore struct {
type DeviceUsageList struct {
DeviceLists []*DeviceListsScore
Policy string
NumaIgnore bool
}

func (l DeviceUsageList) Len() int {
Expand All @@ -43,17 +44,17 @@ func (l DeviceUsageList) Swap(i, j int) {
}

func (l DeviceUsageList) Less(i, j int) bool {
if l.Policy == util.GPUSchedulerPolicyBinpack.String() {
if l.DeviceLists[i].Device.Numa == l.DeviceLists[j].Device.Numa {
return l.DeviceLists[i].Score < l.DeviceLists[j].Score
di, dj := l.DeviceLists[i], l.DeviceLists[j]
if !l.NumaIgnore && di.Device.Numa != dj.Device.Numa {
if l.Policy == util.GPUSchedulerPolicyBinpack.String() {
return di.Device.Numa > dj.Device.Numa
}
return l.DeviceLists[i].Device.Numa > l.DeviceLists[j].Device.Numa
return di.Device.Numa < dj.Device.Numa
}
// default policy is spread
if l.DeviceLists[i].Device.Numa == l.DeviceLists[j].Device.Numa {
return l.DeviceLists[i].Score > l.DeviceLists[j].Score
if l.Policy == util.GPUSchedulerPolicyBinpack.String() {
return di.Score < dj.Score
}
return l.DeviceLists[i].Device.Numa < l.DeviceLists[j].Device.Numa
return di.Score > dj.Score
}

func (l DeviceUsageList) DeepCopy() DeviceUsageList {
Expand All @@ -67,6 +68,7 @@ func (l DeviceUsageList) DeepCopy() DeviceUsageList {
return DeviceUsageList{
DeviceLists: deviceLists,
Policy: l.Policy,
NumaIgnore: l.NumaIgnore,
}
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/scheduler/policy/gpu_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestDeviceUsageList_Less(t *testing.T) {
tests := []struct {
name string
policy string
numaIgnore bool
deviceLists []*DeviceListsScore
expectedLess bool
}{
Expand Down Expand Up @@ -181,12 +182,33 @@ func TestDeviceUsageList_Less(t *testing.T) {
},
expectedLess: true,
},
{
name: "Binpack NumaIgnore score primary",
policy: "binpack",
numaIgnore: true,
deviceLists: []*DeviceListsScore{
{Device: &device.DeviceUsage{Numa: 0, Used: 10}, Score: 10},
{Device: &device.DeviceUsage{Numa: 1, Used: 20}, Score: 20},
},
expectedLess: true,
},
{
name: "Spread NumaIgnore score primary",
policy: "spread",
numaIgnore: true,
deviceLists: []*DeviceListsScore{
{Device: &device.DeviceUsage{Numa: 1, Used: 10}, Score: 10},
{Device: &device.DeviceUsage{Numa: 0, Used: 20}, Score: 20},
},
expectedLess: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
l := DeviceUsageList{
Policy: tt.policy,
NumaIgnore: tt.numaIgnore,
DeviceLists: tt.deviceLists,
}
i, j := 0, 1
Expand Down
4 changes: 3 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,14 @@ func (s *Scheduler) getNodesUsage(nodes *[]string, task *corev1.Pod) (*map[strin
return &overallnodeMap, failedNodes, err
}

userGPUPolicy := util.GetGPUSchedulerPolicyByPod(device.GPUSchedulerPolicy, task)
numaIgnore := task != nil && task.Annotations != nil && task.Annotations[util.GPUTopologyAwareAnnotationKey] == "false"
for _, node := range allNodes {
nodeInfo := &NodeUsage{}
userGPUPolicy := util.GetGPUSchedulerPolicyByPod(device.GPUSchedulerPolicy, task)
nodeInfo.Node = node.Node
nodeInfo.Devices = policy.DeviceUsageList{
Policy: userGPUPolicy,
NumaIgnore: numaIgnore,
DeviceLists: make([]*policy.DeviceListsScore, 0),
}
for _, k := range node.Devices {
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const (
NodeSchedulerPolicyAnnotationKey = "hami.io/node-scheduler-policy"
// GPUSchedulerPolicyAnnotationKey is user set Pod annotation to change this default GPU policy.
GPUSchedulerPolicyAnnotationKey = "hami.io/gpu-scheduler-policy"
// GPUTopologyAwareAnnotationKey disables NUMA-first sorting when set to "false".
GPUTopologyAwareAnnotationKey = "hami.io/topology-aware-scoring"
)

func (s SchedulerPolicyName) String() string {
Expand Down
Loading