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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. TaskInfoName = "/taskInfo"
  17. SubTaskName = "task1"
  18. Success = "S000"
  19. )
  20. var (
  21. ResourceSpecs *models.ResourceSpecs
  22. )
  23. func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue string, resourceSpecId int) error {
  24. dataActualPath := setting.Attachment.Minio.RealPath +
  25. setting.Attachment.Minio.Bucket + "/" +
  26. setting.Attachment.Minio.BasePath +
  27. models.AttachmentRelativePath(uuid) +
  28. uuid
  29. var resourceSpec *models.ResourceSpec
  30. for _, spec := range ResourceSpecs.ResourceSpec {
  31. if resourceSpecId == spec.Id {
  32. resourceSpec = spec
  33. }
  34. }
  35. if resourceSpec == nil {
  36. log.Error("no such resourceSpecId(%d)", resourceSpecId, ctx.Data["MsgID"])
  37. return errors.New("no such resourceSpec")
  38. }
  39. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  40. JobName: jobName,
  41. RetryCount: 1,
  42. GpuType: gpuQueue,
  43. Image: image,
  44. TaskRoles: []models.TaskRole{
  45. {
  46. Name: SubTaskName,
  47. TaskNumber: 1,
  48. MinSucceededTaskCount: 1,
  49. MinFailedTaskCount: 1,
  50. CPUNumber: resourceSpec.CpuNum,
  51. GPUNumber: resourceSpec.GpuNum,
  52. MemoryMB: resourceSpec.MemMiB,
  53. ShmMB: resourceSpec.ShareMemMiB,
  54. Command: command,
  55. NeedIBDevice: false,
  56. IsMainRole: false,
  57. UseNNI: false,
  58. },
  59. },
  60. Volumes: []models.Volume{
  61. {
  62. HostPath: models.StHostPath{
  63. Path: codePath,
  64. MountPath: CodeMountPath,
  65. ReadOnly: false,
  66. },
  67. },
  68. {
  69. HostPath: models.StHostPath{
  70. Path: dataActualPath,
  71. MountPath: DataSetMountPath,
  72. ReadOnly: true,
  73. },
  74. },
  75. {
  76. HostPath: models.StHostPath{
  77. Path: modelPath,
  78. MountPath: ModelMountPath,
  79. ReadOnly: false,
  80. },
  81. },
  82. {
  83. HostPath: models.StHostPath{
  84. Path: benchmarkPath,
  85. MountPath: BenchMarkMountPath,
  86. ReadOnly: true,
  87. },
  88. },
  89. {
  90. HostPath: models.StHostPath{
  91. Path: snn4imagenetPath,
  92. MountPath: Snn4imagenetMountPath,
  93. ReadOnly: true,
  94. },
  95. },
  96. },
  97. })
  98. if err != nil {
  99. log.Error("CreateJob failed:", err.Error())
  100. return err
  101. }
  102. if jobResult.Code != Success {
  103. log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
  104. return errors.New(jobResult.Msg)
  105. }
  106. var jobID = jobResult.Payload["jobId"].(string)
  107. err = models.CreateCloudbrain(&models.Cloudbrain{
  108. Status: string(models.JobWaiting),
  109. UserID: ctx.User.ID,
  110. RepoID: ctx.Repo.Repository.ID,
  111. JobID: jobID,
  112. JobName: jobName,
  113. SubTaskName: SubTaskName,
  114. JobType: jobType,
  115. Type: models.TypeCloudBrainOne,
  116. })
  117. if err != nil {
  118. return err
  119. }
  120. return nil
  121. }