Browse Source

fix pnnx crash on unsupported expression

tags/20220216
nihuini 4 years ago
parent
commit
f8ca1e7585
No known key found for this signature in database GPG Key ID: 98FD8F4EBC3E5DB8
3 changed files with 51 additions and 0 deletions
  1. +22
    -0
      tools/pnnx/src/pass_level2/torch_mean.cpp
  2. +22
    -0
      tools/pnnx/src/pass_level2/torch_sum.cpp
  3. +7
    -0
      tools/pnnx/src/pass_ncnn/expand_expression.cpp

+ 22
- 0
tools/pnnx/src/pass_level2/torch_mean.cpp View File

@@ -40,4 +40,26 @@ pnnx.Output output 1 0 out

REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_mean, 20)

class torch_mean_1 : public GraphRewriterPass
{
public:
const char* match_pattern_graph() const
{
return R"PNNXIR(7767517
4 3
pnnx.Input input_0 0 1 input
prim::Constant op_0 0 1 dtype value=*
aten::mean op_1 2 1 input dtype out
pnnx.Output output 1 0 out
)PNNXIR";
}

const char* type_str() const
{
return "torch.mean";
}
};

REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_mean_1, 20)

} // namespace pnnx

+ 22
- 0
tools/pnnx/src/pass_level2/torch_sum.cpp View File

@@ -40,4 +40,26 @@ pnnx.Output output 1 0 out

REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_sum, 20)

class torch_sum_1 : public GraphRewriterPass
{
public:
const char* match_pattern_graph() const
{
return R"PNNXIR(7767517
4 3
pnnx.Input input_0 0 1 input
prim::Constant op_0 0 1 dtype value=*
aten::sum op_1 2 1 input dtype out
pnnx.Output output 1 0 out
)PNNXIR";
}

const char* type_str() const
{
return "torch.sum";
}
};

REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_sum_1, 20)

} // namespace pnnx

+ 7
- 0
tools/pnnx/src/pass_ncnn/expand_expression.cpp View File

@@ -265,6 +265,13 @@ void expand_expression(Graph& graph)
Operand* old_output_operand = op->outputs[0];
Operand* new_output_operand = graph.get_operand(op->name + "_" + outname);

if (!new_output_operand)
{
// not supported expr
nonsupported_expr_ops.insert(op);
break;
}

for (auto r : op->inputs)
{
r->remove_consumer(op);


Loading…
Cancel
Save