diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 92928639a..02ce26576 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -462,13 +462,14 @@ var ( MaxDuration int64 //benchmark config - IsBenchmarkEnabled bool - BenchmarkOwner string - BenchmarkName string - BenchmarkServerHost string - BenchmarkCategory string - BenchmarkTypes string - BenchmarkGpuTypes string + IsBenchmarkEnabled bool + BenchmarkOwner string + BenchmarkName string + BenchmarkServerHost string + BenchmarkCategory string + BenchmarkTypes string + BenchmarkGpuTypes string + BenchmarkResourceSpecs string //snn4imagenet config IsSnn4imagenetEnabled bool @@ -1274,6 +1275,7 @@ func NewContext() { BenchmarkCategory = sec.Key("CATEGORY").MustString("") BenchmarkTypes = sec.Key("TYPES").MustString("") BenchmarkGpuTypes = sec.Key("GPU_TYPES").MustString("") + BenchmarkResourceSpecs = sec.Key("RESOURCE_SPECS").MustString("") sec = Cfg.Section("snn4imagenet") IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 2181eb098..8b435e5e1 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -42,6 +42,7 @@ var ( categories *models.Categories benchmarkTypes *models.BenchmarkTypes benchmarkGpuInfos *models.GpuInfos + benchmarkResourceSpecs *models.ResourceSpecs ) var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) @@ -146,6 +147,11 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { } ctx.Data["benchmark_gpu_types"] = benchmarkGpuInfos.GpuInfo + if benchmarkResourceSpecs == nil { + json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &benchmarkResourceSpecs) + } + ctx.Data["benchmark_resource_specs"] = benchmarkResourceSpecs.ResourceSpec + if cloudbrain.ResourceSpecs == nil { json.Unmarshal([]byte(setting.ResourceSpecs), &cloudbrain.ResourceSpecs) } @@ -1116,6 +1122,32 @@ func getBenchmarkGpuQueue(gpuQueue string) (string, error) { return queue, nil } +func getBenchmarkResourceSpec(resourceSpecID int) (int, error) { + var id int + if benchmarkResourceSpecs == nil { + if err := json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &benchmarkResourceSpecs); err != nil { + log.Error("json.Unmarshal BenchmarkResourceSpecs(%s) failed:%v", setting.BenchmarkResourceSpecs, err) + return id, err + } + } + + var isExist bool + for _, resourceSpec := range benchmarkResourceSpecs.ResourceSpec { + if resourceSpecID == resourceSpec.Id { + isExist = true + id = resourceSpecID + break + } + } + + if !isExist { + log.Error("no such resourceSpecID, %d", resourceSpecID) + return id, errors.New("no such resourceSpec") + } + + return id, nil +} + func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { ctx.Data["PageIsCloudBrain"] = true jobName := form.JobName @@ -1148,6 +1180,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF return } + _, err = getBenchmarkResourceSpec(resourceSpecId) + if err != nil { + log.Error("getBenchmarkResourceSpec failed:%v", err, ctx.Data["MsgID"]) + cloudBrainNewDataPrepare(ctx) + ctx.RenderWithErr("resource spec 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"]) @@ -1186,6 +1226,8 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF return } + //todo: check the boot file(train.py&test.py) + if err := uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/"); err != nil { log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) cloudBrainNewDataPrepare(ctx) diff --git a/templates/repo/cloudbrain/benchmark/new.tmpl b/templates/repo/cloudbrain/benchmark/new.tmpl index 2be134126..a8bd056ae 100755 --- a/templates/repo/cloudbrain/benchmark/new.tmpl +++ b/templates/repo/cloudbrain/benchmark/new.tmpl @@ -129,7 +129,7 @@