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
16 changes: 8 additions & 8 deletions pkg/scheduler/policy/gpu_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ func (l DeviceUsageList) Swap(i, j int) {
}

func (l DeviceUsageList) Less(i, j int) bool {
if l.Policy == util.GPUSchedulerPolicyBinpack.String() {
switch l.Policy {
case util.GPUSchedulerPolicyBinpack.String():
return l.DeviceLists[i].Score < l.DeviceLists[j].Score
case util.GPUSchedulerPolicySpread.String():
return l.DeviceLists[i].Score > l.DeviceLists[j].Score
default:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default branch has no test. add a case with a non-binpack, non-spread policy (e.g. empty string or "topology") and devices on different numa nodes to cover the two return paths here.

if l.DeviceLists[i].Device.Numa == l.DeviceLists[j].Device.Numa {
return l.DeviceLists[i].Score < l.DeviceLists[j].Score
return l.DeviceLists[i].Score > l.DeviceLists[j].Score
}
return l.DeviceLists[i].Device.Numa > l.DeviceLists[j].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
return l.DeviceLists[i].Device.Numa < l.DeviceLists[j].Device.Numa
}
return l.DeviceLists[i].Device.Numa < l.DeviceLists[j].Device.Numa
}

func (ds *DeviceListsScore) ComputeScore(requests device.ContainerDeviceRequests) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/policy/gpu_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestDeviceUsageList_Less(t *testing.T) {
{Device: &device.DeviceUsage{Numa: 0, Used: 10}, Score: 10},
{Device: &device.DeviceUsage{Numa: 1, Used: 20}, Score: 20},
},
expectedLess: false,
expectedLess: true,
},
{
name: "Spread policy with same Numa",
Expand All @@ -177,7 +177,7 @@ func TestDeviceUsageList_Less(t *testing.T) {
{Device: &device.DeviceUsage{Numa: 0, Used: 10}, Score: 10},
{Device: &device.DeviceUsage{Numa: 1, Used: 20}, Score: 20},
},
expectedLess: true,
expectedLess: false,
},
}

Expand Down
Loading