zhangmeng
2019-07-10 0a324c77e33d8c0b61fd6d166cc8d3cec7d78139
update
1个文件已修改
27 ■■■■■ 已修改文件
gogpu.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gogpu.go
@@ -11,16 +11,39 @@
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"`