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.

rt_kernel_info.h 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Copyright 2019 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_KERNEL_MNG_RT_KERNEL_INFO_H
  17. #define MINDSPORE_CCSRC_KERNEL_MNG_RT_KERNEL_INFO_H
  18. #include <memory>
  19. #include <functional>
  20. #include <map>
  21. #include <string>
  22. #include <set>
  23. #include <vector>
  24. #include <utility>
  25. #include "ir/dtype.h"
  26. #include "kernel/kernel_build_info.h"
  27. #include "kernel/kernel.h"
  28. #include "utils/utils.h"
  29. namespace mindspore {
  30. namespace kernel {
  31. class RtKerDesc {
  32. public:
  33. virtual ~RtKerDesc() {}
  34. virtual std::vector<std::shared_ptr<kernel::KernelBuildInfo>> GetKernelInfo() {
  35. return std::vector<std::shared_ptr<kernel::KernelBuildInfo>>{};
  36. }
  37. };
  38. using RtKerDescCreater = std::function<std::shared_ptr<RtKerDesc>()>;
  39. class RtKerDescFactory {
  40. RtKerDescFactory() = default;
  41. ~RtKerDescFactory() = default;
  42. public:
  43. static RtKerDescFactory &Get();
  44. void Register(const std::string &name, RtKerDescCreater &&fun);
  45. static std::shared_ptr<RtKerDesc> Create(const std::string &name);
  46. private:
  47. std::map<std::string, RtKerDescCreater> fmap_;
  48. };
  49. class _RtKerDescRegister {
  50. public:
  51. _RtKerDescRegister(const std::string &name, RtKerDescCreater &&fun) {
  52. RtKerDescFactory::Get().Register(name, std::move(fun));
  53. }
  54. ~_RtKerDescRegister() = default;
  55. };
  56. #define _MS_REG_RTKERNEL_DESC_REG(KNAME, clazz) \
  57. static_assert(std::is_base_of<RtKerDesc, clazz>::value, " must be base of RtKerDesc"); \
  58. static const _RtKerDescRegister g_##KNAME##_##_rtkernel_desc_reg(#KNAME, []() { return std::make_shared<clazz>(); });
  59. #define MS_REG_RTKERNEL_DESC(KNAME, clazz) _MS_REG_RTKERNEL_DESC_REG(KNAME, clazz)
  60. void GetRtKelInfo(const CNodePtr &kernel_node, std::vector<std::shared_ptr<kernel::KernelBuildInfo>> *kernel_info_list);
  61. } // namespace kernel
  62. } // namespace mindspore
  63. #endif // MINDSPORE_CCSRC_KERNEL_MNG_RT_KERNEL_INFO_H