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.

kernel_build_info.h 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_KERNEL_BUILD_INFO_H_
  17. #define MINDSPORE_CCSRC_KERNEL_KERNEL_BUILD_INFO_H_
  18. #include <iostream>
  19. #include <vector>
  20. #include <memory>
  21. #include <string>
  22. #include <utility>
  23. #include "ir/dtype.h"
  24. #include "kernel/kernel.h"
  25. namespace mindspore {
  26. namespace kernel {
  27. class KernelBuildInfo {
  28. public:
  29. class KernelBuildInfoBuilder;
  30. KernelBuildInfo() {
  31. kernel_type_ = TBE_KERNEL;
  32. fusion_type_ = OPAQUE;
  33. processor_ = AICORE;
  34. op_pattern_ = kCommonPattern;
  35. input_reshape_type_ = {};
  36. output_reshape_type_ = {};
  37. inputs_format_ = {};
  38. outputs_format_ = {};
  39. inputs_device_type_ = {};
  40. outputs_device_type_ = {};
  41. }
  42. ~KernelBuildInfo() = default;
  43. KernelType kernel_type() const { return kernel_type_; }
  44. std::string GetInputFormat(size_t input_index) const;
  45. std::string GetOutputFormat(size_t output_index) const;
  46. TypeId GetInputDeviceType(size_t input_index) const;
  47. TypeId GetOutputDeviceType(size_t output_index) const;
  48. std::vector<Axis> GetInputReshapeType(size_t input_index) const;
  49. bool IsInputDefaultPadding() const;
  50. bool IsOutputDefaultPadding() const;
  51. std::vector<Axis> GetOutputReshapeType(size_t input_index) const;
  52. std::vector<std::string> GetAllInputFormats() const;
  53. std::vector<std::string> GetAllOutputFormats() const;
  54. std::vector<TypeId> GetAllInputDeviceTypes() const;
  55. std::vector<TypeId> GetAllOutputDeviceTypes() const;
  56. OpPattern op_pattern() const { return op_pattern_; }
  57. FusionType fusion_type() const { return fusion_type_; }
  58. Processor processor() const { return processor_; }
  59. size_t GetInputNum() const;
  60. size_t GetOutputNum() const;
  61. std::string ToString() const;
  62. bool operator==(const KernelBuildInfo &other) const;
  63. public:
  64. static auto constexpr kInvalidFormat = "InvalidFormat";
  65. private:
  66. KernelType kernel_type_;
  67. std::vector<std::string> inputs_format_;
  68. OpPattern op_pattern_;
  69. std::vector<std::string> outputs_format_;
  70. std::vector<std::vector<Axis>> input_reshape_type_;
  71. std::vector<std::vector<Axis>> output_reshape_type_;
  72. std::vector<TypeId> inputs_device_type_;
  73. std::vector<TypeId> outputs_device_type_;
  74. FusionType fusion_type_;
  75. Processor processor_;
  76. };
  77. using KernelBuildInfoPtr = std::shared_ptr<KernelBuildInfo>;
  78. class KernelBuildInfo::KernelBuildInfoBuilder {
  79. public:
  80. KernelBuildInfoBuilder() { kernel_build_info_ = std::make_shared<KernelBuildInfo>(); }
  81. explicit KernelBuildInfoBuilder(std::shared_ptr<KernelBuildInfo> kernel_build_info)
  82. : kernel_build_info_(std::move(kernel_build_info)) {}
  83. ~KernelBuildInfoBuilder() = default;
  84. void SetKernelType(const KernelType &kernel_type);
  85. void SetInputsFormat(const std::vector<std::string> &inputs_format);
  86. void SetOutputsFormat(const std::vector<std::string> &outputs_format);
  87. void SetInputsDeviceType(const std::vector<TypeId> &inputs_device_type);
  88. void SetOutputsDeviceType(const std::vector<TypeId> &outputs_device_type);
  89. void SetInputReshapeType(const std::vector<std::vector<Axis>> &input_reshape_type);
  90. void SetOutputReshapeType(const std::vector<std::vector<Axis>> &output_reshape_type);
  91. void SetFusionType(FusionType fusion_type);
  92. void SetProcessor(Processor processor);
  93. void SetOpPattern(OpPattern pattern);
  94. void SetInputFormat(const std::string &format, size_t index);
  95. void SetOutputFormat(const std::string &format, size_t index);
  96. std::shared_ptr<KernelBuildInfo> Build();
  97. private:
  98. std::shared_ptr<KernelBuildInfo> kernel_build_info_;
  99. };
  100. } // namespace kernel
  101. } // namespace mindspore
  102. #endif // MINDSPORE_CCSRC_KERNEL_KERNEL_BUILD_INFO_H_