You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

count.go 5.4 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package cloudbrainTask
  2. import (
  3. "fmt"
  4. "strconv"
  5. "code.gitea.io/gitea/models"
  6. )
  7. type StatusInfo struct {
  8. CloudBrainTypes []int
  9. JobType []models.JobType
  10. NotFinalStatuses []string
  11. ComputeResource string
  12. }
  13. var CloudbrainOneNotFinalStatuses = []string{string(models.JobWaiting), string(models.JobRunning)}
  14. var CloudbrainTwoNotFinalStatuses = []string{string(models.ModelArtsTrainJobInit), string(models.ModelArtsTrainJobImageCreating), string(models.ModelArtsTrainJobSubmitTrying), string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobRunning), string(models.ModelArtsTrainJobScaling), string(models.ModelArtsTrainJobCheckInit), string(models.ModelArtsTrainJobCheckRunning), string(models.ModelArtsTrainJobCheckRunningCompleted)}
  15. var GrampusNotFinalStatuses = []string{models.GrampusStatusWaiting, models.GrampusStatusRunning}
  16. var StatusInfoDict = map[string]StatusInfo{string(models.JobTypeDebug) + "-" + strconv.Itoa(models.TypeCloudBrainOne): {
  17. CloudBrainTypes: []int{models.TypeCloudBrainOne},
  18. JobType: []models.JobType{models.JobTypeDebug},
  19. NotFinalStatuses: CloudbrainOneNotFinalStatuses,
  20. ComputeResource: models.GPUResource,
  21. }, string(models.JobTypeTrain) + "-" + strconv.Itoa(models.TypeCloudBrainOne): {
  22. CloudBrainTypes: []int{models.TypeCloudBrainOne},
  23. JobType: []models.JobType{models.JobTypeTrain},
  24. NotFinalStatuses: CloudbrainOneNotFinalStatuses,
  25. ComputeResource: models.GPUResource,
  26. }, string(models.JobTypeInference) + "-" + strconv.Itoa(models.TypeCloudBrainOne): {
  27. CloudBrainTypes: []int{models.TypeCloudBrainOne},
  28. JobType: []models.JobType{models.JobTypeInference},
  29. NotFinalStatuses: CloudbrainOneNotFinalStatuses,
  30. ComputeResource: models.GPUResource,
  31. }, string(models.JobTypeBenchmark) + "-" + strconv.Itoa(models.TypeCloudBrainOne): {
  32. CloudBrainTypes: []int{models.TypeCloudBrainOne},
  33. JobType: []models.JobType{models.JobTypeBenchmark, models.JobTypeBrainScore, models.JobTypeSnn4imagenet},
  34. NotFinalStatuses: CloudbrainOneNotFinalStatuses,
  35. ComputeResource: models.GPUResource,
  36. }, string(models.JobTypeDebug) + "-" + strconv.Itoa(models.TypeCloudBrainTwo): {
  37. CloudBrainTypes: []int{models.TypeCloudBrainTwo, models.TypeCDCenter},
  38. JobType: []models.JobType{models.JobTypeDebug},
  39. NotFinalStatuses: []string{string(models.ModelArtsCreateQueue), string(models.ModelArtsCreating), string(models.ModelArtsStarting), string(models.ModelArtsReadyToStart), string(models.ModelArtsResizing), string(models.ModelArtsStartQueuing), string(models.ModelArtsRunning), string(models.ModelArtsRestarting)},
  40. ComputeResource: models.NPUResource,
  41. }, string(models.JobTypeTrain) + "-" + strconv.Itoa(models.TypeCloudBrainTwo): {
  42. CloudBrainTypes: []int{models.TypeCloudBrainTwo},
  43. JobType: []models.JobType{models.JobTypeTrain},
  44. NotFinalStatuses: CloudbrainTwoNotFinalStatuses,
  45. ComputeResource: models.NPUResource,
  46. }, string(models.JobTypeInference) + "-" + strconv.Itoa(models.TypeCloudBrainTwo): {
  47. CloudBrainTypes: []int{models.TypeCloudBrainTwo},
  48. JobType: []models.JobType{models.JobTypeInference},
  49. NotFinalStatuses: CloudbrainTwoNotFinalStatuses,
  50. ComputeResource: models.NPUResource,
  51. }, string(models.JobTypeTrain) + "-" + strconv.Itoa(models.TypeC2Net) + "-" + models.GPUResource: {
  52. CloudBrainTypes: []int{models.TypeC2Net},
  53. JobType: []models.JobType{models.JobTypeTrain},
  54. NotFinalStatuses: GrampusNotFinalStatuses,
  55. ComputeResource: models.GPUResource,
  56. }, string(models.JobTypeTrain) + "-" + strconv.Itoa(models.TypeC2Net) + "-" + models.NPUResource: {
  57. CloudBrainTypes: []int{models.TypeC2Net},
  58. JobType: []models.JobType{models.JobTypeTrain},
  59. NotFinalStatuses: GrampusNotFinalStatuses,
  60. ComputeResource: models.NPUResource,
  61. }, string(models.JobTypeDebug) + "-" + strconv.Itoa(models.TypeC2Net) + "-" + models.GPUResource: {
  62. CloudBrainTypes: []int{models.TypeC2Net},
  63. JobType: []models.JobType{models.JobTypeDebug},
  64. NotFinalStatuses: GrampusNotFinalStatuses,
  65. ComputeResource: models.GPUResource,
  66. }, string(models.JobTypeDebug) + "-" + strconv.Itoa(models.TypeC2Net) + "-" + models.NPUResource: {
  67. CloudBrainTypes: []int{models.TypeC2Net},
  68. JobType: []models.JobType{models.JobTypeDebug},
  69. NotFinalStatuses: GrampusNotFinalStatuses,
  70. ComputeResource: models.NPUResource,
  71. }, string(models.JobTypeDebug) + "-" + strconv.Itoa(models.TypeC2Net) + "-" + models.GCUResource: {
  72. CloudBrainTypes: []int{models.TypeC2Net},
  73. JobType: []models.JobType{models.JobTypeDebug},
  74. NotFinalStatuses: GrampusNotFinalStatuses,
  75. ComputeResource: models.GCUResource,
  76. }}
  77. func GetNotFinalStatusTaskCount(uid int64, cloudbrainType int, jobType string, computeResource ...string) (int, error) {
  78. jobNewType := jobType
  79. if jobType == string(models.JobTypeSnn4imagenet) || jobType == string(models.JobTypeBrainScore) {
  80. jobNewType = string(models.JobTypeBenchmark)
  81. }
  82. key := jobNewType + "-" + strconv.Itoa(cloudbrainType)
  83. if len(computeResource) > 0 && cloudbrainType == models.TypeC2Net {
  84. key = key + "-" + computeResource[0]
  85. }
  86. if statusInfo, ok := StatusInfoDict[key]; ok {
  87. return models.GetNotFinalStatusTaskCount(uid, statusInfo.NotFinalStatuses, statusInfo.JobType, statusInfo.CloudBrainTypes, statusInfo.ComputeResource)
  88. } else {
  89. return 0, fmt.Errorf("Can not find the status info.")
  90. }
  91. }