Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
50ac7dbf
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看板
未验证
提交
50ac7dbf
编写于
3月 12, 2021
作者:
S
Shang Zhizhou
提交者:
GitHub
3月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Trt elementwise plugin serialize (#31587)
* add serialize unittest * fix element_op trt plugin serialize bug
上级
ef0dd3ef
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
3 deletion
+105
-3
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
.../fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
+7
-2
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.h
...e/fluid/inference/tensorrt/plugin/elementwise_op_plugin.h
+46
-1
python/paddle/fluid/tests/unittests/ir/inference/test_trt_subgraph_pass.py
...id/tests/unittests/ir/inference/test_trt_subgraph_pass.py
+52
-0
未找到文件。
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
浏览文件 @
50ac7dbf
...
...
@@ -152,9 +152,14 @@ int ElementWisePlugin::enqueue(int batch_size, const void *const *inputs,
int
ElementwisePluginDynamic
::
initialize
()
{
return
0
;
}
size_t
ElementwisePluginDynamic
::
getSerializationSize
()
const
{
return
0
;
}
size_t
ElementwisePluginDynamic
::
getSerializationSize
()
const
{
return
SerializedSize
(
type_
.
c_str
())
+
SerializedSize
(
axis_
);
}
void
ElementwisePluginDynamic
::
serialize
(
void
*
buffer
)
const
{}
void
ElementwisePluginDynamic
::
serialize
(
void
*
buffer
)
const
{
SerializeValue
(
&
buffer
,
type_
.
c_str
());
SerializeValue
(
&
buffer
,
axis_
);
}
nvinfer1
::
DimsExprs
ElementwisePluginDynamic
::
getOutputDimensions
(
int
output_index
,
const
nvinfer1
::
DimsExprs
*
inputs
,
int
nb_inputs
,
...
...
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.h
浏览文件 @
50ac7dbf
...
...
@@ -92,7 +92,12 @@ class ElementwisePluginDynamic : public DynamicPluginTensorRT {
public:
explicit
ElementwisePluginDynamic
(
const
std
::
string
&
type
,
int
axis
)
:
type_
(
type
),
axis_
(
axis
)
{}
ElementwisePluginDynamic
(
void
const
*
serialData
,
size_t
serialLength
)
{}
ElementwisePluginDynamic
(
void
const
*
serialData
,
size_t
serialLength
)
{
const
char
*
elementwise_type
;
DeserializeValue
(
&
serialData
,
&
serialLength
,
&
elementwise_type
);
type_
=
std
::
string
(
elementwise_type
);
DeserializeValue
(
&
serialData
,
&
serialLength
,
&
axis_
);
}
nvinfer1
::
IPluginV2DynamicExt
*
clone
()
const
override
{
return
new
ElementwisePluginDynamic
(
type_
,
axis_
);
}
...
...
@@ -138,6 +143,46 @@ class ElementwisePluginDynamic : public DynamicPluginTensorRT {
std
::
string
type_
;
int
axis_
;
};
class
ElementwisePluginV2Creator
:
public
nvinfer1
::
IPluginCreator
{
public:
ElementwisePluginV2Creator
()
{}
const
char
*
getPluginName
()
const
override
{
return
"elementwise_plugin"
;
}
const
char
*
getPluginVersion
()
const
override
{
return
"1"
;
}
const
nvinfer1
::
PluginFieldCollection
*
getFieldNames
()
override
{
return
&
field_collection_
;
}
nvinfer1
::
IPluginV2
*
createPlugin
(
const
char
*
name
,
const
nvinfer1
::
PluginFieldCollection
*
fc
)
override
{
return
nullptr
;
}
nvinfer1
::
IPluginV2
*
deserializePlugin
(
const
char
*
name
,
const
void
*
serial_data
,
size_t
serial_length
)
override
{
auto
plugin
=
new
ElementwisePluginDynamic
(
serial_data
,
serial_length
);
return
plugin
;
}
void
setPluginNamespace
(
const
char
*
lib_namespace
)
override
{
plugin_namespace_
=
lib_namespace
;
}
const
char
*
getPluginNamespace
()
const
override
{
return
plugin_namespace_
.
c_str
();
}
private:
std
::
string
plugin_namespace_
;
std
::
string
plugin_name_
;
nvinfer1
::
PluginFieldCollection
field_collection_
{
0
,
nullptr
};
std
::
vector
<
nvinfer1
::
PluginField
>
plugin_attributes_
;
};
REGISTER_TRT_PLUGIN_V2
(
ElementwisePluginV2Creator
);
#endif
}
// namespace plugin
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_subgraph_pass.py
浏览文件 @
50ac7dbf
...
...
@@ -414,6 +414,58 @@ class TensorRTSubgraphPassElementwiseMulTest(
return
fluid
.
layers
.
elementwise_mul
(
x
=
data1
,
y
=
data2
)
class
TensorRTSubgraphPassElementwiseSerializeTest
(
TensorRTSubgraphPassElementwiseTest
):
def
setUp
(
self
):
super
(
TensorRTSubgraphPassElementwiseSerializeTest
,
self
).
setUp
()
self
.
trt_parameters
=
TensorRTSubgraphPassElementwiseTest
.
TensorRTParam
(
1
<<
30
,
32
,
0
,
AnalysisConfig
.
Precision
.
Float32
,
True
,
False
)
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
super
(
TensorRTSubgraphPassElementwiseSerializeTest
,
self
).
test_check_output
()
class
TensorRTSubgraphPassElementwiseBroadcastDynamicTest
(
InferencePassTest
):
def
setUp
(
self
):
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data1
=
fluid
.
data
(
name
=
"data1"
,
shape
=
[
-
1
,
3
,
64
,
64
],
dtype
=
"float32"
)
data2
=
fluid
.
data
(
name
=
"data2"
,
shape
=
[
64
,
64
],
dtype
=
"float32"
)
eltwise_out
=
self
.
append_eltwise
(
data1
,
data2
)
out
=
fluid
.
layers
.
batch_norm
(
eltwise_out
,
is_test
=
True
)
self
.
feeds
=
{
"data1"
:
np
.
random
.
random
([
1
,
3
,
64
,
64
]).
astype
(
"float32"
),
"data2"
:
np
.
random
.
random
([
64
,
64
]).
astype
(
"float32"
),
}
self
.
enable_trt
=
True
self
.
trt_parameters
=
TensorRTSubgraphPassElementwiseBroadcastDynamicTest
.
TensorRTParam
(
1
<<
30
,
32
,
0
,
AnalysisConfig
.
Precision
.
Float32
,
True
,
False
)
self
.
dynamic_shape_params
=
TensorRTSubgraphPassElementwiseBroadcastDynamicTest
.
DynamicShapeParam
(
{
'data1'
:
[
1
,
3
,
8
,
64
],
'data2'
:
[
8
,
64
]
},
{
'data1'
:
[
1
,
3
,
512
,
64
],
'data2'
:
[
512
,
64
]},
{
'data1'
:
[
1
,
3
,
256
,
64
],
'data2'
:
[
256
,
64
]},
False
)
self
.
fetch_list
=
[
out
]
def
append_eltwise
(
self
,
data1
,
data2
):
return
fluid
.
layers
.
elementwise_add
(
x
=
data1
,
y
=
data2
)
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
))
class
TensorRTSubgraphPassShuffleChannelTest
(
InferencePassTest
):
def
setUp
(
self
):
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录