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.cc 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "kernel/mng/rt_kernel_info.h"
  17. #include <unordered_map>
  18. #include <algorithm>
  19. #include "utils/convert_utils.h"
  20. #include "utils/utils.h"
  21. #include "common/utils.h"
  22. #include "session/anf_runtime_algorithm.h"
  23. namespace mindspore {
  24. namespace kernel {
  25. void RtKerDescFactory::Register(const std::string &name, RtKerDescCreater &&fun) {
  26. if (fmap_.find(name) == fmap_.end()) {
  27. (void)fmap_.emplace(name, std::move(fun));
  28. }
  29. }
  30. std::shared_ptr<RtKerDesc> RtKerDescFactory::Create(const std::string &name) {
  31. const auto &map = Get().fmap_;
  32. auto it = map.find(name);
  33. if (it != map.end() && it->second) {
  34. return (it->second)();
  35. }
  36. return nullptr;
  37. }
  38. RtKerDescFactory &RtKerDescFactory::Get() {
  39. static RtKerDescFactory _this;
  40. return _this;
  41. }
  42. void GetRtKelInfo(const CNodePtr &kernel_node,
  43. std::vector<std::shared_ptr<kernel::KernelBuildInfo>> *kernel_info_list) {
  44. MS_LOG(INFO) << "Mng kernel Info.";
  45. MS_EXCEPTION_IF_NULL(kernel_info_list);
  46. MS_EXCEPTION_IF_NULL(kernel_node);
  47. std::string opNameLower = AnfAlgo::GetCNodeName(kernel_node);
  48. (void)std::transform(opNameLower.begin(), opNameLower.end(), opNameLower.begin(), ::tolower);
  49. auto ker_desc_ptr = RtKerDescFactory::Create(opNameLower);
  50. if (ker_desc_ptr == nullptr) {
  51. MS_LOG(DEBUG) << "Mng can't find op [" << opNameLower << "].";
  52. return;
  53. }
  54. MS_EXCEPTION_IF_NULL(ker_desc_ptr);
  55. auto kernel_info = ker_desc_ptr->GetKernelInfo();
  56. if (kernel_info.empty()) {
  57. MS_LOG(DEBUG) << "Rt dose not have op [" << opNameLower << "].";
  58. return;
  59. }
  60. *kernel_info_list = kernel_info;
  61. }
  62. } // namespace kernel
  63. } // namespace mindspore