From a4601e735d79dac6fb08e926e2f9fa1d2472a6ba Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 12 Dec 2023 11:05:44 +0800 Subject: [PATCH] quick return for edge case Signed-off-by: kerthcet --- gpuallocator/besteffort_policy.go | 4 ++++ gpuallocator/besteffort_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/gpuallocator/besteffort_policy.go b/gpuallocator/besteffort_policy.go index 366ba6a..4c0f0bc 100644 --- a/gpuallocator/besteffort_policy.go +++ b/gpuallocator/besteffort_policy.go @@ -46,6 +46,10 @@ func (p *bestEffortPolicy) Allocate(available []*Device, required []*Device, siz return []*Device{} } + if len(required) > len(available) { + return []*Device{} + } + // Find the highest scoring GPU partition with sets of of size 'size'. // Don't consider partitions that don't have at least one set that contains // all of the GPUs 'required' by the allocation. diff --git a/gpuallocator/besteffort_test.go b/gpuallocator/besteffort_test.go index b36bb00..24699c6 100644 --- a/gpuallocator/besteffort_test.go +++ b/gpuallocator/besteffort_test.go @@ -110,6 +110,14 @@ func TestBestEffortAllocate(t *testing.T) { 4, []int{}, }, + { + "Required too many devices than available", + devices, + []int{1, 2, 3, 4, 5}, + []int{1, 2, 3, 4, 5, 6}, + 1, + []int{}, + }, } RunPolicyAllocTests(t, policy, tests)