Skip to content

Commit c961e77

Browse files
authored
fix: sort node by device minor id (#137)
fix: use AllocatableMemory instead of used Signed-off-by: thomassong <thomassong2012@gmail.com>
1 parent b0770c7 commit c961e77

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

pkg/algorithm/nvidia/fragment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (al *fragmentMode) Evaluate(cores int64, _ int64) []*nvidia.NvidiaNode {
4444
var (
4545
candidate = al.tree.Root()
4646
next *nvidia.NvidiaNode
47-
sorter = fragmentSort(nvidia.ByAvailable, nvidia.ByMemory, nvidia.ByPids, nvidia.ByID)
47+
sorter = fragmentSort(nvidia.ByAvailable, nvidia.ByAllocatableMemory, nvidia.ByPids, nvidia.ByMinorID)
4848
nodes = make([]*nvidia.NvidiaNode, 0)
4949
num = int(cores / nvidia.HundredCore)
5050
)

pkg/algorithm/nvidia/link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewLinkMode(t *nvidia.NvidiaTree) *linkMode {
3939

4040
func (al *linkMode) Evaluate(cores int64, memory int64) []*nvidia.NvidiaNode {
4141
var (
42-
sorter = linkSort(nvidia.ByType, nvidia.ByAvailable, nvidia.ByMemory, nvidia.ByPids, nvidia.ByID)
42+
sorter = linkSort(nvidia.ByType, nvidia.ByAvailable, nvidia.ByAllocatableMemory, nvidia.ByPids, nvidia.ByMinorID)
4343
tmpStore = make(map[int]*nvidia.NvidiaNode)
4444
root = al.tree.Root()
4545
nodes = make([]*nvidia.NvidiaNode, 0)

pkg/algorithm/nvidia/share.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (al *shareMode) Evaluate(cores int64, memory int64) []*nvidia.NvidiaNode {
4444
var (
4545
nodes []*nvidia.NvidiaNode
4646
tmpStore = make([]*nvidia.NvidiaNode, al.tree.Total())
47-
sorter = shareModeSort(nvidia.ByAllocatableCores, nvidia.ByAllocatableMemory, nvidia.ByPids, nvidia.ByID)
47+
sorter = shareModeSort(nvidia.ByAllocatableCores, nvidia.ByAllocatableMemory, nvidia.ByPids, nvidia.ByMinorID)
4848
)
4949

5050
for i := 0; i < al.tree.Total(); i++ {

pkg/device/nvidia/sort.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ var (
4242
return p1.Meta.ID < p2.Meta.ID
4343
}
4444

45+
//ByMinorID compares two NvidiaNode by minor ID
46+
ByMinorID = func(p1, p2 *NvidiaNode) bool {
47+
return p1.Meta.MinorID < p2.Meta.MinorID
48+
}
49+
4550
//ByMemory compares two NvidiaNode by memory already used
4651
ByMemory = func(p1, p2 *NvidiaNode) bool {
4752
return p1.Meta.UsedMemory < p2.Meta.UsedMemory
@@ -64,7 +69,7 @@ var (
6469

6570
//PrintSorter is used to sort nodes when printing them out
6671
PrintSorter = &printSort{
67-
less: []LessFunc{ByType, ByAvailable, ByID},
72+
less: []LessFunc{ByType, ByAvailable, ByMinorID},
6873
}
6974
)
7075

pkg/device/nvidia/sort_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ GPU5 SOC SOC SOC SOC PIX X
5858
ByAvailable,
5959
ByType,
6060
ByAllocatableMemory,
61-
ByID,
61+
ByMinorID,
6262
ByPids,
6363
ByMemory},
6464
}

0 commit comments

Comments
 (0)