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.

getcomputingpowerlogic.go 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package core
  13. import (
  14. "context"
  15. "github.com/zeromicro/go-zero/core/logx"
  16. "gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  19. "gitlink.org.cn/JointCloud/pcm-octopus/octopus"
  20. "log"
  21. )
  22. type GetComputingPowerLogic struct {
  23. logx.Logger
  24. ctx context.Context
  25. svcCtx *svc.ServiceContext
  26. }
  27. func NewGetComputingPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputingPowerLogic {
  28. return &GetComputingPowerLogic{
  29. Logger: logx.WithContext(ctx),
  30. ctx: ctx,
  31. svcCtx: svcCtx,
  32. }
  33. }
  34. type client struct {
  35. }
  36. func (c *client) getComputingPower(cp computingPower, l *GetComputingPowerLogic) float32 {
  37. return cp.GetComputing(l)
  38. }
  39. type OctopusComputingPower struct {
  40. }
  41. type AcComputingPower struct {
  42. }
  43. type computingPower interface {
  44. GetComputing(l *GetComputingPowerLogic) float32
  45. }
  46. // 启智章鱼资源算力
  47. func (cp OctopusComputingPower) GetComputing(l *GetComputingPowerLogic) float32 {
  48. octopusCpReq := &octopus.ResourceReq{}
  49. octopusCpResp, err := l.svcCtx.OctopusRpc.GetComputingPower(l.ctx, octopusCpReq)
  50. if err != nil {
  51. log.Println("OctopusRpc 算力请求失败", err)
  52. }
  53. return octopusCpResp.POpsAtFp16
  54. }
  55. // 曙光账号算力
  56. func (cp AcComputingPower) GetComputing(l *GetComputingPowerLogic) float32 {
  57. acCpReq := &hpcAC.ResourceReq{}
  58. acCpResp, err := l.svcCtx.ACRpc.GetComputingPower(l.ctx, acCpReq)
  59. if err != nil {
  60. log.Println("ACRpc 算力请求失败", err)
  61. }
  62. return acCpResp.POpsAtFp16
  63. }
  64. func (l *GetComputingPowerLogic) GetComputingPower() (resp *types.CpResp, err error) {
  65. apiResp := types.CpResp{}
  66. c := client{}
  67. ot := OctopusComputingPower{}
  68. ac := AcComputingPower{}
  69. a := c.getComputingPower(ot, l)
  70. b := c.getComputingPower(ac, l)
  71. apiResp.POpsAtFp16 = a + b
  72. ////启智章鱼资源算力
  73. //octopusCpReq := &octopus.ResourceReq{}
  74. //octopusCpResp, err := l.svcCtx.OctopusRpc.GetComputingPower(l.ctx, octopusCpReq)
  75. //if err != nil {
  76. // log.Println("OctopusRpc 算力请求失败", err)
  77. //}
  78. //
  79. ////曙光账号算力
  80. //acCpReq := &hpcAC.ResourceReq{}
  81. //acCpResp, err := l.svcCtx.ACRpc.GetComputingPower(l.ctx, acCpReq)
  82. //if err != nil {
  83. // log.Println("ACRpc 算力请求失败", err)
  84. //}
  85. //
  86. //computingPowerAggregated := acCpResp.POpsAtFp16 + octopusCpResp.POpsAtFp16
  87. //apiResp.POpsAtFp16 = computingPowerAggregated
  88. return &apiResp, nil
  89. }

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.