1 /** 2 * Copyright 2021 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 17 #ifndef MINDSPORE_CORE_MINDAPI_IR_PRIMITIVE_H_ 18 #define MINDSPORE_CORE_MINDAPI_IR_PRIMITIVE_H_ 19 20 #include <vector> 21 #include <string> 22 #include <unordered_map> 23 #include "mindapi/base/base.h" 24 #include "mindapi/ir/common.h" 25 #include "mindapi/ir/value.h" 26 27 namespace mindspore::api { 28 /// \brief Primitive defines a primitive operator. 29 class MIND_API Primitive : public Value { 30 public: 31 MIND_API_BASE_MEMBER(Primitive); 32 33 /// \brief Create primitive with the given name. 34 /// 35 /// \param[in] name The primitive name. 36 explicit Primitive(const std::string &name); 37 38 /// \brief Get name of the primitive. 39 /// 40 /// \return The name of primitive. 41 const std::string &name() const; 42 43 /// \brief Add attribute to primitive. 44 /// 45 /// \param[in] name The attribute name. 46 /// \param[in] attr The attribute value. 47 /// \return The primitive to which attribute has been added. 48 Primitive &AddAttr(const std::string &name, const ValuePtr &attr); 49 50 /// \brief Add attributes by using a map, all elements of the map will be added to this primitive. 51 /// 52 /// \param[in] attrs The attribute map needs to be added in the primitive attribute. 53 /// \return The primitive to which attribute has been added. 54 Primitive &SetAttrs(const std::unordered_map<std::string, ValuePtr> &attrs); 55 56 /// \brief Erase attribute to the primitive attribute map. 57 /// 58 /// \param[in] name The attribute name. 59 void EraseAttr(const std::string &name); 60 61 /// \brief Get attribute value by name. 62 /// 63 /// \param[in] name the attribute name. 64 /// \return The value of the attribute, null if attribute name not found. 65 ValuePtr GetAttr(const std::string &name) const; 66 67 /// \brief Check If Primitive has an attribute with then given name. 68 /// 69 /// \param[in] name The attribute name. 70 /// \return True if there is an attribute with the given name, otherwise false. 71 bool HasAttr(const std::string &name) const; 72 73 /// \brief Get all attributes of this primitive as a map. 74 /// 75 /// \return The attribute map of this primitive. 76 std::unordered_map<std::string, ValuePtr> attrs() const; 77 }; 78 } // namespace mindspore::api 79 #endif // MINDSPORE_CORE_MINDAPI_IR_PRIMITIVE_H_ 80