Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
9d108a21
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
9d108a21
编写于
9月 16, 2017
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test for mkldnn_pool and pass them
上级
2a98cba2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
4 deletion
+77
-4
paddle/gserver/layers/MKLDNNPoolLayer.cpp
paddle/gserver/layers/MKLDNNPoolLayer.cpp
+11
-4
paddle/gserver/tests/test_MKLDNN.cpp
paddle/gserver/tests/test_MKLDNN.cpp
+66
-0
未找到文件。
paddle/gserver/layers/MKLDNNPoolLayer.cpp
浏览文件 @
9d108a21
...
...
@@ -49,13 +49,14 @@ bool MKLDNNPoolLayer::init(const LayerMap& layerMap,
if
(
type
==
"max-projection"
)
{
poolAlgo_
=
algorithm
::
pooling_max
;
}
else
if
(
type
==
"avg-projection"
)
{
// TODO(TJ): support choosing exclude or include when paddle support it
// paddle only support pooling_avg_exclude_padding yet
poolAlgo_
=
algorithm
::
pooling_avg_exclude_padding
;
// TODO(TJ): support choosing exclusive or inclusive when paddle support it
// only can make sure that paddle use exclude when ph==pw==0
// otherwise, paddle may used mixed or only include.
poolAlgo_
=
(
ph_
==
0
&&
pw_
==
0
)
?
algorithm
::
pooling_avg_exclude_padding
:
algorithm
::
pooling_avg_include_padding
;
}
else
{
LOG
(
FATAL
)
<<
"unknow pooling type!"
;
}
return
true
;
}
...
...
@@ -177,6 +178,12 @@ void MKLDNNPoolLayer::resetFwdPD(std::shared_ptr<pool_fwd::primitive_desc>& pd,
padR
,
padKind
);
pd
.
reset
(
new
pool_fwd
::
primitive_desc
(
fwdDesc
,
engine_
));
if
((
ph_
!=
0
||
pw_
!=
0
)
&&
(
padR
[
0
]
>
padL
[
0
]
||
padR
[
1
]
>
padL
[
1
]))
{
LOG
(
WARNING
)
<<
"With this layer "
<<
getName
()
<<
", mkldnn_pool use "
<<
"inclusive pooling, while paddle mix inclusice and exclusive."
<<
"So they may have different results for this layer."
;
}
// prepare workspace if necessary
workspace_
=
...
...
paddle/gserver/tests/test_MKLDNN.cpp
浏览文件 @
9d108a21
...
...
@@ -141,6 +141,72 @@ TEST(MKLDNNLayer, ConvLayer) {
testConvLayer
({
4
,
4
,
16
,
3
,
3
,
16
,
3
,
3
,
3
,
3
,
1
,
1
,
1
,
1
,
1
,
1
});
}
struct
testPoolDesc
{
int
bs
,
ch
;
// input channel and output channel are the same
int
ih
,
iw
;
int
oh
,
ow
;
int
fh
,
fw
;
int
ph
,
pw
;
int
sh
,
sw
;
};
void
testPoolLayer
(
const
testPoolDesc
&
pm
)
{
const
std
::
string
compareTypes
[]
=
{
"mkldnn_pool"
,
"pool"
};
TestConfig
cfg
;
cfg
.
layerConfig
.
set_type
(
compareTypes
[
0
]);
cfg
.
layerConfig
.
set_size
(
pm
.
ch
*
pm
.
oh
*
pm
.
ow
);
cfg
.
inputDefs
.
push_back
(
{
INPUT_DATA
,
"layer_0"
,
/* size of input layer= */
size_t
(
pm
.
ch
*
pm
.
ih
*
pm
.
iw
),
0
});
LayerInputConfig
*
input
=
cfg
.
layerConfig
.
add_inputs
();
PoolConfig
*
pool
=
input
->
mutable_pool_conf
();
// pool->set_pool_type(poolType);
pool
->
set_channels
(
pm
.
ch
);
pool
->
set_img_size
(
pm
.
iw
);
pool
->
set_img_size_y
(
pm
.
ih
);
pool
->
set_output_x
(
pm
.
ow
);
pool
->
set_output_y
(
pm
.
oh
);
pool
->
set_size_x
(
pm
.
fw
);
pool
->
set_size_y
(
pm
.
fh
);
pool
->
set_padding
(
pm
.
pw
);
pool
->
set_padding_y
(
pm
.
ph
);
pool
->
set_stride
(
pm
.
sw
);
pool
->
set_stride_y
(
pm
.
sh
);
int
oh
=
outputSize
(
pm
.
ih
,
pm
.
fh
,
pm
.
ph
,
pm
.
sh
,
false
);
int
ow
=
outputSize
(
pm
.
iw
,
pm
.
fw
,
pm
.
pw
,
pm
.
sw
,
false
);
CHECK_EQ
(
ow
,
pm
.
ow
)
<<
"output size check failed"
;
CHECK_EQ
(
oh
,
pm
.
oh
)
<<
"output size check failed"
;
MKLDNNTester
tester
;
for
(
auto
type
:
{
"max-projection"
,
"avg-projection"
})
{
pool
->
set_pool_type
(
type
);
TestConfig
ref
=
cfg
;
ref
.
layerConfig
.
set_type
(
compareTypes
[
1
]);
for
(
auto
bs
:
{
pm
.
bs
,
1
})
{
tester
.
run
(
cfg
,
ref
,
bs
,
pm
.
ih
,
pm
.
iw
);
}
}
}
TEST
(
MkldnnLayer
,
PoolLayer
)
{
// For max pooling, MKLDNN has the same result with Paddle.
// For avg pooling, MKLDNN use either inclusive or exclusive pooling, while
// Paddle mixes these two types. So, when encountering some
// test cases with padding>0, they may get different results.
// Then MKLDNN layer will give warnning for these cases.
/* bs, ch, ih, iw, oh, ow, fh, fw, ph, pw, sh, sw*/
testPoolLayer
({
2
,
1
,
4
,
4
,
2
,
2
,
3
,
3
,
0
,
0
,
2
,
2
});
testPoolLayer
({
10
,
8
,
16
,
16
,
8
,
8
,
2
,
2
,
0
,
0
,
2
,
2
});
testPoolLayer
({
4
,
2
,
5
,
5
,
3
,
3
,
3
,
3
,
1
,
1
,
2
,
2
});
testPoolLayer
({
8
,
16
,
56
,
56
,
28
,
28
,
3
,
3
,
0
,
0
,
2
,
2
});
testPoolLayer
({
8
,
16
,
14
,
14
,
7
,
7
,
3
,
3
,
0
,
0
,
2
,
2
});
testPoolLayer
({
4
,
16
,
7
,
7
,
1
,
1
,
7
,
7
,
0
,
0
,
1
,
1
});
testPoolLayer
({
4
,
2
,
5
,
5
,
3
,
3
,
5
,
5
,
1
,
1
,
1
,
1
});
}
// TODO(TJ): add branch test
int
main
(
int
argc
,
char
**
argv
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录