• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2024 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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_KERNEL_PACKET_SYMBOL_ENGINE_EXTENDER_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_KERNEL_PACKET_SYMBOL_ENGINE_EXTENDER_H_
18 
19 #include <string>
20 #include "utils/hash_set.h"
21 #include "include/backend/optimizer/pass.h"
22 #include "include/backend/optimizer/optimizer.h"
23 
24 namespace mindspore::graphkernel::packet {
25 // Extend kernel to a bigger subgraph using a symbol engine,
26 // to include all the nodes that do shape calc for the kernel.
27 class SymbolEngineExtender : public opt::Pass {
28  public:
SymbolEngineExtender()29   SymbolEngineExtender() : Pass("symbol_engine_extender") {}
30   ~SymbolEngineExtender() override = default;
31   bool Run(const FuncGraphPtr &func_graph) override;
32 
33  protected:
34   bool CheckBaseNode(const AnfNodePtr &node);
35   AnfNodePtrList FindCandidates(const CNodePtr &base_node);
36   bool ExtendNode(const AnfNodePtr &node, const FuncGraphPtr &main_fg);
37   void FindValueDependNode(const CNodePtr &node, HashSet<AnfNodePtr> *visited, HashSet<AnfNodePtr> *valid_nodes);
38   void FindShapeDependHostNode(const CNodePtr &node, HashSet<AnfNodePtr> *visited, HashSet<AnfNodePtr> *valid_nodes);
39   ValuePtr FindOnlyDependShapeInputs(const FuncGraphPtr &fg) const;
40 };
41 }  // namespace mindspore::graphkernel::packet
42 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_KERNEL_PACKET_SYMBOL_ENGINE_EXTENDER_H_
43