diff --git a/modules/setting/setting.go b/modules/setting/setting.go index a327a25d6..92928639a 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -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) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index c45efc069..2181eb098 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -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 diff --git a/templates/repo/cloudbrain/benchmark/new.tmpl b/templates/repo/cloudbrain/benchmark/new.tmpl old mode 100644 new mode 100755 index fad6496e0..2be134126 --- a/templates/repo/cloudbrain/benchmark/new.tmpl +++ b/templates/repo/cloudbrain/benchmark/new.tmpl @@ -85,7 +85,7 @@