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