Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize for requesting 1 device #18

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
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
47 changes: 39 additions & 8 deletions gpuallocator/besteffort_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ func (p *bestEffortPolicy) Allocate(available []*Device, required []*Device, siz
return []*Device{}
}

if len(required) > len(available) {
return []*Device{}
}

// Optimize for the case when we required is actually the `size`.
if size == len(required) {
if gpuSetContainsAll(available, required) {
return required
}
return []*Device{}
}

// Optimize for the case when size == 1.
// We'll pick the device with the minimum sum of scores with available devices.
Copy link
Contributor Author

@kerthcet kerthcet Dec 6, 2023

Choose a reason for hiding this comment

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

We can discuss here, from my POV, since 1 device no longer needs the communication with other GPUs, so the lower score the better.

Copy link
Member

Choose a reason for hiding this comment

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

For requests with 1 device is the choice not irrellevant from the perspective of the application requesting the device? It may be that assigning the device with the lowest connectivity in this case provides some advantage since other more connected devices are available for future requests that require multple devices.

Do you have benchmarks to show whether this change improves performance at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be that assigning the device with the lowest connectivity in this case provides some advantage since other more connected devices are available for future requests that require multple devices.

Yes, exactly the case, benefit to the future request for multi-devices.

I have no benchmark yet, but I can provide one if needed, generally, this is not quite aimed for the performance but for the application friendly and rational utilization as you described above.

if size == 1 {
var bestDevice *Device
var minScore int
iterateGPUSetScore(available, func(score int, index int) {
if score < minScore || bestDevice == nil {
minScore = score
bestDevice = available[index]
}
})
return []*Device{bestDevice}
}

// 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 Expand Up @@ -217,14 +243,6 @@ func iterateGPUPartitions(devices []*Device, size int, callback func([][]*Device
return
}

// Optimize for the case when size == 1.
if size == 1 {
for _, device := range devices {
callback([][]*Device{{device}})
}
return
}

// Otherwise, pad the list of available GPUs on the node such that the list
// can be evenly partitioned into subsets of size 'size'. This is necessary
// to ensure that the recursive solution does not exit early and actually
Expand Down Expand Up @@ -392,3 +410,16 @@ func calculateGPUPartitionScore(gpuPartition [][]*Device) int {

return score
}

func iterateGPUSetScore(gpuSet []*Device, callback func(int, int)) {
for i := range gpuSet {
score := 0
for j := range gpuSet {
if i == j {
continue
}
score += calculateGPUPairScore(gpuSet[i], gpuSet[j])
}
callback(score, i)
}
}
40 changes: 40 additions & 0 deletions gpuallocator/besteffort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,46 @@ func TestBestEffortAllocate(t *testing.T) {
4,
[]int{},
},
{
"Required too many devices than available",
kerthcet marked this conversation as resolved.
Show resolved Hide resolved
devices,
[]int{0, 1, 2, 3, 4, 5},
[]int{1, 2, 3, 4, 5, 6},
1,
[]int{},
},
{
"Required devices is equal to the size",
devices,
[]int{0, 1, 2, 4, 5, 6},
[]int{0, 1, 2, 5},
4,
[]int{0, 1, 2, 5},
},
{
"Required 1 device exists",
devices,
[]int{0, 1, 2, 4, 5, 6},
[]int{2},
1,
[]int{2},
},
{
"Required 1 device not exists",
devices,
[]int{0, 1, 2, 4, 5, 6},
[]int{3},
1,
[]int{},
},
{
"Required 1 best effort device",
devices,
[]int{0, 1, 2},
[]int{},
1,
[]int{0},
},
}

RunPolicyAllocTests(t, policy, tests)
Expand Down