Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ff44df18
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看板
未验证
提交
ff44df18
编写于
11月 17, 2022
作者:
X
xiaoxiaohehe001
提交者:
GitHub
11月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Paddle Inference] Support cast trt converter of bool input and output . (#48043)
* add_cast_bool * cast
上级
bf6af816
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
8 deletion
+30
-8
paddle/fluid/inference/tensorrt/convert/cast_op.cc
paddle/fluid/inference/tensorrt/convert/cast_op.cc
+7
-0
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+8
-3
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_cast.py
...uid/tests/unittests/ir/inference/test_trt_convert_cast.py
+14
-4
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_where.py
...id/tests/unittests/ir/inference/test_trt_convert_where.py
+1
-1
未找到文件。
paddle/fluid/inference/tensorrt/convert/cast_op.cc
浏览文件 @
ff44df18
...
...
@@ -42,14 +42,21 @@ class CastOpConverter : public OpConverter {
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Identity
,
*
input
);
switch
(
out_dtype
)
{
case
0
:
// BOOL = 0
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kBOOL
);
layer
->
getOutput
(
0
)
->
setType
(
nvinfer1
::
DataType
::
kBOOL
);
break
;
case
2
:
// INT32 = 2
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kINT32
);
layer
->
getOutput
(
0
)
->
setType
(
nvinfer1
::
DataType
::
kINT32
);
break
;
case
4
:
// FP16 = 4
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kHALF
);
layer
->
getOutput
(
0
)
->
setType
(
nvinfer1
::
DataType
::
kHALF
);
break
;
case
5
:
// FP32 = 5
layer
->
setOutputType
(
0
,
nvinfer1
::
DataType
::
kFLOAT
);
layer
->
getOutput
(
0
)
->
setType
(
nvinfer1
::
DataType
::
kFLOAT
);
break
;
default:
LOG
(
ERROR
)
<<
"Unable to convert a fluid data type("
<<
out_dtype
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
ff44df18
...
...
@@ -2124,10 +2124,15 @@ struct SimpleOpTypeSetTeller : public Teller {
VLOG
(
3
)
<<
"unsupport data type conversion"
;
return
false
;
}
if
(
in_dtype
==
0
)
{
VLOG
(
3
)
<<
"do not support input data type as bool now"
;
return
false
;
#if IS_TRT_VERSION_GE(8400)
if
(
in_dtype
==
0
||
out_dtype
==
0
)
{
if
(
with_dynamic_shape
)
{
VLOG
(
3
)
<<
"the cast op supports inputs and outputs of BOOL by "
"trt8.4 above "
;
return
true
;
}
}
#endif
if
(
!
((
in_dtype
==
5
||
in_dtype
==
4
||
in_dtype
==
2
)
&&
(
out_dtype
==
5
||
out_dtype
==
4
||
out_dtype
==
2
)))
{
VLOG
(
3
)
<<
"only valid conversions are: "
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_cast.py
浏览文件 @
ff44df18
...
...
@@ -30,9 +30,16 @@ class TrtConvertCastTest(TrtLayerAutoScanTest):
return
False
if
attrs
[
0
][
'in_dtype'
]
in
[
4
,
5
]
and
attrs
[
0
][
'out_dtype'
]
==
4
:
return
False
if
attrs
[
0
][
'in_dtype'
]
not
in
[
2
,
4
,
5
]
or
attrs
[
0
][
'out_dtype'
]
not
in
[
2
,
4
,
5
]:
out_dtype
=
[
2
,
4
,
5
]
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
2
]
*
10
>
8400
:
out_dtype
.
insert
(
3
,
0
)
if
(
attrs
[
0
][
'in_dtype'
]
not
in
[
2
,
4
,
5
]
or
attrs
[
0
][
'out_dtype'
]
not
in
out_dtype
):
return
False
return
True
...
...
@@ -49,6 +56,7 @@ class TrtConvertCastTest(TrtLayerAutoScanTest):
for
in_dtype
in
[
0
,
2
,
5
,
6
]:
for
out_dtype
in
[
0
,
2
,
5
,
6
]:
self
.
out_dtype
=
out_dtype
dics
=
[
{
"in_dtype"
:
in_dtype
,
"out_dtype"
:
out_dtype
},
{
"in_dtype"
:
out_dtype
,
"out_dtype"
:
in_dtype
},
...
...
@@ -89,7 +97,7 @@ class TrtConvertCastTest(TrtLayerAutoScanTest):
)
->
(
paddle_infer
.
Config
,
List
[
int
],
float
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]}
def
clear_dynamic_shape
():
...
...
@@ -98,6 +106,8 @@ class TrtConvertCastTest(TrtLayerAutoScanTest):
self
.
dynamic_shape
.
opt_input_shape
=
{}
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
if
not
dynamic_shape
and
self
.
out_dtype
==
0
:
return
0
,
4
return
1
,
2
attrs
=
[
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_where.py
浏览文件 @
ff44df18
...
...
@@ -195,7 +195,7 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
if
not
dynamic_shape
:
return
0
,
6
return
1
,
5
return
1
,
4
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录