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.

opinfo.h 6.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_OPLIB_OPINFO_H_
  17. #define MINDSPORE_CCSRC_KERNEL_OPLIB_OPINFO_H_
  18. #include <vector>
  19. #include <string>
  20. #include <memory>
  21. #include <unordered_map>
  22. #include "ir/dtype.h"
  23. namespace mindspore {
  24. namespace kernel {
  25. enum OpImplyType { kAKG = 0, kTBE = 1, kAICPU };
  26. enum OpIOType { kInput = 0, kOutput };
  27. class OpAttr {
  28. public:
  29. OpAttr() = default;
  30. ~OpAttr() = default;
  31. std::string name() const { return name_; }
  32. std::string param_type() const { return param_type_; }
  33. std::string type() const { return type_; }
  34. std::string value() const { return value_; }
  35. std::string default_value() const { return default_value_; }
  36. void set_name(const std::string &name) { name_ = name; }
  37. void set_param_type(const std::string &param_type) { param_type_ = param_type; }
  38. void set_type(const std::string &type) { type_ = type; }
  39. void set_value(const std::string &value) { value_ = value; }
  40. void set_default_value(const std::string &default_value) { default_value_ = default_value; }
  41. private:
  42. std::string name_;
  43. std::string param_type_;
  44. std::string type_;
  45. std::string value_;
  46. std::string default_value_;
  47. };
  48. class OpIOInfo {
  49. public:
  50. OpIOInfo() = default;
  51. ~OpIOInfo() = default;
  52. int index() const { return index_; }
  53. std::string name() const { return name_; }
  54. bool need_compile() const { return need_compile_; }
  55. std::string param_type() const { return param_type_; }
  56. std::string reshape_type() const { return reshape_type_; }
  57. std::string shape() const { return shape_; }
  58. std::vector<std::string> dtypes() const { return dtypes_; }
  59. std::vector<std::string> formats() const { return formats_; }
  60. void set_index(const int index) { index_ = index; }
  61. void set_name(const std::string &name) { name_ = name; }
  62. void set_need_compile(const bool need_compile) { need_compile_ = need_compile; }
  63. void set_param_type(const std::string &param_type) { param_type_ = param_type; }
  64. void set_reshape_type(const std::string &reshape_type) { reshape_type_ = reshape_type; }
  65. void set_shape(const std::string &shape) { shape_ = shape; }
  66. void set_dtypes(const std::vector<std::string> &dtype) { dtypes_ = dtype; }
  67. void set_formats(const std::vector<std::string> &formats) { formats_ = formats; }
  68. private:
  69. int index_ = 0;
  70. std::string name_;
  71. bool need_compile_ = false;
  72. std::string param_type_;
  73. std::string reshape_type_;
  74. std::string shape_;
  75. std::vector<std::string> dtypes_;
  76. std::vector<std::string> formats_;
  77. };
  78. class OpInfo {
  79. public:
  80. OpInfo() = default;
  81. ~OpInfo() = default;
  82. std::string op_name() const { return op_name_; }
  83. OpImplyType imply_type() const { return imply_type_; }
  84. std::string impl_path() const { return impl_path_; }
  85. std::string fusion_type() const { return fusion_type_; }
  86. bool async_flag() const { return async_flag_; }
  87. std::string binfile_name() const { return binfile_name_; }
  88. int compute_cost() const { return compute_cost_; }
  89. std::string kernel_name() const { return kernel_name_; }
  90. bool partial_flag() const { return partial_flag_; }
  91. bool dynamic_format() const { return dynamic_format_; }
  92. std::string op_pattern() const { return op_pattern_; }
  93. std::vector<std::shared_ptr<OpAttr>> attrs_ptr() const { return attrs_ptr_; }
  94. std::vector<std::shared_ptr<OpIOInfo>> inputs_ptr() const { return inputs_ptr_; }
  95. std::vector<std::shared_ptr<OpIOInfo>> outputs_ptr() const { return outputs_ptr_; }
  96. const std::unordered_map<size_t, size_t> &ref_infos() const { return ref_infos_; }
  97. void set_op_name(const std::string &op_name) { op_name_ = op_name; }
  98. void set_imply_type(const OpImplyType imply_type) { imply_type_ = imply_type; }
  99. void set_impl_path(const std::string &impl_path) { impl_path_ = impl_path; }
  100. void set_fusion_type(const std::string &fusion_type) { fusion_type_ = fusion_type; }
  101. void set_async_flag(const bool async_flag) { async_flag_ = async_flag; }
  102. void set_binfile_name(const std::string &binfile_name) { binfile_name_ = binfile_name; }
  103. void set_compute_cost(const int compute_cost) { compute_cost_ = compute_cost; }
  104. void set_kernel_name(const std::string &kernel_name) { kernel_name_ = kernel_name; }
  105. void set_partial_flag(const bool partial_flag) { partial_flag_ = partial_flag; }
  106. void set_dynamic_format(const bool dynamic_format) { dynamic_format_ = dynamic_format; }
  107. void set_op_pattern(const std::string op_pattern) { op_pattern_ = op_pattern; }
  108. void add_attrs_ptr(const std::shared_ptr<OpAttr> &attr) { attrs_ptr_.push_back(attr); }
  109. void add_inputs_ptr(const std::shared_ptr<OpIOInfo> &input) { inputs_ptr_.push_back(input); }
  110. void add_outputs_ptr(const std::shared_ptr<OpIOInfo> &output) { outputs_ptr_.push_back(output); }
  111. void set_inputs_ptr(const std::vector<std::shared_ptr<OpIOInfo>> &inputs) { inputs_ptr_ = inputs; }
  112. void set_outputs_ptr(const std::vector<std::shared_ptr<OpIOInfo>> &outputs) { outputs_ptr_ = outputs; }
  113. bool is_ref() const { return !ref_infos_.empty(); }
  114. bool has_ref_index(size_t out_index) const { return ref_infos_.find(out_index) != ref_infos_.end(); }
  115. void add_ref_pair(size_t out_index, size_t in_index) { (void)ref_infos_.emplace(out_index, in_index); }
  116. private:
  117. std::string op_name_;
  118. OpImplyType imply_type_ = kTBE;
  119. std::string impl_path_;
  120. std::string fusion_type_;
  121. bool async_flag_ = false;
  122. std::string binfile_name_;
  123. int compute_cost_ = 0;
  124. std::string kernel_name_;
  125. bool partial_flag_ = false;
  126. bool dynamic_format_ = false;
  127. std::string op_pattern_;
  128. std::vector<std::shared_ptr<OpAttr>> attrs_ptr_;
  129. std::vector<std::shared_ptr<OpIOInfo>> inputs_ptr_;
  130. std::vector<std::shared_ptr<OpIOInfo>> outputs_ptr_;
  131. std::unordered_map<size_t, size_t> ref_infos_;
  132. };
  133. } // namespace kernel
  134. } // namespace mindspore
  135. #endif // MINDSPORE_CCSRC_KERNEL_OPLIB_OPINFO_H_