Skip to content

Commit a4601e7

Browse files
committed
quick return for edge case
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent bf96ab0 commit a4601e7

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

gpuallocator/besteffort_policy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (p *bestEffortPolicy) Allocate(available []*Device, required []*Device, siz
4646
return []*Device{}
4747
}
4848

49+
if len(required) > len(available) {
50+
return []*Device{}
51+
}
52+
4953
// Find the highest scoring GPU partition with sets of of size 'size'.
5054
// Don't consider partitions that don't have at least one set that contains
5155
// all of the GPUs 'required' by the allocation.

gpuallocator/besteffort_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ func TestBestEffortAllocate(t *testing.T) {
110110
4,
111111
[]int{},
112112
},
113+
{
114+
"Required too many devices than available",
115+
devices,
116+
[]int{1, 2, 3, 4, 5},
117+
[]int{1, 2, 3, 4, 5, 6},
118+
1,
119+
[]int{},
120+
},
113121
}
114122

115123
RunPolicyAllocTests(t, policy, tests)

0 commit comments

Comments
 (0)