已合并
【PR】: fix: 修复融合pass编译失败 #3787
hugo111创建于 6月30日
【PR】: fix: 修复融合pass编译失败 #3787
已合并
hugo111创建于 6月30日
4 个文件变更+8-28
@@ -191,7 +191,7 @@ GraphUniqPtr Replacement(const std::unique_ptr<MatchResult> &match_result) overr
191}191}
192```192```
193 193 
194-如果 pass 注册在 InferShape 后,replacement 中新建节点的 shape 信息需要自行处理。需要对 replacement 做 shape 推导时,可参考现有样例中对 `GeUtils::InferShape` 的使用。194+如果 pass 注册在 InferShape 后,replacement 中新建节点的 shape 信息需要自行处理。需要对 replacement 做 shape 推导时,可参考现有样例中对 `InferShapeUtil::InferShape` 的使用。
195 195 
196## 6. CaptureTensor:读取 pattern 中的关键 Tensor196## 6. CaptureTensor:读取 pattern 中的关键 Tensor
197 197 
@@ -191,7 +191,7 @@ GraphUniqPtr Replacement(const std::unique_ptr<MatchResult> &match_result) overr
191}191}
192```192```
193 193 
194-If the pass is registered after InferShape, shape information for new nodes in the replacement needs to be handled manually. Refer to existing examples for using `GeUtils::InferShape` when shape inference is needed for replacement.194+If the pass is registered after InferShape, shape information for new nodes in the replacement needs to be handled manually. Refer to existing examples for using `InferShapeUtil::InferShape` when shape inference is needed for replacement.
195 195 
196## 6. CaptureTensor: Read Key Tensors in Pattern196## 6. CaptureTensor: Read Key Tensors in Pattern
197 197 
@@ -100,24 +100,14 @@ class DecomposeGroupedConvToSplitedPass : public DecomposePass {
100 auto res = es::Concat(replacement_graph_builder.CreateScalar(1), convs, groups);100 auto res = es::Concat(replacement_graph_builder.CreateScalar(1), convs, groups);
101 auto replace_graph = replacement_graph_builder.BuildAndReset({res});101 auto replace_graph = replacement_graph_builder.BuildAndReset({res});
102 // 当前pass注册在after infershape阶段,需要自行保证替换部分的shape连续102 // 当前pass注册在after infershape阶段,需要自行保证替换部分的shape连续
103- if (!InferShape(matched_node, *replace_graph)) {103+ // 使用 ge::fusion::InferShapeUtil 提供的 InferShape 接口做 shape/dtype 推导
104+ // 该接口会自动从 matched_node 边界获取输入 tensor desc(shape/dtype/format)
105+ if (InferShapeUtil::InferShape(*replace_graph, matched_node) != SUCCESS) {
106+ std::cout << "InferShapeUtil::InferShape failed" << std::endl;
104 return nullptr;107 return nullptr;
105 }108 }
106 return replace_graph;109 return replace_graph;
107 }110 }
108- 
109- private:
110- // 因为pass会被重复执行,不建议使用私有成员
111- // 如果使用,需要保证pass对象的可重入性
112- bool InferShapeAndCheckSupport(const GNode &matched_node, const Graph &graph) {
113- // 使用 ge::fusion::InferShapeUtil 提供的 InferShape 接口做 shape/dtype 推导
114- // 该接口会自动从 matched_node 边界获取输入 tensor desc(shape/dtype/format)
115- if (InferShapeUtil::InferShape(graph, matched_node) != SUCCESS) {
116- std::cout << "InferShapeUtil::InferShape failed" << std::endl;
117- return false;
118- }
119- return true;
120- }
121};111};
122 112 
123REG_DECOMPOSE_PASS(DecomposeGroupedConvToSplitedPass, {"Conv2D"}).Stage(CustomPassStage::kAfterInferShape);113REG_DECOMPOSE_PASS(DecomposeGroupedConvToSplitedPass, {"Conv2D"}).Stage(CustomPassStage::kAfterInferShape);
@@ -13,7 +13,7 @@
13#include <limits>13#include <limits>
14#include "es_all_ops.h"14#include "es_all_ops.h"
15#include "ge/fusion/pass/pattern_fusion_pass.h"15#include "ge/fusion/pass/pattern_fusion_pass.h"
16-#include "ge/ge_utils.h"16+#include "ge/fusion/infer_shape_util.h"
17 17 
18using namespace ge;18using namespace ge;
19using namespace fusion;19using namespace fusion;
@@ -262,17 +262,7 @@ class BatchMatmulFlattenPass : public PatternFusionPass {
262 }262 }
263 263 
264 bool InferShapeAndCheckSupport(const GNode &matched_node, const Graph &graph) {264 bool InferShapeAndCheckSupport(const GNode &matched_node, const Graph &graph) {
265- std::vector<ge::Shape> input_shapes;265+ if (InferShapeUtil::InferShape(graph, matched_node) != SUCCESS) {
266- auto input_size = matched_node.GetInputsSize();
267- for (size_t i = 0; i < input_size; i++) {
268- TensorDesc tensor_desc;
269- if (matched_node.GetInputDesc(i, tensor_desc) != SUCCESS) {
270- return false;
271- }
272- input_shapes.emplace_back(tensor_desc.GetShape());
273- }
274- 
275- if (GeUtils::InferShape(graph, input_shapes) != SUCCESS) {
276 std::cout << "InferShape failed" << std::endl;266 std::cout << "InferShape failed" << std::endl;
277 return false;267 return false;
278 }268 }