| | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "strconv" |
| | | "strings" |
| | | "unsafe" |
| | | ) |
| | | |
| | | // IdleGPU pass needed gpu memory size test if satisfy |
| | | func IdleGPU(memSize int) int { |
| | | // ValidGPU pass needed gpu memory size test if satisfy |
| | | func ValidGPU(memSize int) int { |
| | | return int(C.get_idle_gpu(C.int(memSize))) |
| | | } |
| | | |
| | | // IdleGPU idle most |
| | | func IdleGPU() int { |
| | | info, err := Info() |
| | | if err != nil { |
| | | fmt.Println("no gpu") |
| | | return -1 |
| | | } |
| | | if info.Count == 1 { |
| | | return 0 |
| | | } |
| | | |
| | | var free int64 |
| | | gpu := 0 |
| | | for k, v := range info.Info { |
| | | if v.GpuMemoryFree > free { |
| | | free = v.GpuMemoryFree |
| | | gpu = k |
| | | } |
| | | } |
| | | return gpu |
| | | } |
| | | |
| | | // GpuUnitInfo gpu card info |
| | | type GpuUnitInfo struct { |
| | | GpuUtilization int `json:"utilization"` |