1 /** 2 * Copyright 2022-2023 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_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_VALUE_DEPEND_OP_UTILS_H_ 18 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_VALUE_DEPEND_OP_UTILS_H_ 19 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 24 #include "base/base.h" 25 #include "ir/anf.h" 26 #include "ir/func_graph.h" 27 #include "utils/hash_set.h" 28 29 namespace mindspore::graphkernel { 30 class ValueDependOpUtils { 31 public: 32 static bool IsConstInput(const AnfNodePtr &node); 33 static bool AddConstInputToAttr(const CNodePtr &cnode, const HashSet<size_t> &input_idx); KeepValueNode(const std::string & prim_name,size_t index)34 static bool KeepValueNode(const std::string &prim_name, size_t index) { 35 auto iter = GetOpIndexInfo().find(prim_name); 36 return iter != GetOpIndexInfo().end() && iter->second.count(index) != 0; 37 } GetIndices(const std::string & prim_name)38 static const HashSet<size_t> &GetIndices(const std::string &prim_name) { 39 auto iter = GetOpIndexInfo().find(prim_name); 40 return iter->second; 41 } 42 43 static const std::unordered_map<std::string, HashSet<size_t>> &GetOpIndexInfo(); 44 }; 45 } // namespace mindspore::graphkernel 46 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_VALUE_DEPEND_OP_UTILS_H_ 47