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 authored Oct 23, 2021
1 parent f6d8252 commit 99e396f
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 @@ -138,8 +138,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 @@ -148,6 +151,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

0 comments on commit 99e396f

Please sign in to comment.