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 4.5 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 grampusTwoNotFinalStatuses = []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: grampusTwoNotFinalStatuses,
  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: grampusTwoNotFinalStatuses,
  60. ComputeResource: models.NPUResource,
  61. }}
  62. func GetNotFinalStatusTaskCount(uid int64, cloudbrainType int, jobType string, computeResource ...string) (int, error) {
  63. jobNewType := jobType
  64. if jobType == string(models.JobTypeSnn4imagenet) || jobType == string(models.JobTypeBrainScore) {
  65. jobNewType = string(models.JobTypeBenchmark)
  66. }
  67. key := jobNewType + "-" + strconv.Itoa(cloudbrainType)
  68. if len(computeResource) > 0 {
  69. key = key + "-" + computeResource[0]
  70. }
  71. if statusInfo, ok := StatusInfoDict[key]; ok {
  72. return models.GetNotFinalStatusTaskCount(uid, statusInfo.NotFinalStatuses, statusInfo.JobType, statusInfo.CloudBrainTypes, statusInfo.ComputeResource)
  73. } else {
  74. return 0, fmt.Errorf("Can not find the status info.")
  75. }
  76. }