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.

aiService.go 5.7 kB

11 months ago
8 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package service
  2. import (
  3. "github.com/zeromicro/go-zero/zrpc"
  4. hpcacclient "gitlink.org.cn/JointCloud/pcm-ac/hpcacclient"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/config"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/database"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/executor"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  12. "gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
  13. "gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
  14. "gitlink.org.cn/JointCloud/pcm-octopus/octopusclient"
  15. "strconv"
  16. "sync"
  17. )
  18. const (
  19. OCTOPUS = "octopus"
  20. MODELARTS = "modelarts"
  21. SHUGUANGAI = "shuguangAi"
  22. OPENI = "openI"
  23. )
  24. type AiService struct {
  25. AiExecutorAdapterMap map[string]map[string]executor.AiExecutor
  26. AiCollectorAdapterMap map[string]map[string]collector.AiCollector
  27. InferenceAdapterMap map[string]map[string]inference.ICluster
  28. Storage *database.AiStorage
  29. LocalCache map[string]interface{}
  30. Conf *config.Config
  31. TaskSyncLock sync.Mutex
  32. }
  33. func NewAiService(conf *config.Config, storages *database.AiStorage, localCache map[string]interface{}) (*AiService, error) {
  34. var aiType = "1"
  35. adapterIds, err := storages.GetAdapterIdsByType(aiType)
  36. if err != nil {
  37. return nil, err
  38. }
  39. aiService := &AiService{
  40. AiExecutorAdapterMap: make(map[string]map[string]executor.AiExecutor),
  41. AiCollectorAdapterMap: make(map[string]map[string]collector.AiCollector),
  42. InferenceAdapterMap: make(map[string]map[string]inference.ICluster),
  43. Storage: storages,
  44. LocalCache: localCache,
  45. Conf: conf,
  46. }
  47. for _, id := range adapterIds {
  48. clusters, err := storages.GetClustersByAdapterId(id)
  49. if err != nil {
  50. return nil, err
  51. }
  52. if len(clusters.List) == 0 {
  53. continue
  54. }
  55. exeClusterMap, colClusterMap, inferMap := InitAiClusterMap(conf, clusters.List)
  56. aiService.AiExecutorAdapterMap[id] = exeClusterMap
  57. aiService.AiCollectorAdapterMap[id] = colClusterMap
  58. aiService.InferenceAdapterMap[id] = inferMap
  59. }
  60. return aiService, nil
  61. }
  62. func InitAiClusterMap(conf *config.Config, clusters []types.ClusterInfo) (map[string]executor.AiExecutor, map[string]collector.AiCollector, map[string]inference.ICluster) {
  63. executorMap := make(map[string]executor.AiExecutor)
  64. collectorMap := make(map[string]collector.AiCollector)
  65. inferenceMap := make(map[string]inference.ICluster)
  66. for _, c := range clusters {
  67. switch c.Name {
  68. case OCTOPUS:
  69. id, _ := strconv.ParseInt(c.Id, 10, 64)
  70. octopusRpc := octopusclient.NewOctopus(zrpc.MustNewClient(conf.OctopusRpcConf))
  71. octopus := storeLink.NewOctopusLink(octopusRpc, c.Nickname, id)
  72. collectorMap[c.Id] = octopus
  73. executorMap[c.Id] = octopus
  74. inferenceMap[c.Id] = octopus
  75. case MODELARTS:
  76. id, _ := strconv.ParseInt(c.Id, 10, 64)
  77. modelArtsRpc := modelartsservice.NewModelArtsService(zrpc.MustNewClient(conf.ModelArtsRpcConf))
  78. modelArtsImgRpc := imagesservice.NewImagesService(zrpc.MustNewClient(conf.ModelArtsImgRpcConf))
  79. modelarts := storeLink.NewModelArtsLink(modelArtsRpc, modelArtsImgRpc, c.Name, id, c.Nickname)
  80. collectorMap[c.Id] = modelarts
  81. executorMap[c.Id] = modelarts
  82. inferenceMap[c.Id] = modelarts
  83. case SHUGUANGAI:
  84. id, _ := strconv.ParseInt(c.Id, 10, 64)
  85. aCRpc := hpcacclient.NewHpcAC(zrpc.MustNewClient(conf.ACRpcConf))
  86. sgai := storeLink.NewShuguangAi(aCRpc, c.Nickname, id)
  87. collectorMap[c.Id] = sgai
  88. executorMap[c.Id] = sgai
  89. inferenceMap[c.Id] = sgai
  90. case OPENI:
  91. id, _ := strconv.ParseInt(c.Id, 10, 64)
  92. openi := storeLink.NewOpenI(c.Server, id, c.Username, c.Token)
  93. collectorMap[c.Id] = openi
  94. executorMap[c.Id] = openi
  95. inferenceMap[c.Id] = openi
  96. }
  97. }
  98. return executorMap, collectorMap, inferenceMap
  99. }
  100. func (as *AiService) UpdateClusterMaps(conf *config.Config, adapterId string, clusters []types.ClusterInfo) {
  101. for _, c := range clusters {
  102. _, ok := as.AiExecutorAdapterMap[adapterId][c.Id]
  103. _, ok2 := as.AiCollectorAdapterMap[adapterId][c.Id]
  104. _, ok3 := as.InferenceAdapterMap[adapterId][c.Id]
  105. if !ok && !ok2 && !ok3 {
  106. switch c.Name {
  107. case OCTOPUS:
  108. id, _ := strconv.ParseInt(c.Id, 10, 64)
  109. octopusRpc := octopusclient.NewOctopus(zrpc.MustNewClient(conf.OctopusRpcConf))
  110. octopus := storeLink.NewOctopusLink(octopusRpc, c.Nickname, id)
  111. as.AiExecutorAdapterMap[adapterId][c.Id] = octopus
  112. as.AiCollectorAdapterMap[adapterId][c.Id] = octopus
  113. as.InferenceAdapterMap[adapterId][c.Id] = octopus
  114. case MODELARTS:
  115. id, _ := strconv.ParseInt(c.Id, 10, 64)
  116. modelArtsRpc := modelartsservice.NewModelArtsService(zrpc.MustNewClient(conf.ModelArtsRpcConf))
  117. modelArtsImgRpc := imagesservice.NewImagesService(zrpc.MustNewClient(conf.ModelArtsImgRpcConf))
  118. modelarts := storeLink.NewModelArtsLink(modelArtsRpc, modelArtsImgRpc, c.Name, id, c.Nickname)
  119. as.AiExecutorAdapterMap[adapterId][c.Id] = modelarts
  120. as.AiCollectorAdapterMap[adapterId][c.Id] = modelarts
  121. as.InferenceAdapterMap[adapterId][c.Id] = modelarts
  122. case SHUGUANGAI:
  123. id, _ := strconv.ParseInt(c.Id, 10, 64)
  124. aCRpc := hpcacclient.NewHpcAC(zrpc.MustNewClient(conf.ACRpcConf))
  125. sgai := storeLink.NewShuguangAi(aCRpc, c.Nickname, id)
  126. as.AiExecutorAdapterMap[adapterId][c.Id] = sgai
  127. as.AiCollectorAdapterMap[adapterId][c.Id] = sgai
  128. as.InferenceAdapterMap[adapterId][c.Id] = sgai
  129. }
  130. } else {
  131. continue
  132. }
  133. }
  134. }

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.