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.

ps_context.h 1.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_CONTEXT_H_
  17. #define MINDSPORE_CCSRC_PS_CONTEXT_H_
  18. #include <string>
  19. #include <memory>
  20. namespace mindspore {
  21. namespace ps {
  22. constexpr char kEnvRole[] = "MS_ROLE";
  23. constexpr char kEnvRoleOfPServer[] = "MS_PSERVER";
  24. constexpr char kEnvRoleOfWorker[] = "MS_WORKER";
  25. constexpr char kEnvRoleOfScheduler[] = "MS_SCHED";
  26. constexpr char kEnvRoleOfNotPS[] = "MS_NOT_PS";
  27. class PSContext {
  28. public:
  29. ~PSContext() = default;
  30. PSContext(PSContext const &) = delete;
  31. PSContext &operator=(const PSContext &) = delete;
  32. static std::shared_ptr<PSContext> instance();
  33. void SetPSEnable(bool enabled);
  34. bool is_ps_enabled() const;
  35. void Reset();
  36. std::string ms_role() const;
  37. bool is_role_worker() const;
  38. bool is_role_pserver() const;
  39. bool is_role_sched() const;
  40. void SetPSRankId(int rank_id);
  41. int ps_rank_id() const;
  42. private:
  43. PSContext() : ps_enabled_(false), is_worker_(false), is_pserver_(false), is_sched_(false), rank_id_(-1) {}
  44. bool ps_enabled_;
  45. bool is_worker_;
  46. bool is_pserver_;
  47. bool is_sched_;
  48. int rank_id_;
  49. };
  50. } // namespace ps
  51. } // namespace mindspore
  52. #endif // MINDSPORE_CCSRC_PS_CONTEXT_H_