Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bad3bebf
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bad3bebf
编写于
6月 08, 2021
作者:
W
Wangzheee
提交者:
GitHub
6月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add trt convert reshape_op in release/2.1.1 (#33372)
上级
5e09d67a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
200 addition
and
1 deletion
+200
-1
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+1
-0
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
+1
-0
paddle/fluid/inference/tensorrt/convert/op_converter.h
paddle/fluid/inference/tensorrt/convert/op_converter.h
+7
-0
paddle/fluid/inference/tensorrt/convert/reshape_op.cc
paddle/fluid/inference/tensorrt/convert/reshape_op.cc
+63
-0
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+17
-0
python/paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
.../paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
+2
-1
python/paddle/fluid/tests/unittests/ir/inference/test_trt_reshape_op.py
...fluid/tests/unittests/ir/inference/test_trt_reshape_op.py
+109
-0
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
bad3bebf
...
...
@@ -1234,6 +1234,7 @@ USE_TRT_CONVERTER(roi_align);
USE_TRT_CONVERTER
(
affine_channel
);
USE_TRT_CONVERTER
(
multiclass_nms
);
USE_TRT_CONVERTER
(
nearest_interp
);
USE_TRT_CONVERTER
(
reshape
);
#endif
namespace
paddle_infer
{
...
...
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
浏览文件 @
bad3bebf
...
...
@@ -12,6 +12,7 @@ nv_library(tensorrt_converter
affine_channel_op.cc
multiclass_nms_op.cc
nearest_interp_op.cc
reshape_op.cc
DEPS tensorrt_engine tensorrt_plugin operator scope framework_proto op_registry
)
nv_test
(
test_op_converter SRCS test_op_converter.cc DEPS
...
...
paddle/fluid/inference/tensorrt/convert/op_converter.h
浏览文件 @
bad3bebf
...
...
@@ -127,6 +127,13 @@ class OpConverter {
it
,
platform
::
errors
::
Unimplemented
(
"no OpConverter for optype [%s]"
,
op_desc
.
Type
()));
}
// reshape2 == reshape
if
(
op_desc
.
Type
()
==
"reshape2"
)
{
it
=
Registry
<
OpConverter
>::
Global
().
Lookup
(
"reshape"
);
PADDLE_ENFORCE_NOT_NULL
(
it
,
platform
::
errors
::
Unimplemented
(
"no OpConverter for optype [%s]"
,
op_desc
.
Type
()));
}
if
(
!
it
)
{
it
=
Registry
<
OpConverter
>::
Global
().
Lookup
(
op_desc
.
Type
());
}
...
...
paddle/fluid/inference/tensorrt/convert/reshape_op.cc
0 → 100644
浏览文件 @
bad3bebf
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/inference/tensorrt/convert/op_converter.h"
namespace
paddle
{
namespace
framework
{
class
Scope
;
namespace
proto
{
class
OpDesc
;
}
// namespace proto
}
// namespace framework
}
// namespace paddle
namespace
paddle
{
namespace
inference
{
namespace
tensorrt
{
/*
* ReshapeOp
*/
class
ReshapeOpConverter
:
public
OpConverter
{
public:
void
operator
()(
const
framework
::
proto
::
OpDesc
&
op
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
{
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
// Declare inputs
auto
*
input
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
const
std
::
vector
<
int
>&
shape
=
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"shape"
));
int
nbDims_num
=
shape
.
size
();
nvinfer1
::
Dims
reshape_dim
;
if
(
engine_
->
with_dynamic_shape
())
{
// running the TRT Dynamic Shape mode
reshape_dim
.
nbDims
=
nbDims_num
;
for
(
int
i
=
0
;
i
<
nbDims_num
;
++
i
)
{
reshape_dim
.
d
[
i
]
=
shape
[
i
];
}
}
else
{
// running the TRT Static Shape mode
reshape_dim
.
nbDims
=
nbDims_num
-
1
;
for
(
int
i
=
0
;
i
<
nbDims_num
-
1
;
++
i
)
{
reshape_dim
.
d
[
i
]
=
shape
[
i
+
1
];
}
}
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
input
);
layer
->
setReshapeDimensions
(
reshape_dim
);
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"reshape"
,
{
output_name
},
test_mode
);
}
};
}
// namespace tensorrt
}
// namespace inference
}
// namespace paddle
REGISTER_TRT_OP_CONVERTER
(
reshape
,
ReshapeOpConverter
);
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
bad3bebf
...
...
@@ -49,6 +49,10 @@ struct SimpleOpTypeSetTeller : public Teller {
#endif
#if IS_TRT_VERSION_GE(7130)
teller_set
.
insert
(
"group_norm"
);
#endif
#if CUDA_VERSION >= 10200
teller_set
.
insert
(
"reshape"
);
teller_set
.
insert
(
"reshape2"
);
#endif
}
...
...
@@ -654,6 +658,19 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
}
}
if
(
op_type
==
"reshape"
||
op_type
==
"reshape2"
)
{
if
(
!
desc
.
HasAttr
(
"shape"
)
||
with_dynamic_shape
)
{
return
false
;
// Paddle-TRT does not support the input tensors: Shape and ShapeTensor
}
else
if
(
desc
.
Input
(
"Shape"
).
size
()
>=
1
||
desc
.
Input
(
"ShapeTensor"
).
size
()
>=
1
)
{
return
false
;
}
else
{
std
::
vector
<
int
>
shape
=
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
desc
.
GetAttr
(
"shape"
));
if
(
shape
.
size
()
>=
nvinfer1
::
Dims
::
MAX_DIMS
)
return
false
;
}
}
if
((
*
teller
)(
op_type
,
desc
,
use_no_calib_int8
))
return
true
;
}
return
false
;
...
...
python/paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
浏览文件 @
bad3bebf
...
...
@@ -8,6 +8,7 @@ foreach(TEST_INFERENCE_IR_PASS ${TEST_TRT_IR_PASSES})
endforeach
()
if
(
WITH_GPU AND TENSORRT_FOUND
)
list
(
REMOVE_ITEM TEST_TRT_IR_PASSES test_trt_multiclass_nms_op
)
foreach
(
target
${
TEST_TRT_IR_PASSES
}
)
py_test_modules
(
${
target
}
MODULES
${
target
}
)
endforeach
()
...
...
@@ -32,6 +33,6 @@ if(WITH_GPU AND TENSORRT_FOUND)
set_tests_properties
(
test_trt_subgraph_pass PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_trt_activation_pass PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_trt_conv_pass PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_trt_multiclass_nms_op PROPERTIES TIMEOUT 200
)
#
set_tests_properties(test_trt_multiclass_nms_op PROPERTIES TIMEOUT 200)
set_tests_properties
(
test_trt_dynamic_shape PROPERTIES TIMEOUT 120
)
endif
()
python/paddle/fluid/tests/unittests/ir/inference/test_trt_reshape_op.py
0 → 100644
浏览文件 @
bad3bebf
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
unittest
import
numpy
as
np
from
inference_pass_test
import
InferencePassTest
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.core
import
PassVersionChecker
from
paddle.fluid.core
import
AnalysisConfig
class
TRTReshapeTest
(
InferencePassTest
):
def
setUp
(
self
):
self
.
bs
=
1
self
.
input_shape
=
[
32
,
15
,
24
]
self
.
reshape
=
[
-
1
,
8
,
20
,
72
]
self
.
data_shape
=
[
self
.
bs
,
self
.
input_shape
[
0
],
self
.
input_shape
[
1
],
self
.
input_shape
[
2
]
]
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
'data'
,
shape
=
self
.
data_shape
,
dtype
=
'float32'
)
reshape_out
=
self
.
append_reshape
(
data
,
self
.
reshape
)
out
=
fluid
.
layers
.
batch_norm
(
reshape_out
,
is_test
=
True
)
self
.
feeds
=
{
'data'
:
np
.
random
.
random
(
self
.
data_shape
).
astype
(
'float32'
),
}
self
.
enable_trt
=
True
self
.
trt_parameters
=
TRTReshapeTest
.
TensorRTParam
(
1
<<
30
,
self
.
bs
,
1
,
AnalysisConfig
.
Precision
.
Float32
,
False
,
False
)
self
.
fetch_list
=
[
out
]
def
append_reshape
(
self
,
data
,
reshape
):
return
fluid
.
layers
.
reshape
(
data
,
reshape
)
def
test_check_output
(
self
):
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
))
class
TRTReshapeTest1
(
TRTReshapeTest
):
def
setUp
(
self
):
self
.
bs
=
2
self
.
input_shape
=
[
23
,
13
,
24
]
self
.
reshape
=
[
2
,
0
,
-
1
,
12
]
self
.
data_shape
=
[
self
.
bs
,
self
.
input_shape
[
0
],
self
.
input_shape
[
1
],
self
.
input_shape
[
2
]
]
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
'data'
,
shape
=
self
.
data_shape
,
dtype
=
'float32'
)
reshape_out
=
self
.
append_reshape
(
data
,
self
.
reshape
)
out
=
fluid
.
layers
.
batch_norm
(
reshape_out
,
is_test
=
True
)
self
.
feeds
=
{
'data'
:
np
.
random
.
random
(
self
.
data_shape
).
astype
(
'float32'
),
}
self
.
enable_trt
=
True
self
.
trt_parameters
=
TRTReshapeTest
.
TensorRTParam
(
1
<<
30
,
self
.
bs
,
1
,
AnalysisConfig
.
Precision
.
Float32
,
False
,
False
)
self
.
fetch_list
=
[
out
]
class
TRTReshapeTest2
(
TRTReshapeTest
):
def
setUp
(
self
):
self
.
bs
=
1
self
.
input_shape
=
[
14
,
48
,
27
]
self
.
reshape
=
[
1
,
24
,
28
,
0
]
self
.
data_shape
=
[
self
.
bs
,
self
.
input_shape
[
0
],
self
.
input_shape
[
1
],
self
.
input_shape
[
2
]
]
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
'data'
,
shape
=
self
.
data_shape
,
dtype
=
'float32'
)
bn_out
=
fluid
.
layers
.
batch_norm
(
data
,
is_test
=
True
)
out
=
self
.
append_reshape
(
bn_out
,
self
.
reshape
)
self
.
feeds
=
{
'data'
:
np
.
random
.
random
(
self
.
data_shape
).
astype
(
'float32'
),
}
self
.
enable_trt
=
True
self
.
trt_parameters
=
TRTReshapeTest
.
TensorRTParam
(
1
<<
30
,
self
.
bs
,
1
,
AnalysisConfig
.
Precision
.
Float32
,
False
,
False
)
self
.
dynamic_shape_params
=
TRTReshapeTest
.
DynamicShapeParam
({
'data'
:
[
1
,
3
,
8
,
8
]
},
{
'data'
:
[
5
,
100
,
100
,
100
]},
{
'data'
:
[
1
,
3
,
16
,
16
]},
False
)
self
.
fetch_list
=
[
out
]
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录