Browse Source

opt

tags/v1.22.1.3
lewis 4 years ago
parent
commit
cefc20ff4f
3 changed files with 48 additions and 6 deletions
  1. +2
    -0
      modules/setting/setting.go
  2. +45
    -5
      routers/repo/cloudbrain.go
  3. +1
    -1
      templates/repo/cloudbrain/benchmark/new.tmpl

+ 2
- 0
modules/setting/setting.go View File

@@ -468,6 +468,7 @@ var (
BenchmarkServerHost string
BenchmarkCategory string
BenchmarkTypes string
BenchmarkGpuTypes string

//snn4imagenet config
IsSnn4imagenetEnabled bool
@@ -1272,6 +1273,7 @@ func NewContext() {
BenchmarkServerHost = sec.Key("HOST").MustString("")
BenchmarkCategory = sec.Key("CATEGORY").MustString("")
BenchmarkTypes = sec.Key("TYPES").MustString("")
BenchmarkGpuTypes = sec.Key("GPU_TYPES").MustString("")

sec = Cfg.Section("snn4imagenet")
IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false)


+ 45
- 5
routers/repo/cloudbrain.go View File

@@ -41,6 +41,7 @@ var (
gpuInfos *models.GpuInfos
categories *models.Categories
benchmarkTypes *models.BenchmarkTypes
benchmarkGpuInfos *models.GpuInfos
)

var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`)
@@ -140,6 +141,11 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error {
}
ctx.Data["gpu_types"] = gpuInfos.GpuInfo

if benchmarkGpuInfos == nil {
json.Unmarshal([]byte(setting.BenchmarkGpuTypes), &benchmarkGpuInfos)
}
ctx.Data["benchmark_gpu_types"] = benchmarkGpuInfos.GpuInfo

if cloudbrain.ResourceSpecs == nil {
json.Unmarshal([]byte(setting.ResourceSpecs), &cloudbrain.ResourceSpecs)
}
@@ -1084,6 +1090,32 @@ func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int) (string,
return uuid, nil
}

func getBenchmarkGpuQueue(gpuQueue string) (string, error) {
queue := ""
if benchmarkGpuInfos == nil {
if err := json.Unmarshal([]byte(setting.BenchmarkGpuTypes), &benchmarkGpuInfos); err != nil {
log.Error("json.Unmarshal BenchmarkGpuTypes(%s) failed:%v", setting.BenchmarkGpuTypes, err)
return queue, err
}
}

var isExist bool
for _, gpuInfo := range benchmarkGpuInfos.GpuInfo {
if gpuQueue == gpuInfo.Queue {
isExist = true
queue = gpuQueue
break
}
}

if !isExist {
log.Error("no such gpuQueue, %s", gpuQueue)
return queue, errors.New("no such gpuQueue")
}

return queue, nil
}

func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
ctx.Data["PageIsCloudBrain"] = true
jobName := form.JobName
@@ -1108,6 +1140,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF
return
}

_, err = getBenchmarkGpuQueue(gpuQueue)
if err != nil {
log.Error("getBenchmarkGpuQueue failed:%v", err, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("gpu queue error", tplCloudBrainBenchmarkNew, &form)
return
}

count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, string(models.JobTypeBenchmark))
if err != nil {
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"])
@@ -1131,7 +1171,7 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF
return
} else {
if !models.IsErrJobNotExist(err) {
log.Error("system error, %v", err, ctx.Data["MsgID"])
log.Error("GetCloudbrainByName failed, %v", err, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form)
return
@@ -1140,14 +1180,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF
repo := ctx.Repo.Repository
os.RemoveAll(codePath)
if err := downloadCode(repo, codePath); err != nil {
log.Error("system error, %v", err, ctx.Data["MsgID"])
log.Error("downloadCode failed, %v", err, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form)
return
}

if err := uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/"); err != nil {
log.Error("system error, %v", err, ctx.Data["MsgID"])
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form)
return
@@ -1162,14 +1202,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF
}

if err := downloadRateCode(repo, jobName, setting.BenchmarkOwner, setting.BenchmarkName, benchmarkPath, form.BenchmarkCategory, gpuType); err != nil {
log.Error("system error, %v", err, ctx.Data["MsgID"])
log.Error("downloadRateCode failed, %v", err, ctx.Data["MsgID"])
//cloudBrainNewDataPrepare(ctx)
//ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form)
//return
}

if err := uploadCodeToMinio(benchmarkPath+"/", jobName, cloudbrain.BenchMarkMountPath+"/"); err != nil {
log.Error("system error, %v", err, ctx.Data["MsgID"])
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"])
//cloudBrainNewDataPrepare(ctx)
//ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form)
//return


+ 1
- 1
templates/repo/cloudbrain/benchmark/new.tmpl View File

@@ -85,7 +85,7 @@
<div class="required unite min_title inline field">
<label style="font-weight: normal;">GPU类型</label>
<select id="cloudbrain_gpu_type" class="ui search dropdown" placeholder="选择GPU类型" style='width:385px' name="gpu_type">
{{range .gpu_types}}
{{range .benchmark_gpu_types}}
<option value="{{.Queue}}">{{.Value}}</option>
{{end}}
</select>


Loading…
Cancel
Save