Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
6c54e0e8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6c54e0e8
编写于
11月 16, 2022
作者:
Z
Zhang Jun
提交者:
GitHub
11月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[inference][trt] update trt hardswish plugin to layer (#47745)
上级
7c304580
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
26 addition
and
17 deletion
+26
-17
paddle/fluid/inference/tensorrt/convert/hard_swish_op.cc
paddle/fluid/inference/tensorrt/convert/hard_swish_op.cc
+26
-17
未找到文件。
paddle/fluid/inference/tensorrt/convert/hard_swish_op.cc
浏览文件 @
6c54e0e8
...
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/inference/tensorrt/convert/op_converter.h"
#include "paddle/fluid/inference/tensorrt/plugin/hard_swish_op_plugin.h"
namespace
paddle
{
namespace
framework
{
...
...
@@ -41,7 +40,6 @@ class HardSwishOpConverter : public OpConverter {
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
// Declare inputs
int
input_num
=
op_desc
.
Input
(
"X"
).
size
();
auto
*
input
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
const
float
threshold
=
...
...
@@ -69,21 +67,32 @@ class HardSwishOpConverter : public OpConverter {
nvinfer1
::
ElementWiseOperation
::
kPROD
);
layer
=
eltwise_layer
;
}
else
{
if
(
engine_
->
with_dynamic_shape
())
{
#if IS_TRT_VERSION_GE(6000)
plugin
::
HardSwishPluginDynamic
*
plugin
=
new
plugin
::
HardSwishPluginDynamic
(
threshold
,
scale
,
offset
);
layer
=
engine_
->
AddDynamicPlugin
(
&
input
,
input_num
,
plugin
);
#else
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"You are running the TRT Dynamic Shape mode, need to confirm that "
"your TRT version is no less than 6.0"
));
#endif
}
else
{
plugin
::
HardSwishPlugin
*
plugin
=
new
plugin
::
HardSwishPlugin
(
threshold
,
scale
,
offset
);
layer
=
engine_
->
AddPlugin
(
&
input
,
input_num
,
plugin
);
}
int32_t
rank
=
input
->
getDimensions
().
nbDims
;
nvinfer1
::
Dims
constant_shape
;
constant_shape
.
nbDims
=
rank
;
std
::
fill
(
constant_shape
.
d
,
constant_shape
.
d
+
rank
,
1
);
std
::
vector
<
float
>
weight_threshold_data
{
threshold
};
std
::
vector
<
float
>
weight_scale_data
{
scale
};
std
::
vector
<
float
>
weight_offset_data
{
offset
};
std
::
vector
<
float
>
weight_zero_data
{
0.
f
};
auto
*
threshold_data
=
AddConstantLayer
(
weight_threshold_data
.
data
(),
constant_shape
);
auto
*
scale_data
=
AddConstantLayer
(
weight_scale_data
.
data
(),
constant_shape
);
auto
*
offset_data
=
AddConstantLayer
(
weight_offset_data
.
data
(),
constant_shape
);
auto
*
zero_data
=
AddConstantLayer
(
weight_zero_data
.
data
(),
constant_shape
);
auto
*
input_sum_with_offset
=
Sum
(
input
,
offset_data
);
auto
*
pre_max_with_zero
=
Max
(
input_sum_with_offset
,
zero_data
);
auto
*
pre_min_with_threshold
=
Min
(
pre_max_with_zero
,
threshold_data
);
auto
*
pre_prod_with_input
=
Prod
(
pre_min_with_threshold
,
input
);
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
pre_prod_with_input
,
*
scale_data
,
nvinfer1
::
ElementWiseOperation
::
kDIV
);
}
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"hard_swish"
,
{
output_name
},
test_mode
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录