Skip to content

Commit 4c92499

Browse files
authored
Add nvidia gpu topoloy score registry to node (#1018)
Signed-off-by: rongfu.leng <[email protected]>
1 parent de20781 commit 4c92499

File tree

7 files changed

+921
-8
lines changed

7 files changed

+921
-8
lines changed

docs/proposals/gpu-topo-policy.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# GPU topology scheduling strategy
2+
3+
## Use Case
4+
5+
### Node Select
6+
7+
If multiple nodes meet the requirements, the minimum meeting node should be selected first::
8+
- `Node1`
9+
```json
10+
[
11+
{
12+
"uuid": "gpu0",
13+
"score": {
14+
"gpu1": "100",
15+
"gpu2": "100",
16+
"gpu3": "200"
17+
}
18+
},
19+
{
20+
"uuid": "gpu1",
21+
"score": {
22+
"gpu0": "100",
23+
"gpu2": "200",
24+
"gpu3": "100"
25+
}
26+
},
27+
{
28+
"uuid": "gpu2",
29+
"score": {
30+
"gpu0": "100",
31+
"gpu1": "200",
32+
"gpu3": "200"
33+
}
34+
},
35+
{
36+
"uuid": "gpu3",
37+
"score": {
38+
"gpu0": "200",
39+
"gpu1": "100",
40+
"gpu2": "200"
41+
}
42+
}
43+
]
44+
```
45+
46+
47+
- `Node2`
48+
```json
49+
[
50+
{
51+
"uuid": "gpu0",
52+
"score": {
53+
"gpu1": "100",
54+
"gpu2": "100",
55+
"gpu3": "200",
56+
"gpu4": "200",
57+
"gpu5": "200"
58+
}
59+
},
60+
{
61+
"uuid": "gpu1",
62+
"score": {
63+
"gpu0": "100",
64+
"gpu2": "200",
65+
"gpu3": "100",
66+
"gpu4": "200",
67+
"gpu5": "200"
68+
}
69+
},
70+
{
71+
"uuid": "gpu2",
72+
"score": {
73+
"gpu0": "100",
74+
"gpu1": "200",
75+
"gpu3": "200",
76+
"gpu4": "200",
77+
"gpu5": "200"
78+
}
79+
},
80+
{
81+
"uuid": "gpu3",
82+
"score": {
83+
"gpu0": "200",
84+
"gpu1": "100",
85+
"gpu2": "200",
86+
"gpu4": "200",
87+
"gpu5": "200"
88+
}
89+
},
90+
{
91+
"uuid": "gpu4",
92+
"score": {
93+
"gpu0": "200",
94+
"gpu1": "100",
95+
"gpu2": "200",
96+
"gpu3": "200",
97+
"gpu5": "200"
98+
}
99+
},
100+
{
101+
"uuid": "gpu5",
102+
"score": {
103+
"gpu0": "200",
104+
"gpu1": "100",
105+
"gpu2": "200",
106+
"gpu3": "200",
107+
"gpu4": "200"
108+
}
109+
}
110+
]
111+
```
112+
113+
For example, the two nodes above should be given priority `Node1`.
114+
115+
116+
### Device Select, One Pod One Device
117+
118+
1. When a Pod only needs one card, the card with the worst communication with other cards should be given priority if the video memory and computing power are sufficient, such as:
119+
- `Node1`
120+
```json
121+
[
122+
{
123+
"uuid": "gpu0",
124+
"score": {
125+
"gpu1": "100",
126+
"gpu2": "100",
127+
"gpu3": "200"
128+
}
129+
},
130+
{
131+
"uuid": "gpu1",
132+
"score": {
133+
"gpu0": "100",
134+
"gpu2": "200",
135+
"gpu3": "100"
136+
}
137+
},
138+
{
139+
"uuid": "gpu2",
140+
"score": {
141+
"gpu0": "100",
142+
"gpu1": "200",
143+
"gpu3": "200"
144+
}
145+
},
146+
{
147+
"uuid": "gpu3",
148+
"score": {
149+
"gpu0": "200",
150+
"gpu1": "100",
151+
"gpu2": "200"
152+
}
153+
}
154+
]
155+
```
156+
There are only four cards on this node, and `gpu0` and `gpu1` have the worst connectivity with other cards, so these two cards are preferred in single-card mode.
157+
158+
### Device Select, One Pod More Than One Device
159+
1. When a Pod only needs multiple cards, if the video memory and computing power are sufficient, the card with the best communication with other cards should be given priority, such as:
160+
- `Node1`
161+
```json
162+
[
163+
{
164+
"uuid": "gpu0",
165+
"score": {
166+
"gpu1": "100",
167+
"gpu2": "100",
168+
"gpu3": "200"
169+
}
170+
},
171+
{
172+
"uuid": "gpu1",
173+
"score": {
174+
"gpu0": "100",
175+
"gpu2": "200",
176+
"gpu3": "100"
177+
}
178+
},
179+
{
180+
"uuid": "gpu2",
181+
"score": {
182+
"gpu0": "100",
183+
"gpu1": "200",
184+
"gpu3": "200"
185+
}
186+
},
187+
{
188+
"uuid": "gpu3",
189+
"score": {
190+
"gpu0": "200",
191+
"gpu1": "100",
192+
"gpu2": "200"
193+
}
194+
}
195+
]
196+
```
197+
There are only four cards on this node, and `gpu2` and `gpu3` have the best connectivity with other cards, so these two cards are given priority in multi-card mode.

pkg/device-plugin/nvidiadevice/nvinternal/plugin/register.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
package plugin
3434

3535
import (
36+
"encoding/json"
3637
"fmt"
38+
"os"
3739
"os/exec"
3840
"strconv"
3941
"strings"
@@ -188,8 +190,25 @@ func (plugin *NvidiaDevicePlugin) RegistrInAnnotation() error {
188190
return err
189191
}
190192
encodeddevices := util.EncodeNodeDevices(*devices)
193+
var data []byte
194+
if os.Getenv("ENABLE_TOPOLOGY_SCORE") == "true" {
195+
gpuScore, err := nvidia.CalculateGPUScore(util.GetDevicesUUIDList(*devices))
196+
if err != nil {
197+
klog.ErrorS(err, "calculate gpu topo score error")
198+
return err
199+
}
200+
data, err = json.Marshal(gpuScore)
201+
if err != nil {
202+
klog.ErrorS(err, "marshal gpu score error.")
203+
return err
204+
}
205+
}
206+
klog.V(4).InfoS("patch nvidia topo score to node", "hami.io/node-nvidia-score", string(data))
191207
annos[nvidia.HandshakeAnnos] = "Reported " + time.Now().String()
192208
annos[nvidia.RegisterAnnos] = encodeddevices
209+
if len(data) > 0 {
210+
annos[nvidia.RegisterGPUPairScore] = string(data)
211+
}
193212
klog.Infof("patch node with the following annos %v", fmt.Sprintf("%v", annos))
194213
err = util.PatchNodeAnnotations(node, annos)
195214

0 commit comments

Comments
 (0)