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

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.