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.

scope_pattern_impl.h 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef REGISTER_SCOPE_SCOPE_PATTERN_IMPL_H_
  17. #define REGISTER_SCOPE_SCOPE_PATTERN_IMPL_H_
  18. #include "external/register/scope/scope_fusion_pass_register.h"
  19. namespace ge {
  20. class ScopeAttrValue::ScopeAttrValueImpl {
  21. public:
  22. ScopeAttrValueImpl() : int_value_(0), float_value_(0.0), string_value_(""), bool_value_(false) {}
  23. ~ScopeAttrValueImpl() {}
  24. void SetIntValue(const int64_t &value) { int_value_ = value; }
  25. void SetFloatValue(const float &value) { float_value_ = value; }
  26. void SetStringValue(const std::string &value) { string_value_ = value; }
  27. void SetBoolValue(const bool &value) { bool_value_ = value; }
  28. const int64_t &GetIntValue() const { return int_value_; }
  29. const float &GetFloatValue() const { return float_value_; }
  30. const std::string &GetStrValue() const { return string_value_; }
  31. const bool &GetBoolValue() const { return bool_value_; }
  32. private:
  33. int64_t int_value_;
  34. float float_value_;
  35. std::string string_value_;
  36. bool bool_value_;
  37. };
  38. class NodeOpTypeFeature::NodeOpTypeFeatureImpl : ScopeBaseFeature {
  39. public:
  40. NodeOpTypeFeatureImpl(std::string nodeType, int num, int step = 0)
  41. : node_type_(nodeType), num_(num), step_(step) {}
  42. ~NodeOpTypeFeatureImpl() {}
  43. bool Match(const Scope *scope) override;
  44. public:
  45. std::string node_type_; // Node type
  46. int num_; // Node number
  47. int step_; // step
  48. };
  49. class NodeAttrFeature::NodeAttrFeatureImpl : ScopeBaseFeature {
  50. public:
  51. NodeAttrFeatureImpl(std::string nodeType, std::string attr_name, ge::DataType datatype, ScopeAttrValue &attr_value)
  52. : node_type_(nodeType), attr_name_(attr_name), datatype_(datatype), attr_value_(attr_value) {}
  53. ~NodeAttrFeatureImpl() {}
  54. bool Match(const Scope *scope) override;
  55. public:
  56. std::string node_type_; // Node type
  57. std::string attr_name_; // attribute name
  58. ge::DataType datatype_; // datatype
  59. ScopeAttrValue attr_value_; // AttrValue
  60. };
  61. class ScopeFeature::ScopeFeatureImpl : ScopeBaseFeature {
  62. public:
  63. ScopeFeatureImpl(std::string sub_type, int32_t num, std::string suffix = "",
  64. std::string sub_scope_mask = "", int step = 0)
  65. : sub_type_(sub_type), num_(num), suffix_(suffix), sub_scope_mask_(sub_scope_mask), step_(step) {}
  66. ~ScopeFeatureImpl() {}
  67. bool Match(const Scope *scope) override;
  68. bool SubScopesMatch(const std::vector<Scope *> &scopes);
  69. public:
  70. std::string sub_type_;
  71. int32_t num_;
  72. std::string suffix_;
  73. std::string sub_scope_mask_;
  74. int step_;
  75. };
  76. class ScopePattern::ScopePatternImpl {
  77. public:
  78. ScopePatternImpl() {}
  79. ~ScopePatternImpl() {}
  80. bool Match(const Scope *scope) const;
  81. void SetSubType(const std::string &sub_type);
  82. const std::string &SubType() const { return sub_type_; }
  83. void AddNodeOpTypeFeature(NodeOpTypeFeature &feature);
  84. void AddNodeAttrFeature(NodeAttrFeature &feature);
  85. void AddScopeFeature(ScopeFeature &feature);
  86. private:
  87. std::string sub_type_; // get Scope sub type
  88. std::vector<NodeOpTypeFeature> node_optype_features_;
  89. std::vector<NodeAttrFeature> node_attr_features_;
  90. std::vector<ScopeFeature> scopes_features_;
  91. };
  92. } // namespace ge
  93. #endif // REGISTER_SCOPE_SCOPE_PATTERN_IMPL_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示