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.

aicpu_kernel_metadata.cc 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "kernel/aicpu/aicpu_kernel_metadata.h"
  17. #include <memory>
  18. #include <string>
  19. #include "kernel/oplib/oplib.h"
  20. #include "kernel/common_utils.h"
  21. #include "kernel/aicpu/aicpu_util.h"
  22. #include "session/anf_runtime_algorithm.h"
  23. namespace mindspore {
  24. namespace kernel {
  25. void AicpuMetadataInfo(const CNodePtr &kernel_node, std::vector<std::shared_ptr<KernelBuildInfo>> *kernel_info_list) {
  26. MS_LOG(INFO) << "AicpuMetadataInfo.";
  27. MS_EXCEPTION_IF_NULL(kernel_node);
  28. MS_EXCEPTION_IF_NULL(kernel_info_list);
  29. std::string op_name = AnfAlgo::GetCNodeName(kernel_node);
  30. if (op_name == kInitDataSetQueue) {
  31. op_name = kInitData;
  32. }
  33. auto op_info_ptr = mindspore::kernel::OpLib::FindOp(op_name, OpImplyType::kAICPU);
  34. if (op_info_ptr == nullptr) {
  35. MS_LOG(DEBUG) << "Aicpu does not have op [" << op_name << "]";
  36. return;
  37. }
  38. // For compatibility with the current framework
  39. if (op_name == kPrint || op_name == kGetNext) {
  40. std::vector<std::string> inputs_format{};
  41. std::vector<TypeId> inputs_type{};
  42. if (op_name == kPrint) {
  43. for (size_t input_index = 0; input_index < AnfAlgo::GetInputTensorNum(kernel_node); ++input_index) {
  44. inputs_format.emplace_back(kOpFormat_DEFAULT);
  45. inputs_type.push_back(AnfAlgo::GetPrevNodeOutputInferDataType(kernel_node, input_index));
  46. }
  47. }
  48. std::vector<std::string> outputs_format;
  49. std::vector<TypeId> outputs_type;
  50. for (size_t output_index = 0; output_index < AnfAlgo::GetOutputTensorNum(kernel_node); ++output_index) {
  51. outputs_format.emplace_back(kOpFormat_DEFAULT);
  52. outputs_type.push_back(AnfAlgo::GetOutputInferDataType(kernel_node, output_index));
  53. }
  54. auto builder = KernelBuildInfo::KernelBuildInfoBuilder();
  55. builder.SetInputsFormat(inputs_format);
  56. builder.SetInputsDeviceType(inputs_type);
  57. builder.SetOutputsFormat(outputs_format);
  58. builder.SetOutputsDeviceType(outputs_type);
  59. builder.SetProcessor(AICPU);
  60. builder.SetKernelType(AICPU_KERNEL);
  61. builder.SetFusionType(OPAQUE);
  62. kernel_info_list->push_back(builder.Build());
  63. return;
  64. }
  65. if (!ParseMetadata(kernel_node, op_info_ptr, AICPU, kernel_info_list)) {
  66. MS_LOG(WARNING) << "Aicpu parsed metadata op [" << op_name << "] failed";
  67. return;
  68. }
  69. }
  70. } // namespace kernel
  71. } // namespace mindspore