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_OPS_CUSTOM_H_ 18 #define MINDSPORE_CORE_OPS_CUSTOM_H_ 19 #include <string> 20 #include <utility> 21 #include <vector> 22 #include <map> 23 #include <memory> 24 #include <unordered_map> 25 #include "ops/primitive_c.h" 26 #include "ops/op_utils.h" 27 #include "ir/anf.h" 28 29 namespace mindspore { 30 namespace ops { 31 constexpr auto kNameCustom = "Custom"; 32 /// \brief Custom defined user-defined operator prototype. 33 class MS_CORE_API Custom : public PrimitiveC { 34 public: 35 /// \brief Constructor. Custom()36 Custom() : PrimitiveC(kNameCustom) {} 37 38 /// \brief Destructor. 39 ~Custom() override = default; 40 41 MS_DECLARE_PARENT(Custom, PrimitiveC); 42 43 /// \brief Method to init the op's attributes. 44 /// 45 /// \param[in] type Define the concrete type of the custom op, which is used to distinguish different custom op. 46 /// \param[in] attrs Define the attributes of the custom op. 47 void Init(const std::string &type, const std::map<std::string, std::vector<uint8_t>> &attrs); 48 49 /// \brief Method to set type attribute. 50 /// 51 /// \param[in] type Define the concrete type of the custom op, which is used to distinguish different custom op. 52 void set_type(const std::string &type); 53 54 /// \brief Method to get type attribute. 55 /// 56 /// \return a string 57 std::string get_type() const; 58 59 /// \brief Method to set attr attribute. 60 /// 61 /// \param[in] attrs Define the attributes of the custom op. 62 void set_attr(const std::map<std::string, std::vector<uint8_t>> &attrs); 63 64 /// \brief Method to get attr attribute. 65 /// 66 /// \return a map which contains all attributes of the custom op. 67 std::map<std::string, std::vector<uint8_t>> get_attr() const; 68 }; 69 70 using PrimCustomPtr = std::shared_ptr<Custom>; 71 } // namespace ops 72 } // namespace mindspore 73 74 #endif // MINDSPORE_CORE_OPS_CUSTOM_H_ 75