Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
179d4264
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
179d4264
编写于
9月 04, 2023
作者:
M
ming1753
提交者:
GitHub
9月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify MarkTrtEngineOutputs API (#56858)
* Modify MarkTrtEngineOutputs API
上级
8aa1772c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
31 addition
and
18 deletion
+31
-18
paddle/fluid/inference/analysis/argument.h
paddle/fluid/inference/analysis/argument.h
+1
-0
paddle/fluid/inference/analysis/ir_pass_manager.cc
paddle/fluid/inference/analysis/ir_pass_manager.cc
+2
-0
paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
...id/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
+13
-12
paddle/fluid/inference/api/analysis_config.cc
paddle/fluid/inference/api/analysis_config.cc
+4
-1
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+1
-0
paddle/fluid/inference/api/paddle_analysis_config.h
paddle/fluid/inference/api/paddle_analysis_config.h
+3
-1
paddle/fluid/pybind/inference_api.cc
paddle/fluid/pybind/inference_api.cc
+2
-1
test/cpp/inference/api/trt_mark_trt_engine_outputs_test.cc
test/cpp/inference/api/trt_mark_trt_engine_outputs_test.cc
+5
-3
未找到文件。
paddle/fluid/inference/analysis/argument.h
浏览文件 @
179d4264
...
...
@@ -241,6 +241,7 @@ struct Argument {
DECL_ARGUMENT_FIELD
(
tensorrt_workspace_size
,
TensorRtWorkspaceSize
,
int64_t
);
DECL_ARGUMENT_FIELD
(
tensorrt_min_subgraph_size
,
TensorRtMinSubgraphSize
,
int
);
DECL_ARGUMENT_FIELD
(
trt_mark_output
,
TRTMarkOutput
,
bool
);
DECL_ARGUMENT_FIELD
(
trt_mark_output_with_id
,
TRTMarkOutputWithId
,
bool
);
DECL_ARGUMENT_FIELD
(
trt_output_tensor_names
,
TRTOutputTensorNames
,
std
::
vector
<
std
::
string
>
);
...
...
paddle/fluid/inference/analysis/ir_pass_manager.cc
浏览文件 @
179d4264
...
...
@@ -163,6 +163,8 @@ void IRPassManager::CreatePasses(Argument *argument,
pass
->
Set
(
"min_subgraph_size"
,
new
int
(
argument
->
tensorrt_min_subgraph_size
()));
pass
->
Set
(
"mark_output"
,
new
bool
(
argument
->
trt_mark_output
()));
pass
->
Set
(
"mark_output_with_id"
,
new
bool
(
argument
->
trt_mark_output_with_id
()));
pass
->
Set
(
"output_tensor_names"
,
new
std
::
vector
<
std
::
string
>
(
argument
->
trt_output_tensor_names
()));
...
...
paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
浏览文件 @
179d4264
...
...
@@ -376,29 +376,30 @@ std::string TensorRtSubgraphPass::CreateTensorRTOp(
std
::
vector
<
int
>
origin_outputs_dtype
;
std
::
map
<
std
::
string
,
int
>
map_origin_outputs_dtype
;
//
Whether to mark Outpu
s
//
Mark TensorRT output nodes as trt output
s
auto
mark_output
=
Get
<
bool
>
(
"mark_output"
);
auto
output_tensor_name
=
Get
<
std
::
vector
<
std
::
string
>>
(
"output_tensor_names"
);
VLOG
(
1
)
<<
"mark Output: "
<<
mark_output
;
auto
mark_output_with_id
=
Get
<
bool
>
(
"mark_output_with_id"
)
;
if
(
mark_output
==
1
)
{
if
(
mark_output
)
{
VLOG
(
1
)
<<
"begin to mark output ..."
;
for
(
auto
node
:
subgraph
)
{
if
(
node
->
NodeType
()
==
Node
::
Type
::
kOperation
)
{
if
(
node
->
Op
()
->
Outputs
().
count
(
"Xshape"
))
continue
;
for
(
auto
*
x
:
node
->
outputs
)
{
if
(
std
::
count
(
parameters
.
begin
(),
parameters
.
end
(),
x
->
Name
())
>
0
)
continue
;
if
(
!
output_tensor_name
.
empty
()
&&
std
::
count
(
output_tensor_name
.
begin
(),
output_tensor_name
.
end
(),
x
->
Name
()))
{
VLOG
(
1
)
<<
"output "
<<
x
->
Name
()
<<
" has been marked"
;
std
::
string
output_name_withid
=
x
->
Name
()
+
std
::
to_string
(
x
->
id
());
std
::
string
name_with_id
=
x
->
Name
()
+
std
::
to_string
(
x
->
id
());
if
(((
!
mark_output_with_id
&&
std
::
count
(
output_tensor_name
.
begin
(),
output_tensor_name
.
end
(),
x
->
Name
())
>
0
)
||
(
mark_output_with_id
&&
std
::
count
(
output_tensor_name
.
begin
(),
output_tensor_name
.
end
(),
name_with_id
)
>
0
))
&&
!
x
->
outputs
.
empty
())
{
VLOG
(
3
)
<<
"output "
<<
x
->
Name
()
<<
" has been marked"
;
output_names
.
insert
(
x
->
Name
());
output_names_with_id
.
insert
(
output_name_with
id
);
output_names_with_id
.
insert
(
name_with_
id
);
origin_name_output_rank
[
x
->
Name
()]
=
x
->
Var
()
->
GetShape
().
size
();
trt_outputs
.
insert
(
x
);
map_origin_outputs_dtype
[
x
->
Name
()]
=
...
...
paddle/fluid/inference/api/analysis_config.cc
浏览文件 @
179d4264
...
...
@@ -461,6 +461,7 @@ AnalysisConfig::AnalysisConfig(const AnalysisConfig &other) {
CP_MEMBER
(
tensorrt_min_subgraph_size_
);
CP_MEMBER
(
tensorrt_precision_mode_
);
CP_MEMBER
(
trt_mark_output_
);
CP_MEMBER
(
trt_mark_output_with_id_
);
CP_MEMBER
(
trt_output_tensor_names_
);
CP_MEMBER
(
trt_disabled_ops_
);
CP_MEMBER
(
trt_use_dla_
);
...
...
@@ -762,8 +763,10 @@ void AnalysisConfig::EnableTensorRtEngine(int64_t workspace_size,
}
void
AnalysisConfig
::
MarkTrtEngineOutputs
(
const
std
::
vector
<
std
::
string
>
&
output_tensor_names
)
{
const
std
::
vector
<
std
::
string
>
&
output_tensor_names
,
const
bool
mark_output_with_id
)
{
trt_mark_output_
=
true
;
trt_mark_output_with_id_
=
mark_output_with_id
;
trt_output_tensor_names_
=
output_tensor_names
;
}
...
...
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
179d4264
...
...
@@ -1392,6 +1392,7 @@ void AnalysisPredictor::PrepareArgument() {
argument_
->
SetTensorRtMaxBatchSize
(
config_
.
tensorrt_max_batchsize_
);
argument_
->
SetTensorRtMinSubgraphSize
(
config_
.
tensorrt_min_subgraph_size_
);
argument_
->
SetTRTMarkOutput
(
config_
.
trt_mark_output_
);
argument_
->
SetTRTMarkOutputWithId
(
config_
.
trt_mark_output_with_id_
);
argument_
->
SetTRTOutputTensorNames
(
config_
.
trt_output_tensor_names_
);
argument_
->
SetTensorRtDisabledOPs
(
config_
.
trt_disabled_ops_
);
argument_
->
SetTensorRtUseDLA
(
config_
.
trt_use_dla_
);
...
...
paddle/fluid/inference/api/paddle_analysis_config.h
浏览文件 @
179d4264
...
...
@@ -695,7 +695,8 @@ struct PD_INFER_DECL AnalysisConfig {
/// \param output_tensor_names The name of the Tensor that needs to be marked
///
void
MarkTrtEngineOutputs
(
const
std
::
vector
<
std
::
string
>&
output_tensor_names
=
{});
const
std
::
vector
<
std
::
string
>&
output_tensor_names
=
{},
const
bool
trt_mark_output_with_id
=
false
);
///
/// \brief Turn on the TensorRT memory optimization.
///
...
...
@@ -1237,6 +1238,7 @@ struct PD_INFER_DECL AnalysisConfig {
bool
trt_use_varseqlen_
{
false
};
bool
trt_with_interleaved_
{
false
};
bool
trt_mark_output_
{
false
};
bool
trt_mark_output_with_id_
{
false
};
std
::
vector
<
std
::
string
>
trt_output_tensor_names_
{};
std
::
string
tensorrt_transformer_posid_
{
""
};
std
::
string
tensorrt_transformer_maskid_
{
""
};
...
...
paddle/fluid/pybind/inference_api.cc
浏览文件 @
179d4264
...
...
@@ -896,7 +896,8 @@ void BindAnalysisConfig(py::module *m) {
&
AnalysisConfig
::
tensorrt_dynamic_shape_enabled
)
.
def
(
"mark_trt_engine_outputs"
,
&
AnalysisConfig
::
MarkTrtEngineOutputs
,
py
::
arg
(
"output_tensor_names"
)
=
std
::
vector
<
std
::
string
>
({}))
py
::
arg
(
"output_tensor_names"
)
=
std
::
vector
<
std
::
string
>
({}),
py
::
arg
(
"mark_output_with_id"
)
=
false
)
.
def
(
"enable_tensorrt_varseqlen"
,
&
AnalysisConfig
::
EnableVarseqlen
)
.
def
(
"tensorrt_varseqlen_enabled"
,
&
AnalysisConfig
::
tensorrt_varseqlen_enabled
)
...
...
test/cpp/inference/api/trt_mark_trt_engine_outputs_test.cc
浏览文件 @
179d4264
...
...
@@ -24,9 +24,11 @@ TEST(TensorRT, mark_trt_engine_outputs) {
config
.
EnableUseGpu
(
100
,
0
);
config
.
EnableTensorRtEngine
(
1
<<
30
,
1
,
5
,
AnalysisConfig
::
Precision
::
kFloat32
,
false
,
false
);
// The name of the tensor that needs to be marked, the default is empty (all
// marks)
std
::
vector
<
std
::
string
>
markOutput
=
{
"fc_0.tmp_0"
,
"fc_0.tmp_1"
};
// The name of the tensor that needs to be marked
std
::
vector
<
std
::
string
>
markOutput
=
{
"pool2d_0.tmp_0"
,
"elementwise_add_0.tmp_0"
,
"conv2d_5.tmp_0"
,
"batch_norm_6.tmp_2"
};
config
.
MarkTrtEngineOutputs
(
markOutput
);
std
::
vector
<
std
::
vector
<
PaddleTensor
>>
inputs_all
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录