Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
30b10630
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
30b10630
编写于
6月 13, 2022
作者:
Z
zhoutianzi666
提交者:
GitHub
6月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add only split (#43424)
上级
65e86580
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
313 addition
and
51 deletion
+313
-51
paddle/fluid/inference/tensorrt/convert/op_converter.h
paddle/fluid/inference/tensorrt/convert/op_converter.h
+197
-2
paddle/fluid/inference/tensorrt/convert/split_op.cc
paddle/fluid/inference/tensorrt/convert/split_op.cc
+87
-21
paddle/fluid/inference/tensorrt/engine.h
paddle/fluid/inference/tensorrt/engine.h
+1
-1
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+0
-9
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_slice.py
...id/tests/unittests/ir/inference/test_trt_convert_slice.py
+8
-6
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_split.py
...id/tests/unittests/ir/inference/test_trt_convert_split.py
+20
-12
未找到文件。
paddle/fluid/inference/tensorrt/convert/op_converter.h
浏览文件 @
30b10630
...
@@ -295,20 +295,215 @@ class OpConverter {
...
@@ -295,20 +295,215 @@ class OpConverter {
engine
->
ClearWeights
();
engine
->
ClearWeights
();
}
}
// rank(result) = rank(input)
nvinfer1
::
ITensor
*
Gather
(
nvinfer1
::
ITensor
*
input
,
const
std
::
vector
<
int32_t
>
indices
,
int
axis
=
0
)
{
auto
*
indices_tensor
=
Add1DConstantLayer
(
indices
,
" "
);
auto
*
result
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Gather
,
*
input
,
*
indices_tensor
,
axis
)
->
getOutput
(
0
);
return
result
;
}
// paddle allows negative index
// for axis length = 5, paddle allows [-5, 4]
nvinfer1
::
ITensor
*
FixNegIndices
(
nvinfer1
::
ITensor
*
input_shape
,
nvinfer1
::
ITensor
*
indices
)
{
int
rank
=
input_shape
->
getDimensions
().
nbDims
;
std
::
vector
<
int32_t
>
zero
=
std
::
vector
<
int32_t
>
(
rank
,
0
);
std
::
vector
<
int32_t
>
minus_one
=
std
::
vector
<
int32_t
>
(
rank
,
-
1
);
nvinfer1
::
ITensor
*
zero_tensor
=
Add1DConstantLayer
(
zero
);
nvinfer1
::
ITensor
*
minus_one_tensor
=
Add1DConstantLayer
(
minus_one
);
// -1, 0
auto
*
sign
=
Max
(
Min
(
indices
,
zero_tensor
),
minus_one_tensor
);
return
Sub
(
indices
,
Prod
(
sign
,
input_shape
));
}
nvinfer1
::
ITensor
*
Shape
(
nvinfer1
::
ITensor
*
input
)
{
return
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shape
,
*
input
)
->
getOutput
(
0
);
}
// Concat not make rank changed
nvinfer1
::
ITensor
*
Concat
(
const
std
::
vector
<
nvinfer1
::
ITensor
*>&
inputs
,
int
axis
=
0
)
{
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Concatenation
,
inputs
.
data
(),
inputs
.
size
());
if
(
axis
!=
0
)
layer
->
setAxis
(
axis
);
nvinfer1
::
ITensor
*
c
=
layer
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Sum
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kSUM
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Prod
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kPROD
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Min
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kMIN
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Max
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kMAX
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Sub
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kSUB
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Div
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ITensor
*
b
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
a
,
*
b
,
nvinfer1
::
ElementWiseOperation
::
kDIV
)
->
getOutput
(
0
);
return
c
;
}
nvinfer1
::
ITensor
*
Act
(
nvinfer1
::
ITensor
*
a
,
nvinfer1
::
ActivationType
act_type
)
{
nvinfer1
::
ITensor
*
c
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Activation
,
*
a
,
act_type
)
->
getOutput
(
0
);
return
c
;
}
// Get element tensor of 1D shape tensor
nvinfer1
::
ITensor
*
GetEleTensorOfShape
(
nvinfer1
::
ITensor
*
shape_tensor
,
int
index
,
bool
is_scalar
=
false
)
{
auto
*
tensor
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Gather
,
*
shape_tensor
,
*
Add1DConstantLayer
(
index
,
" "
,
is_scalar
),
0
)
->
getOutput
(
0
);
return
tensor
;
}
// Create and add Multi-D constant float layer
nvinfer1
::
ITensor
*
AddConstantLayer
(
const
float
*
data
,
const
std
::
vector
<
int32_t
>&
weight_dims
,
const
std
::
string
&
weight_name
)
{
std
::
unique_ptr
<
framework
::
Tensor
>
tmp_tensor
(
new
framework
::
Tensor
());
int
data_size
=
std
::
accumulate
(
weight_dims
.
begin
(),
weight_dims
.
end
(),
1
,
std
::
multiplies
<
int
>
());
tmp_tensor
->
Resize
({
data_size
});
auto
*
tmp_data
=
tmp_tensor
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
data
[
i
];
}
engine_
->
SetWeights
(
weight_name
,
std
::
move
(
tmp_tensor
));
TensorRTEngine
::
Weight
weight
{
nvinfer1
::
DataType
::
kFLOAT
,
static_cast
<
void
*>
(
tmp_data
),
static_cast
<
size_t
>
(
data_size
)};
nvinfer1
::
Dims
trt_dims
;
trt_dims
.
nbDims
=
weight_dims
.
size
();
for
(
size_t
i
=
0
;
i
<
weight_dims
.
size
();
i
++
)
trt_dims
.
d
[
i
]
=
weight_dims
[
i
];
auto
const_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Constant
,
trt_dims
,
weight
.
get
());
return
const_layer
->
getOutput
(
0
);
}
// Create and add 1D constant float layer
nvinfer1
::
ITensor
*
Add1DConstantLayer
(
const
std
::
vector
<
float
>&
data
,
const
std
::
string
&
weight_name
=
""
,
bool
scalar
=
false
)
{
std
::
unique_ptr
<
framework
::
Tensor
>
tmp_tensor
(
new
framework
::
Tensor
());
int
data_size
=
data
.
size
();
tmp_tensor
->
Resize
({
data_size
});
auto
*
tmp_data
=
tmp_tensor
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
data
[
i
];
}
engine_
->
SetWeights
(
weight_name
,
std
::
move
(
tmp_tensor
));
TensorRTEngine
::
Weight
weight
{
nvinfer1
::
DataType
::
kFLOAT
,
static_cast
<
void
*>
(
tmp_data
),
static_cast
<
size_t
>
(
data_size
)};
nvinfer1
::
Dims
input_shape
;
input_shape
.
nbDims
=
scalar
?
0
:
1
;
input_shape
.
d
[
0
]
=
data_size
;
auto
const_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Constant
,
input_shape
,
weight
.
get
());
return
const_layer
->
getOutput
(
0
);
}
// Create and add 1D constant layer
nvinfer1
::
ITensor
*
Add1DConstantLayer
(
const
std
::
vector
<
int
>&
data
,
const
std
::
string
&
weight_name
=
""
,
bool
scalar
=
false
)
{
std
::
unique_ptr
<
framework
::
Tensor
>
tmp_tensor
(
new
framework
::
Tensor
());
int
data_size
=
data
.
size
();
tmp_tensor
->
Resize
({
data_size
});
auto
*
tmp_data
=
tmp_tensor
->
mutable_data
<
int
>
(
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
data
[
i
];
}
engine_
->
SetWeights
(
weight_name
,
std
::
move
(
tmp_tensor
));
TensorRTEngine
::
Weight
weight
{
nvinfer1
::
DataType
::
kINT32
,
static_cast
<
void
*>
(
tmp_data
),
static_cast
<
size_t
>
(
data_size
)};
nvinfer1
::
Dims
input_shape
;
input_shape
.
nbDims
=
scalar
?
0
:
1
;
input_shape
.
d
[
0
]
=
data_size
;
auto
const_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Constant
,
input_shape
,
weight
.
get
());
return
const_layer
->
getOutput
(
0
);
}
nvinfer1
::
ITensor
*
Add1DConstantLayer
(
nvinfer1
::
Dims
data
,
const
std
::
string
&
weight_name
=
""
,
bool
scalar
=
false
)
{
std
::
vector
<
int
>
tmp_data
;
for
(
int
i
=
0
;
i
<
data
.
nbDims
;
i
++
)
tmp_data
.
push_back
(
data
.
d
[
i
]);
return
Add1DConstantLayer
(
tmp_data
,
weight_name
,
scalar
);
}
nvinfer1
::
ITensor
*
Add1DConstantLayer
(
int32_t
data
,
const
std
::
string
&
weight_name
=
""
,
bool
scalar
=
false
)
{
std
::
vector
<
int
>
tmp_data
;
tmp_data
.
push_back
(
data
);
return
Add1DConstantLayer
(
tmp_data
,
weight_name
,
scalar
);
}
void
RreplenishLayerAndOutput
(
void
RreplenishLayerAndOutput
(
nvinfer1
::
ILayer
*
layer
,
const
std
::
string
&
layer_type
,
nvinfer1
::
ILayer
*
layer
,
const
std
::
string
&
layer_type
,
const
std
::
vector
<
std
::
string
>&
output_tensor_names
,
const
std
::
vector
<
std
::
string
>&
output_tensor_names
,
bool
test_mode
=
false
)
{
bool
test_mode
=
false
)
{
size_t
num_out
=
output_tensor_names
.
size
();
size_t
num_out
=
output_tensor_names
.
size
();
std
::
string
layer_name
=
layer_type
+
" (Output: "
;
for
(
size_t
i
=
0
;
i
<
num_out
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
num_out
;
i
++
)
{
layer
->
getOutput
(
i
)
->
setName
(
output_tensor_names
[
i
].
c_str
());
layer
->
getOutput
(
i
)
->
setName
(
output_tensor_names
[
i
].
c_str
());
engine_
->
SetITensor
(
output_tensor_names
[
i
],
layer
->
getOutput
(
i
));
engine_
->
SetITensor
(
output_tensor_names
[
i
],
layer
->
getOutput
(
i
));
if
(
test_mode
)
{
if
(
test_mode
)
{
engine_
->
DeclareOutput
(
output_tensor_names
[
i
]);
engine_
->
DeclareOutput
(
output_tensor_names
[
i
]);
}
}
layer_name
+=
output_tensor_names
[
i
];
if
(
i
!=
num_out
-
1
)
layer_name
+=
", "
;
}
}
layer
->
setName
(
layer
->
setName
((
layer_name
+
")"
).
c_str
());
(
layer_type
+
" (Output: "
+
output_tensor_names
[
0
]
+
")"
).
c_str
());
}
}
void
SetEngine
(
TensorRTEngine
*
engine
)
{
engine_
=
engine
;
}
void
SetEngine
(
TensorRTEngine
*
engine
)
{
engine_
=
engine
;
}
...
...
paddle/fluid/inference/tensorrt/convert/split_op.cc
浏览文件 @
30b10630
...
@@ -29,7 +29,6 @@ class SplitOpConverter : public OpConverter {
...
@@ -29,7 +29,6 @@ class SplitOpConverter : public OpConverter {
// Declare inputs
// Declare inputs
auto
*
input
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
auto
*
input
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
auto
input_dims
=
input
->
getDimensions
();
auto
input_dims
=
input
->
getDimensions
();
size_t
input_num
=
op_desc
.
Input
(
"X"
).
size
();
size_t
output_num
=
op_desc
.
Output
(
"Out"
).
size
();
size_t
output_num
=
op_desc
.
Output
(
"Out"
).
size
();
// Get Attrs
// Get Attrs
...
@@ -41,48 +40,115 @@ class SplitOpConverter : public OpConverter {
...
@@ -41,48 +40,115 @@ class SplitOpConverter : public OpConverter {
if
(
op_desc
.
HasAttr
(
"num"
))
{
if
(
op_desc
.
HasAttr
(
"num"
))
{
num
=
BOOST_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"num"
));
num
=
BOOST_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"num"
));
}
}
nvinfer1
::
ITensor
*
shape_tensor
=
nullptr
;
if
(
engine_
->
with_dynamic_shape
())
{
if
(
engine_
->
with_dynamic_shape
())
{
#if IS_TRT_VERSION_GE(6000)
axis
+=
(
axis
<
0
)
?
input_dims
.
nbDims
:
0
;
axis
+=
(
axis
<
0
)
?
input_dims
.
nbDims
:
0
;
#endif
// only be called in dynamic_shape mode
shape_tensor
=
Shape
(
input
);
}
else
{
}
else
{
axis
+=
(
axis
<
0
)
?
input_dims
.
nbDims
:
-
1
;
axis
+=
(
axis
<
0
)
?
input_dims
.
nbDims
:
-
1
;
}
}
if
(
num
>
0
)
{
bool
in_axis_dim_dynamic
=
false
;
int64_t
in_axis_dim
=
input_dims
.
d
[
axis
];
nvinfer1
::
ITensor
*
avg_len_tensor
=
nullptr
;
size_t
out_axis_dim
=
in_axis_dim
/
num
;
// need infer output_lengths
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
if
(
num
>
0
&&
output_lengths
.
empty
())
{
output_lengths
.
push_back
(
out_axis_dim
);
if
(
input_dims
.
d
[
axis
]
>
0
)
{
int64_t
in_axis_dim
=
input_dims
.
d
[
axis
];
size_t
out_axis_dim
=
in_axis_dim
/
num
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
output_lengths
.
push_back
(
out_axis_dim
);
}
}
else
{
in_axis_dim_dynamic
=
true
;
auto
*
num_tensor
=
Add1DConstantLayer
(
num
);
avg_len_tensor
=
Div
(
GetEleTensorOfShape
(
shape_tensor
,
axis
),
num_tensor
);
}
}
}
}
nvinfer1
::
ILayer
*
layer
=
nullptr
;
nvinfer1
::
ILayer
*
layer
=
nullptr
;
#if IS_TRT_VERSION_GE(6000)
if
(
engine_
->
with_dynamic_shape
())
{
nvinfer1
::
Dims
trt_step_dims
;
trt_step_dims
.
nbDims
=
input
->
getDimensions
().
nbDims
;
for
(
int
i
=
0
;
i
<
trt_step_dims
.
nbDims
;
i
++
)
trt_step_dims
.
d
[
i
]
=
1
;
std
::
vector
<
int32_t
>
gather_indices
;
gather_indices
.
resize
(
trt_step_dims
.
nbDims
);
std
::
iota
(
gather_indices
.
begin
(),
gather_indices
.
end
(),
0
);
gather_indices
[
axis
]
=
gather_indices
.
size
();
std
::
vector
<
int32_t
>
zeros
(
trt_step_dims
.
nbDims
,
0
);
auto
*
zeros_tensor
=
Add1DConstantLayer
(
zeros
);
// input : [N,C,H,W]
int
start_point
=
0
;
for
(
size_t
i
=
0
;
i
<
output_num
;
i
++
)
{
nvinfer1
::
ITensor
*
this_len_tensor
=
nullptr
;
nvinfer1
::
ITensor
*
start_point_tensor
=
nullptr
;
if
(
!
in_axis_dim_dynamic
)
{
this_len_tensor
=
Add1DConstantLayer
(
output_lengths
[
i
]);
start_point_tensor
=
Add1DConstantLayer
(
start_point
);
start_point
+=
output_lengths
[
i
];
}
else
{
this_len_tensor
=
avg_len_tensor
;
auto
*
i_tensor
=
Add1DConstantLayer
(
i
);
start_point_tensor
=
Prod
(
i_tensor
,
avg_len_tensor
);
}
std
::
vector
<
nvinfer1
::
ITensor
*>
concat_inputs1
=
{
zeros_tensor
,
start_point_tensor
};
std
::
vector
<
nvinfer1
::
ITensor
*>
concat_inputs2
=
{
shape_tensor
,
this_len_tensor
};
auto
*
start_tensor
=
Gather
(
Concat
(
concat_inputs1
),
gather_indices
);
auto
*
size_tensor
=
Gather
(
Concat
(
concat_inputs2
),
gather_indices
);
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Slice
,
*
input
,
trt_step_dims
,
trt_step_dims
,
trt_step_dims
);
layer
->
setInput
(
1
,
*
start_tensor
);
layer
->
setInput
(
2
,
*
size_tensor
);
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
i
];
RreplenishLayerAndOutput
(
layer
,
"split"
,
{
output_name
},
test_mode
);
}
}
else
{
auto
chw_input_dims
=
input
->
getDimensions
();
nvinfer1
::
Dims
trt_start_dims
;
trt_start_dims
.
nbDims
=
chw_input_dims
.
nbDims
;
memset
(
trt_start_dims
.
d
,
0
,
sizeof
(
int32_t
)
*
chw_input_dims
.
nbDims
);
nvinfer1
::
Dims
trt_size_dims
=
chw_input_dims
;
nvinfer1
::
Dims
trt_step_dims
;
trt_step_dims
.
nbDims
=
chw_input_dims
.
nbDims
;
for
(
int
i
=
0
;
i
<
trt_step_dims
.
nbDims
;
i
++
)
trt_step_dims
.
d
[
i
]
=
1
;
// input : [C,H,W]
for
(
size_t
i
=
0
;
i
<
output_num
;
i
++
)
{
trt_start_dims
.
d
[
axis
]
=
std
::
accumulate
(
output_lengths
.
begin
(),
output_lengths
.
begin
()
+
i
,
0
);
trt_size_dims
.
d
[
axis
]
=
output_lengths
[
i
];
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Slice
,
*
input
,
trt_start_dims
,
trt_size_dims
,
trt_step_dims
);
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
i
];
RreplenishLayerAndOutput
(
layer
,
"split"
,
{
output_name
},
test_mode
);
}
}
#else
if
(
engine_
->
with_dynamic_shape
())
{
if
(
engine_
->
with_dynamic_shape
())
{
bool
with_fp16
=
bool
with_fp16
=
engine_
->
WithFp16
()
&&
!
engine_
->
disable_trt_plugin_fp16
();
engine_
->
WithFp16
()
&&
!
engine_
->
disable_trt_plugin_fp16
();
plugin
::
SplitPluginDynamic
*
plugin
=
plugin
::
SplitPluginDynamic
*
plugin
=
new
plugin
::
SplitPluginDynamic
(
axis
,
output_lengths
,
with_fp16
);
new
plugin
::
SplitPluginDynamic
(
axis
,
output_lengths
,
with_fp16
);
layer
=
engine_
->
AddDynamicPlugin
(
&
input
,
input_num
,
plugin
);
layer
=
engine_
->
AddDynamicPlugin
(
&
input
,
1
,
plugin
);
}
else
{
}
else
{
bool
with_fp16
=
bool
with_fp16
=
engine_
->
WithFp16
()
&&
!
engine_
->
disable_trt_plugin_fp16
();
engine_
->
WithFp16
()
&&
!
engine_
->
disable_trt_plugin_fp16
();
plugin
::
SplitPlugin
*
plugin
=
plugin
::
SplitPlugin
*
plugin
=
new
plugin
::
SplitPlugin
(
axis
,
output_lengths
,
with_fp16
);
new
plugin
::
SplitPlugin
(
axis
,
output_lengths
,
with_fp16
);
layer
=
engine_
->
AddPluginV2Ext
(
&
input
,
input_num
,
plugin
);
layer
=
engine_
->
AddPluginV2Ext
(
&
input
,
1
,
plugin
);
}
}
std
::
vector
<
std
::
string
>
output_names
;
std
::
string
layer_name
=
"split (Output: "
;
for
(
size_t
i
=
0
;
i
<
output_num
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
output_num
;
i
++
)
{
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
i
];
output_names
.
push_back
(
op_desc
.
Output
(
"Out"
)[
i
]);
layer
->
getOutput
(
i
)
->
setName
(
output_name
.
c_str
());
engine_
->
SetITensor
(
output_name
,
layer
->
getOutput
(
i
));
layer_name
+=
output_name
;
if
(
test_mode
)
{
engine_
->
DeclareOutput
(
output_name
);
}
}
}
layer
->
setName
((
layer_name
+
")"
).
c_str
());
RreplenishLayerAndOutput
(
layer
,
"split"
,
output_names
,
test_mode
);
#endif
}
}
};
};
...
...
paddle/fluid/inference/tensorrt/engine.h
浏览文件 @
30b10630
...
@@ -686,7 +686,7 @@ class TensorRTEngine {
...
@@ -686,7 +686,7 @@ class TensorRTEngine {
// them, and an macro like this is more extensible when underlying TensorRT
// them, and an macro like this is more extensible when underlying TensorRT
// library add new layer supports.
// library add new layer supports.
#define TRT_ENGINE_ADD_LAYER(engine__, layer__, ...) \
#define TRT_ENGINE_ADD_LAYER(engine__, layer__, ...) \
engine__->network()->add##layer__(__VA_ARGS__)
;
engine__->network()->add##layer__(__VA_ARGS__)
class
TRTEngineManager
{
class
TRTEngineManager
{
public:
public:
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
30b10630
...
@@ -1041,15 +1041,6 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
...
@@ -1041,15 +1041,6 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
return
false
;
return
false
;
}
}
}
}
}
else
{
for
(
size_t
i
=
0
;
i
<
axes
.
size
();
i
++
)
{
if
(
starts
[
i
]
<
0
||
ends
[
i
]
<
0
)
{
VLOG
(
3
)
<<
"Invalid slice attribute 'starts' or 'ends'. "
"Negative starts or ends not supported in TensorRT "
"when running in dynamic shape mode."
;
return
false
;
}
}
}
}
}
}
}
}
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_slice.py
浏览文件 @
30b10630
...
@@ -29,10 +29,7 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -29,10 +29,7 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
attrs
=
[
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
]
]
out_shape
=
list
(
inputs
[
'input_data'
].
shape
)
for
x
in
attrs
[
0
][
"decrease_axis"
]:
if
x
<
0
:
return
False
for
x
in
range
(
len
(
attrs
[
0
][
"axes"
])):
for
x
in
range
(
len
(
attrs
[
0
][
"axes"
])):
start
=
0
start
=
0
end
=
0
end
=
0
...
@@ -48,15 +45,20 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -48,15 +45,20 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
end
=
attrs
[
0
][
"ends"
][
x
]
end
=
attrs
[
0
][
"ends"
][
x
]
start
=
max
(
0
,
start
)
start
=
max
(
0
,
start
)
end
=
max
(
0
,
end
)
end
=
max
(
0
,
end
)
out_shape
[
attrs
[
0
][
"axes"
][
x
]]
=
end
-
start
if
start
>=
end
:
if
start
>=
end
:
return
False
return
False
for
x
in
attrs
[
0
][
"decrease_axis"
]:
if
x
<
0
:
return
False
if
(
out_shape
[
x
]
!=
1
):
return
False
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
return
np
.
ones
([
6
,
6
,
64
,
64
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
6
,
6
,
64
,
64
]).
astype
(
np
.
float32
)
for
axes
in
[[
0
,
1
],
[
1
,
3
],
[
2
,
3
]]:
for
axes
in
[[
0
,
1
],
[
1
,
3
],
[
2
,
3
]]:
for
starts
in
[[
0
,
1
]]:
for
starts
in
[[
0
,
1
]]:
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_split.py
浏览文件 @
30b10630
...
@@ -73,13 +73,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -73,13 +73,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
3
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
return
np
.
ones
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
return
np
.
ones
([
batch
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
24
]).
astype
(
np
.
float32
)
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
return
np
.
ones
([
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
24
]).
astype
(
np
.
float32
)
def
generate_AxisTensor
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_AxisTensor
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
return
np
.
ones
([
1
]).
astype
(
np
.
int32
)
return
np
.
ones
([
1
]).
astype
(
np
.
int32
)
...
@@ -162,25 +162,33 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -162,25 +162,33 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
def
generate_dynamic_shape
(
attrs
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"split_input"
:
[
1
,
3
,
3
,
24
]
"split_input"
:
[
1
,
3
-
1
,
3
-
1
,
24
-
1
]
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
9
,
3
,
3
,
24
]
"split_input"
:
[
9
,
3
+
1
,
3
+
1
,
24
+
1
]
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
1
,
3
,
3
,
24
]
"split_input"
:
[
1
,
3
,
3
,
24
]
}
}
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
self
.
dynamic_shape
.
min_input_shape
=
{
"split_input"
:
[
1
,
3
,
24
]}
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
9
,
3
,
24
]}
"split_input"
:
[
1
,
3
-
1
,
24
-
1
]
}
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
9
,
3
+
1
,
24
+
1
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
1
,
3
,
24
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
1
,
3
,
24
]}
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
"split_input"
:
[
1
,
24
]}
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
9
,
24
]}
"split_input"
:
[
1
,
24
-
1
]
}
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
9
,
24
+
1
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
1
,
24
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
1
,
24
]}
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
"split_input"
:
[
24
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"split_input"
:
[
24
-
1
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
24
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"split_input"
:
[
24
+
1
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
24
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"split_input"
:
[
24
]}
def
clear_dynamic_shape
():
def
clear_dynamic_shape
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录