1 /** 2 * Copyright 2019-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_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 <vector> 26 #include "utils/hash_map.h" 27 #include "ir/anf.h" 28 #include "ir/primitive.h" 29 #include "ir/dtype.h" 30 31 namespace mindspore { 32 /* namespace to support prim related definition */ 33 namespace prim { 34 // Supported meta type 35 enum PrimType { kPrimTypeUnknown, kPrimTypeNumOneArg, kPrimTypeNumTwoArgs, kPrimTypeStrOneArg, kPrimTypeStrTwoArgs }; 36 37 class PrimToFunction; 38 39 // Get the args, return value and function handle for a primitive instance. 40 class PrimToFunction { 41 public: 42 // Return a thread-safe singleton instance GetInstance()43 static PrimToFunction &GetInstance() { 44 static PrimToFunction instance; 45 return instance; 46 } 47 PrimToFunction(const PrimToFunction &) = delete; 48 PrimToFunction &operator=(const PrimToFunction &) = delete; 49 ~PrimToFunction() = default; 50 51 // Get the args and return value for a primitive instance. 52 bool GetFunction(const PrimitivePtr &prim, FunctionPtr *func) const; 53 54 private: 55 PrimToFunction(); 56 // Get the number of primitive arguments 57 int64_t GetPrimType(const PrimitivePtr &prim) const; 58 const mindspore::HashMap<std::string, int64_t> prim_func_type_map_; 59 }; 60 } // namespace prim 61 } // namespace mindspore 62 #endif // MINDSPORE_CCSRC_FRONTEND_OPERATOR_PRIM_TO_FUNCTION_H_ 63