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.

cloudbrain.go 3.5 kB

5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package cloudbrain
  2. import (
  3. "code.gitea.io/gitea/modules/setting"
  4. "errors"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. const (
  10. Command = `pip3 install jupyterlab==2.2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple;service ssh stop;jupyter lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir="/code" --port=80 --LabApp.token="" --LabApp.allow_origin="self https://cloudbrain.pcl.ac.cn"`
  11. CodeMountPath = "/code"
  12. DataSetMountPath = "/dataset"
  13. ModelMountPath = "/model"
  14. BenchMarkMountPath = "/benchmark"
  15. Snn4imagenetMountPath = "/snn4imagenet"
  16. BrainScoreMountPath = "/brainscore"
  17. TaskInfoName = "/taskInfo"
  18. SubTaskName = "task1"
  19. Success = "S000"
  20. )
  21. var (
  22. ResourceSpecs *models.ResourceSpecs
  23. )
  24. func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue string, resourceSpecId int) error {
  25. dataActualPath := setting.Attachment.Minio.RealPath +
  26. setting.Attachment.Minio.Bucket + "/" +
  27. setting.Attachment.Minio.BasePath +
  28. models.AttachmentRelativePath(uuid) +
  29. uuid
  30. var resourceSpec *models.ResourceSpec
  31. for _, spec := range ResourceSpecs.ResourceSpec {
  32. if resourceSpecId == spec.Id {
  33. resourceSpec = spec
  34. }
  35. }
  36. if resourceSpec == nil {
  37. log.Error("no such resourceSpecId(%d)", resourceSpecId, ctx.Data["MsgID"])
  38. return errors.New("no such resourceSpec")
  39. }
  40. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  41. JobName: jobName,
  42. RetryCount: 1,
  43. GpuType: gpuQueue,
  44. Image: image,
  45. TaskRoles: []models.TaskRole{
  46. {
  47. Name: SubTaskName,
  48. TaskNumber: 1,
  49. MinSucceededTaskCount: 1,
  50. MinFailedTaskCount: 1,
  51. CPUNumber: resourceSpec.CpuNum,
  52. GPUNumber: resourceSpec.GpuNum,
  53. MemoryMB: resourceSpec.MemMiB,
  54. ShmMB: resourceSpec.ShareMemMiB,
  55. Command: command,
  56. NeedIBDevice: false,
  57. IsMainRole: false,
  58. UseNNI: false,
  59. },
  60. },
  61. Volumes: []models.Volume{
  62. {
  63. HostPath: models.StHostPath{
  64. Path: codePath,
  65. MountPath: CodeMountPath,
  66. ReadOnly: false,
  67. },
  68. },
  69. {
  70. HostPath: models.StHostPath{
  71. Path: dataActualPath,
  72. MountPath: DataSetMountPath,
  73. ReadOnly: true,
  74. },
  75. },
  76. {
  77. HostPath: models.StHostPath{
  78. Path: modelPath,
  79. MountPath: ModelMountPath,
  80. ReadOnly: false,
  81. },
  82. },
  83. {
  84. HostPath: models.StHostPath{
  85. Path: benchmarkPath,
  86. MountPath: BenchMarkMountPath,
  87. ReadOnly: true,
  88. },
  89. },
  90. {
  91. HostPath: models.StHostPath{
  92. Path: snn4imagenetPath,
  93. MountPath: Snn4imagenetMountPath,
  94. ReadOnly: true,
  95. },
  96. },
  97. },
  98. })
  99. if err != nil {
  100. log.Error("CreateJob failed:", err.Error())
  101. return err
  102. }
  103. if jobResult.Code != Success {
  104. log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
  105. return errors.New(jobResult.Msg)
  106. }
  107. var jobID = jobResult.Payload["jobId"].(string)
  108. err = models.CreateCloudbrain(&models.Cloudbrain{
  109. Status: string(models.JobWaiting),
  110. UserID: ctx.User.ID,
  111. RepoID: ctx.Repo.Repository.ID,
  112. JobID: jobID,
  113. JobName: jobName,
  114. SubTaskName: SubTaskName,
  115. JobType: jobType,
  116. Type: models.TypeCloudBrainOne,
  117. })
  118. if err != nil {
  119. return err
  120. }
  121. return nil
  122. }