1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| package proc
|
| import (
| "analysis/logo"
|
| "basic.com/valib/gogpu.git"
| )
|
| func freeGPU(id, needed, reserve int) int {
| indices := gogpu.RankGPU()
| if len(indices) == 0 {
| logo.Errorln("THERE IS NO GPU FOR VALID")
| return -2
| }
|
| gi := id
|
| if id == -1 {
| if !gogpu.SatisfyGPU(indices[0], needed, reserve) {
| logo.Errorf("CAN'T SPARE GPU MEMORY NEEDED : %dM, RESERVER: %dM\n", needed, reserve)
| gi = -1
| }
| gi = indices[0]
| } else {
| if !gogpu.SatisfyGPU(gi, needed, reserve) {
| logo.Errorf("2ND CAN'T SPARE GPU MEMORY NEEDED : %dM, RESERVER: %dM\n", needed, reserve)
| gi = indices[0]
| if !gogpu.SatisfyGPU(gi, needed, reserve) {
| logo.Errorf("3RD CAN'T SPARE GPU MEMORY NEEDED : %dM, RESERVER: %dM\n", needed, reserve)
| gi = -1
| }
| }
| }
| return gi
| }
|
| // 优先不使用第1快显卡
| func priorGPU(lastChoice, needed, reserve int) int {
| indices := gogpu.RankGPU()
| if len(indices) == 0 {
| return -1
| }
|
| for _, v := range indices {
| if v != lastChoice {
| if gogpu.SatisfyGPU(v, needed, reserve) {
| return v
| }
| }
| }
|
| if gogpu.SatisfyGPU(lastChoice, needed, reserve) {
| return lastChoice
| }
| return -1
| }
|
|