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.

util.h 2.1 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright 2020 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. #ifndef MINDSPORE_CCSRC_PS_UTIL_H_
  17. #define MINDSPORE_CCSRC_PS_UTIL_H_
  18. #include <map>
  19. #include <string>
  20. #include <unordered_map>
  21. #include "backend/session/anf_runtime_algorithm.h"
  22. #include "backend/kernel_compiler/common_utils.h"
  23. #include "backend/kernel_compiler/cpu/sparse_optimizer_cpu_kernel.h"
  24. namespace mindspore {
  25. namespace ps {
  26. class Util {
  27. public:
  28. static bool IsParamServerMode();
  29. static bool IsRoleOfWorker();
  30. static bool IsRoleOfPServer();
  31. static bool IsRoleOfScheduler();
  32. static void SetInternalEnvVar();
  33. static int optimizer_id(std::string name);
  34. static std::string optimizer_name(int id);
  35. static std::string optimizer_node_name(int id);
  36. static bool is_optimizer(std::string name);
  37. static int LocalShard(int first_dim, int rank_id, int server_num);
  38. static std::map<int, int> AllRankLocalShard(int first_dim, int rank_id, int server_num);
  39. static void ReduceSparseGradient(float *gradients, int *indices, const size_t indices_size, size_t segment_size,
  40. const size_t first_dim_size, const size_t outer_dim_size,
  41. mindspore::kernel::SparseGradient<int> *unique_sparse_grad);
  42. private:
  43. static std::unordered_map<std::string, int> optimizer_to_ids;
  44. static std::unordered_map<int, std::string> id_to_optimizers;
  45. static std::unordered_map<int, std::string> id_to_optimizer_nodes;
  46. static int rank_id_;
  47. };
  48. } // namespace ps
  49. } // namespace mindspore
  50. #endif // MINDSPORE_CCSRC_PS_UTIL_H_