• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_PS_UTIL_H_
18 #define MINDSPORE_CCSRC_PS_UTIL_H_
19 
20 #include <map>
21 #include <memory>
22 #include <vector>
23 #include <string>
24 #include "utils/hash_map.h"
25 #include "include/backend/distributed/ps/constants.h"
26 #include "include/backend/anf_runtime_algorithm.h"
27 #include "include/common/utils/anfalgo.h"
28 #include "kernel/common_utils.h"
29 #include "include/backend/visible.h"
30 
31 namespace mindspore {
32 namespace ps {
33 constexpr size_t kNodeInputWeightNameOffset = 1;
34 constexpr size_t kNodeInputWeightIndexOffset = 2;
35 
36 class BACKEND_EXPORT Util {
37  public:
38   static bool IsRoleOfPServer();
39   static bool IsRoleOfScheduler();
40   static int64_t optimizer_id(const std::string &name);
41   static std::string optimizer_name(int64_t id);
42   static std::string optimizer_node_name(int64_t id);
43   static bool is_optimizer(const std::string &name);
44   static int64_t LocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num);
45   static std::map<int64_t, int64_t> AllRankLocalShard(int64_t first_dim, int64_t rank_id, int64_t server_num);
46   static bool FuseServerCommOps(const FuncGraphPtr &func_graph);
47   static WeightPtr MakeWeightPtr(const std::shared_ptr<std::vector<float>> &data, bool enable_recovery,
48                                  const std::shared_ptr<std::vector<int>> &shape = nullptr);
49   static std::string GetPrimitiveName(const CNodePtr &cnode);
50 
51  private:
52   static void DoFusion(const FuncGraphPtr &func_graph, const std::string &cnode_name,
53                        const std::string &fused_cnode_name);
54   static kernel::KernelBuildInfoPtr GenerateKernelBuildInfo(const std::vector<AnfNodePtr> &node_list);
55 };
56 }  // namespace ps
57 }  // namespace mindspore
58 #endif  // MINDSPORE_CCSRC_PS_UTIL_H_
59