Browse Source

Merge branch 'benchmark' of https://git.openi.org.cn/OpenI/aiforge into benchmark

pull/1405/head
zouap 3 years ago
parent
commit
54abf56f10
3 changed files with 52 additions and 8 deletions
  1. +9
    -7
      modules/setting/setting.go
  2. +42
    -0
      routers/repo/cloudbrain.go
  3. +1
    -1
      templates/repo/cloudbrain/benchmark/new.tmpl

+ 9
- 7
modules/setting/setting.go View File

@@ -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)


+ 42
- 0
routers/repo/cloudbrain.go View File

@@ -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)


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

@@ -129,7 +129,7 @@
<div class="required unite min_title inline field">
<label style="font-weight: normal;">资源规格</label>
<select id="cloudbrain_resource_spec" class="ui search dropdown" placeholder="选择资源规格" style='width:385px' name="resource_spec_id">
{{range .resource_specs}}
{{range .benchmark_resource_specs}}
<option name="resource_spec_id" value="{{.Id}}">GPU数:{{.GpuNum}},CPU数:{{.CpuNum}},内存(MB):{{.MemMiB}},共享内存(MB):{{.ShareMemMiB}}</option>
{{end}}
</select>


Loading…
Cancel
Save