Skip to content

Commit

Permalink
Merge pull request #20 from kerthcet/cleanup/quick-return
Browse files Browse the repository at this point in the history
Quick return in error case
  • Loading branch information
elezar authored Jan 27, 2024
2 parents 02af3d8 + a4601e7 commit b057784
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gpuallocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Allocator struct {
allocated DeviceSet
}

// Policy defines an interface for plugagable allocation policies to be added
// Policy defines an interface for pluggable allocation policies to be added
// to an Allocator.
type Policy interface {
// Allocate is meant to do the heavy-lifting of implementing the actual
Expand Down
4 changes: 4 additions & 0 deletions gpuallocator/besteffort_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions gpuallocator/besteffort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b057784

Please sign in to comment.