From 4b24c1b99c18f0b613abe968add996bb4c62ca25 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Wed, 6 Dec 2023 17:01:23 +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..e614cef 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{0, 1, 2, 3, 4, 5}, + []int{1, 2, 3, 4, 5, 6}, + 1, + []int{}, + }, } RunPolicyAllocTests(t, policy, tests)