@@ -119,6 +119,10 @@ const ( | |||||
//AI center | //AI center | ||||
AICenterOfCloudBrainOne = "OpenIOne" | AICenterOfCloudBrainOne = "OpenIOne" | ||||
AICenterOfCloudBrainTwo = "OpenITwo" | AICenterOfCloudBrainTwo = "OpenITwo" | ||||
//ComputeResource | |||||
GPU = "GPU" | |||||
NPU = "NPU" | |||||
) | ) | ||||
type Cloudbrain struct { | type Cloudbrain struct { | ||||
@@ -141,6 +141,37 @@ func (r ResourceSpecAndQueue) ConvertToRes() *ResourceSpecAndQueueRes { | |||||
} | } | ||||
} | } | ||||
type FindSpecsOptions struct { | |||||
JobType JobType | |||||
ComputeResource string | |||||
Cluster string | |||||
AiCenterCode string | |||||
} | |||||
type Specification struct { | |||||
ID int64 | |||||
SourceSpecId string | |||||
AccCardsNum int | |||||
AccCardType string | |||||
CpuCores int | |||||
MemGiB float32 | |||||
GPUMemGiB float32 | |||||
ShareMemGiB float32 | |||||
ComputeResource string | |||||
UnitPrice int | |||||
QueueId int64 | |||||
QueueCode string | |||||
Cluster string | |||||
AiCenterCode string | |||||
AiCenterName string | |||||
IsExclusive bool | |||||
ExclusiveOrg string | |||||
} | |||||
func (Specification) TableName() string { | |||||
return "resource_specification" | |||||
} | |||||
func InsertResourceSpecification(r ResourceSpecification) (int64, error) { | func InsertResourceSpecification(r ResourceSpecification) (int64, error) { | ||||
return x.Insert(&r) | return x.Insert(&r) | ||||
} | } | ||||
@@ -283,3 +314,32 @@ func SyncGrampusSpecs(updateList []ResourceSpecification, insertList []ResourceS | |||||
return sess.Commit() | return sess.Commit() | ||||
} | } | ||||
func FindAvailableSpecs(opts FindSpecsOptions) ([]Specification, error) { | |||||
var cond = builder.NewCond() | |||||
if opts.JobType != "" { | |||||
cond = cond.And(builder.Eq{"resource_scene.job_type": opts.JobType}) | |||||
} | |||||
if opts.ComputeResource != "" { | |||||
cond = cond.And(builder.Eq{"resource_queue.compute_resource": opts.ComputeResource}) | |||||
} | |||||
if opts.ComputeResource != "" { | |||||
cond = cond.And(builder.Eq{"resource_queue.cluster": opts.Cluster}) | |||||
} | |||||
if opts.AiCenterCode != "" { | |||||
cond = cond.And(builder.Eq{"resource_queue.ai_center_code": opts.AiCenterCode}) | |||||
} | |||||
cond = cond.And(builder.Or(builder.Eq{"resource_scene.delete_time": 0}, builder.IsNull{"resource_scene.delete_time"})) | |||||
r := make([]Specification, 0) | |||||
err := x.Where(cond). | |||||
Join("INNER", "resource_scene_spec", "resource_scene_spec.spec_id = resource_specification.id"). | |||||
Join("INNER", "resource_scene", "resource_scene_spec.scene_id = resource_scene.id"). | |||||
Join("INNER", "resource_queue", "resource_queue.id = resource_specification.queue_id"). | |||||
OrderBy("resource_queue.compute_resource asc,resource_queue.acc_card_type asc,resource_specification.acc_cards_num asc"). | |||||
Unscoped().Find(&r) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
return r, nil | |||||
} |
@@ -2,6 +2,7 @@ package repo | |||||
import ( | import ( | ||||
"bufio" | "bufio" | ||||
"code.gitea.io/gitea/services/cloudbrain/resource" | |||||
"encoding/json" | "encoding/json" | ||||
"errors" | "errors" | ||||
"fmt" | "fmt" | ||||
@@ -166,6 +167,13 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { | |||||
if cloudbrain.InferenceResourceSpecs != nil { | if cloudbrain.InferenceResourceSpecs != nil { | ||||
ctx.Data["inference_resource_specs"] = cloudbrain.InferenceResourceSpecs.ResourceSpec | ctx.Data["inference_resource_specs"] = cloudbrain.InferenceResourceSpecs.ResourceSpec | ||||
} | } | ||||
specs, _ := resource.FindAvailableSpecs(ctx.User.ID, models.FindSpecsOptions{ | |||||
JobType: models.JobTypeDebug, | |||||
ComputeResource: models.GPU, | |||||
Cluster: models.OpenICluster, | |||||
AiCenterCode: models.AICenterOfCloudBrainOne, | |||||
}) | |||||
ctx.Data["Specs"] = specs | |||||
if cloudbrain.SpecialPools != nil { | if cloudbrain.SpecialPools != nil { | ||||
var debugGpuTypes []*models.GpuInfo | var debugGpuTypes []*models.GpuInfo | ||||
@@ -184,3 +184,28 @@ func AddSpecOperateLog(doerId int64, operateType string, newValue, oldValue *mod | |||||
Comment: comment, | Comment: comment, | ||||
}) | }) | ||||
} | } | ||||
func FindAvailableSpecs(userId int64, opts models.FindSpecsOptions) ([]models.Specification, error) { | |||||
r, err := models.FindAvailableSpecs(opts) | |||||
if err != nil { | |||||
log.Error("FindAvailableSpecs error.%v", err) | |||||
return nil, err | |||||
} | |||||
specs := make([]models.Specification, 0, len(r)) | |||||
//filter exclusive spec | |||||
for i := 0; i < len(r); i++ { | |||||
spec := r[i] | |||||
if !spec.IsExclusive { | |||||
specs = append(specs, spec) | |||||
continue | |||||
} | |||||
orgs := strings.Split(spec.ExclusiveOrg, ";") | |||||
for _, org := range orgs { | |||||
isMember, _ := models.IsOrganizationMemberByOrgName(org, userId) | |||||
if isMember { | |||||
specs = append(specs, spec) | |||||
} | |||||
} | |||||
} | |||||
return specs, err | |||||
} |