Skip to content

Commit

Permalink
disable padding if dynamic shape (#36648)
Browse files Browse the repository at this point in the history
* disable padding if dynamic shape

* add parentheses

* correct
  • Loading branch information
b3602sss committed Oct 23, 2021
1 parent baf4359 commit 89ee527
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ class Pool2dOpConverter : public OpConverter {

if (engine_->with_dynamic_shape()) {
if (!adaptive && !global_pooling && !ceil_mode) {
if ((g_post_pad.w() > 0 || g_post_pad.h() > 0) &&
(padding_algorithm != "SAME")) {
// input_shape.d < 0 means we can't get shape info here.
// we may suffer from issue if shape is not met finally.
if ((padding_algorithm != "SAME") &&
((g_post_pad.w() > 0 && input_shape.d[input_dims - 2] > 0) ||
(g_post_pad.h() > 0 && input_shape.d[input_dims - 1] > 0))) {
auto *pad_layer = TRT_ENGINE_ADD_LAYER(engine_, Padding, *input1,
g_pre_pad, g_post_pad);
PADDLE_ENFORCE_NOT_NULL(
Expand All @@ -145,6 +148,7 @@ class Pool2dOpConverter : public OpConverter {
"created. The pointer to pad layer is `NULL`."));
input1 = pad_layer->getOutput(0);
}

auto *pool_layer = TRT_ENGINE_ADD_LAYER(engine_, Pooling, *input1,
nv_pool_type, nv_ksize);
pool_layer->setStride(nv_strides);
Expand Down

1 comment on commit 89ee527

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.