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 17 #ifndef MINDSPORE_CCSRC_FRONTEND_OPERATOR_PRIM_TO_FUNCTION_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_OPERATOR_PRIM_TO_FUNCTION_H_ 19 20 #include <memory> 21 #include <mutex> 22 #include <sstream> 23 #include <string> 24 #include <typeindex> 25 #include <unordered_map> 26 #include <vector> 27 28 #include "ir/anf.h" 29 #include "ir/primitive.h" 30 #include "ir/dtype.h" 31 32 namespace mindspore { 33 /* namespace to support prim related definition */ 34 namespace prim { 35 // Supported meta type 36 enum PrimType { kPrimTypeUnknown, kPrimTypeOneArg, kPrimTypeTwoArgs }; 37 38 class PrimToFunction; 39 40 // Get the args, return value and function handle for a primitive instance. 41 class PrimToFunction { 42 public: 43 // Return a thread-safe singleton instance GetInstance()44 static PrimToFunction &GetInstance() { 45 static PrimToFunction instance; 46 return instance; 47 } 48 PrimToFunction(const PrimToFunction &) = delete; 49 PrimToFunction &operator=(const PrimToFunction &) = delete; 50 ~PrimToFunction() = default; 51 52 // Get the args and return value for a primitive instance. 53 bool GetFunction(const PrimitivePtr &prim, FunctionPtr *func) const; 54 55 private: 56 PrimToFunction(); 57 // Get the number of primitive arguments 58 int64_t GetPrimType(const PrimitivePtr &prim) const; 59 const std::unordered_map<std::string, int64_t> prim_func_type_map_; 60 }; 61 } // namespace prim 62 } // namespace mindspore 63 #endif // MINDSPORE_CCSRC_FRONTEND_OPERATOR_PRIM_TO_FUNCTION_H_ 64