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.

openi.go 6.1 kB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package storeLink
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "errors"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  10. "gitlink.org.cn/JointCloud/pcm-openi/common"
  11. "gitlink.org.cn/JointCloud/pcm-openi/model"
  12. "mime/multipart"
  13. "net/http"
  14. "strings"
  15. "sync"
  16. )
  17. const (
  18. DEBUG = "DEBUG"
  19. TRAIN = "TRAIN"
  20. INFERENCE = "INFERENCE"
  21. C2NET = "C2Net"
  22. TESTREPO = "testrepo"
  23. )
  24. // compute source
  25. var (
  26. ComputeSource = []string{"GPU", "NPU", "GCU", "MLU", "DCU", "CPU", "ILUVATAR-GPGPU", "METAX-GPGPU"}
  27. )
  28. type OpenI struct {
  29. participantId int64
  30. host string
  31. userName string
  32. accessToken string
  33. }
  34. func NewOpenI(host string, id int64, name string, token string) *OpenI {
  35. return &OpenI{
  36. host: host,
  37. participantId: id,
  38. userName: name,
  39. accessToken: token,
  40. }
  41. }
  42. func (o OpenI) Execute(ctx context.Context, option *option.AiOption) (interface{}, error) {
  43. return nil, errors.New("failed to implement")
  44. }
  45. func (o OpenI) GetClusterInferUrl(ctx context.Context, option *option.InferOption) (*inference.ClusterInferUrl, error) {
  46. return nil, errors.New("failed to implement")
  47. }
  48. func (o OpenI) GetInferDeployInstanceList(ctx context.Context) ([]*inference.DeployInstance, error) {
  49. return nil, errors.New("failed to implement")
  50. }
  51. func (o OpenI) StartInferDeployInstance(ctx context.Context, id string) bool {
  52. return false
  53. }
  54. func (o OpenI) StopInferDeployInstance(ctx context.Context, id string) bool {
  55. return false
  56. }
  57. func (o OpenI) GetInferDeployInstance(ctx context.Context, id string) (*inference.DeployInstance, error) {
  58. return nil, errors.New("failed to implement")
  59. }
  60. func (o OpenI) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
  61. return "", errors.New("failed to implement")
  62. }
  63. func (o OpenI) CheckModelExistence(ctx context.Context, modelName string, modelType string) bool {
  64. return false
  65. }
  66. func (o OpenI) GetImageInferResult(ctx context.Context, url string, file multipart.File, fileName string) (string, error) {
  67. return "", errors.New("failed to implement")
  68. }
  69. func (o OpenI) GetResourceStats(ctx context.Context) (*collector.ResourceStats, error) {
  70. return nil, errors.New("failed to implement")
  71. }
  72. func (o OpenI) GetDatasetsSpecs(ctx context.Context) ([]*collector.DatasetsSpecs, error) {
  73. return nil, errors.New("failed to implement")
  74. }
  75. func (o OpenI) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error) {
  76. return nil, errors.New("failed to implement")
  77. }
  78. func (o OpenI) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) {
  79. return "", errors.New("failed to implement")
  80. }
  81. func (o OpenI) GetTrainingTask(ctx context.Context, taskId string) (*collector.Task, error) {
  82. return nil, errors.New("failed to implement")
  83. }
  84. func (o OpenI) DownloadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string) (string, error) {
  85. return "", errors.New("failed to implement")
  86. }
  87. func (o OpenI) UploadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string, code string) error {
  88. return errors.New("failed to implement")
  89. }
  90. func (o OpenI) GetComputeCards(ctx context.Context) ([]string, error) {
  91. return nil, errors.New("failed to implement")
  92. }
  93. func (o OpenI) GetUserBalance(ctx context.Context) (float64, error) {
  94. return 0, errors.New("failed to implement")
  95. }
  96. func (o OpenI) GetResourceSpecs(ctx context.Context) (*collector.ResourceSpec, error) {
  97. var resources []interface{}
  98. res := &collector.ResourceSpec{
  99. ClusterId: o.participantId,
  100. }
  101. url := o.host + "/api/v1/task/creationRequired"
  102. var wg sync.WaitGroup
  103. var ch = make(chan *collector.Usage)
  104. defer close(ch)
  105. for c := range ComputeSource {
  106. wg.Add(1)
  107. i := c
  108. go func() {
  109. defer wg.Done()
  110. param := model.TaskCreationRequiredParam{
  111. UserName: o.userName,
  112. RepoName: TESTREPO,
  113. JobType: TRAIN,
  114. ComputeSource: ComputeSource[i],
  115. ClusterType: C2NET,
  116. }
  117. b, _ := json.Marshal(param)
  118. byt := bytes.NewBuffer(b)
  119. resp := struct {
  120. Code int `json:"code"`
  121. Msg string `json:"msg"`
  122. Data model.TaskCreationRequired `json:"data"`
  123. }{}
  124. req := common.GetRestyRequest(common.TIMEOUT)
  125. r, _ := http.NewRequest("GET", url, byt)
  126. req.RawRequest = r
  127. req.URL = url
  128. _, err := req.
  129. SetHeader("Content-Type", "application/json").
  130. SetQueryParam(common.ACCESSTOKEN, o.accessToken).
  131. SetBody(byt).
  132. SetResult(&resp).
  133. Send()
  134. if err != nil {
  135. return
  136. }
  137. if len(resp.Data.Data.Specs.All) == 0 {
  138. return
  139. }
  140. m := make(map[string]struct {
  141. Id int `json:"id"`
  142. AccCardsNum int `json:"acc_cards_num"`
  143. AccCardType string `json:"acc_card_type"`
  144. CpuCores int `json:"cpu_cores"`
  145. MemGiB int `json:"mem_gi_b"`
  146. GpuMemGiB int `json:"gpu_mem_gi_b"`
  147. ShareMemGiB int `json:"share_mem_gi_b"`
  148. ComputeResource string `json:"compute_resource"`
  149. UnitPrice int `json:"unit_price"`
  150. SourceSpecId string `json:"source_spec_id"`
  151. HasInternet int `json:"has_internet"`
  152. EnableVisualization bool `json:"enable_visualization"`
  153. })
  154. for _, s := range resp.Data.Data.Specs.All {
  155. e, ok := m[s.AccCardType]
  156. if ok {
  157. if s.AccCardsNum > e.AccCardsNum {
  158. m[s.AccCardType] = s
  159. }
  160. } else {
  161. m[s.AccCardType] = s
  162. }
  163. }
  164. for k, v := range m {
  165. u := &collector.Usage{
  166. Type: strings.ToUpper(k),
  167. Total: v.AccCardsNum,
  168. Available: v.AccCardsNum,
  169. }
  170. ch <- u
  171. }
  172. }()
  173. }
  174. go func() {
  175. for v := range ch {
  176. resources = append(resources, v)
  177. }
  178. }()
  179. wg.Wait()
  180. res.Resources = resources
  181. return res, nil
  182. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.