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.

environ_manager.h 1.9 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 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. #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ENVIRON_MANAGER_H_
  17. #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ENVIRON_MANAGER_H_
  18. #include <utility>
  19. #include <map>
  20. #include <memory>
  21. #include <vector>
  22. #include <shared_mutex>
  23. #include "kernel/environ.h"
  24. namespace mindspore {
  25. namespace kernel {
  26. class EnvironMgr {
  27. public:
  28. static EnvironMgr &GetInstance() noexcept {
  29. static EnvironMgr instance;
  30. return instance;
  31. }
  32. // Create the env object and return the unique env handle.
  33. int64_t Create();
  34. EnvironPtr Get(int64_t handle);
  35. void Clear();
  36. // Check whether the inputs of EnvironGet kernel or EnvironSet kernel are valid.
  37. bool CheckEnvInput(const CNodePtr &kernel_node) const;
  38. // Check whether is scalar tensor. Environ handle and env key only support scalar tensor currently.
  39. bool IsScalarTensor(TypeId type, const std::vector<size_t> &shape) const;
  40. private:
  41. EnvironMgr() = default;
  42. ~EnvironMgr() = default;
  43. DISABLE_COPY_AND_ASSIGN(EnvironMgr);
  44. // Store the envs in map, as <handle, env>.
  45. std::map<int64_t, EnvironPtr> envs_;
  46. int64_t env_handles_count_{0};
  47. std::shared_mutex mutex;
  48. };
  49. } // namespace kernel
  50. } // namespace mindspore
  51. #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ENVIRON_MANAGER_H_