Commit 5ca34c42 authored by duanjinfei's avatar duanjinfei

foundSeq

parent 57f6f27c
...@@ -30,4 +30,5 @@ const ( ...@@ -30,4 +30,5 @@ const (
OneHour = 1 OneHour = 1
OneMinutes = 1 OneMinutes = 1
TwoMinutes = 2 TwoMinutes = 2
DefaultGpuSeq = 999
) )
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"example.com/m/db" "example.com/m/db"
"example.com/m/log" "example.com/m/log"
"example.com/m/models" "example.com/m/models"
"example.com/m/utils"
"fmt" "fmt"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
...@@ -391,36 +392,54 @@ func (d *DockerOp) getContainerInfo(id string) (types.Container, error) { ...@@ -391,36 +392,54 @@ func (d *DockerOp) getContainerInfo(id string) (types.Container, error) {
} }
func (d *DockerOp) checkGpuUsage(info *nodemanagerV2.HardwareInfo, modelInfo *models.ModelInfo, dockerCmd *models.DockerCmd) int32 { func (d *DockerOp) checkGpuUsage(info *nodemanagerV2.HardwareInfo, modelInfo *models.ModelInfo, dockerCmd *models.DockerCmd) int32 {
envMap := make(map[string]string, 0) var res int32 = models.DefaultGpuSeq
var res int32 = 999 // 匹配首次启动模型的硬件信息数据
gpu := info.GPU gpu := info.GPU
isMatch := false isMatch := false
for _, gpuInfo := range gpu { for _, gpuInfo := range gpu {
if gpuInfo.MemFree > modelInfo.RunningMem { if gpuInfo.MemFree > modelInfo.RunningMem {
envMap[models.CudaEnv] = strconv.FormatInt(int64(gpuInfo.Seq), 10)
res = gpuInfo.Seq res = gpuInfo.Seq
isMatch = true isMatch = true
break break
} }
} }
if !isMatch { if !isMatch {
runningModel := db.GetRunningModel() res = d.foundSeq(modelInfo)
if len(runningModel) == 0 { }
return 0 return res
}
func (d *DockerOp) foundSeq(modelInfo *models.ModelInfo) int32 {
var res int32 = models.DefaultGpuSeq
isMatch := false
// 获取当前启动的模型
runningModel := d.ListContainer()
for _, containerInfo := range runningModel {
runningModelInfo, err := db.GetModel(containerInfo.Image)
if err != nil || runningModelInfo == nil {
continue
} }
for _, modelInfo := range runningModel { if runningModelInfo.RunningMem > modelInfo.RunningMem {
if modelInfo.RunningMem > modelInfo.RunningMem { isMatch = true
isMatch = true d.StopContainer(containerInfo.ID)
d.StopContainer(modelInfo.ContainerId) if modelInfo.GpuSeq != models.DefaultGpuSeq {
envMap[models.CudaEnv] = strconv.FormatInt(int64(modelInfo.GpuSeq), 10) res = modelInfo.GpuSeq
break } else {
time.Sleep(time.Second * 2)
hardwareInfo := utils.GetHardwareInfo(conf.GetConfig().HardwareUrl)
for _, gpuInfo := range hardwareInfo.Data.Gpus {
if gpuInfo.MemFree > modelInfo.RunningMem {
res = gpuInfo.Seq
isMatch = true
break
}
}
} }
break
} }
} }
if isMatch { if !isMatch {
//nm.ModelRunningBeforeMem[modelInfo.ImageName] = dockerCmd.RunningBeforeMem d.foundSeq(modelInfo)
gpuSeq, _ := strconv.ParseInt(dockerCmd.EnvMap[models.CudaEnv], 10, 32)
res = int32(gpuSeq)
} }
return res return res
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment