Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
a38641be
Mace
项目概览
冰之2023
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a38641be
编写于
12月 03, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add half-type pooling UT.
上级
c899d438
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
26 deletion
+54
-26
mace/kernels/opencl/cl/pooling.cl
mace/kernels/opencl/cl/pooling.cl
+1
-1
mace/ops/pooling.cc
mace/ops/pooling.cc
+8
-0
mace/ops/pooling_test.cc
mace/ops/pooling_test.cc
+45
-25
未找到文件。
mace/kernels/opencl/cl/pooling.cl
浏览文件 @
a38641be
#
include
<common.h>
#
ifdef
FP16
#
define
MIN_VALUE
-
HALF
_MAX
#
define
MIN_VALUE
-
USHRT
_MAX
#
else
#
define
MIN_VALUE
-FLT_MAX
#
endif
...
...
mace/ops/pooling.cc
浏览文件 @
a38641be
...
...
@@ -10,6 +10,10 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Pooling")
.
TypeConstraint
<
float
>
(
"T"
)
.
Build
(),
PoolingOp
<
DeviceType
::
CPU
,
float
>
);
REGISTER_CPU_OPERATOR
(
OpKeyBuilder
(
"Pooling"
)
.
TypeConstraint
<
half
>
(
"T"
)
.
Build
(),
PoolingOp
<
DeviceType
::
CPU
,
half
>
);
#if __ARM_NEON
REGISTER_NEON_OPERATOR
(
OpKeyBuilder
(
"Pooling"
)
...
...
@@ -22,5 +26,9 @@ REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Pooling")
.
TypeConstraint
<
float
>
(
"T"
)
.
Build
(),
PoolingOp
<
DeviceType
::
OPENCL
,
float
>
);
REGISTER_OPENCL_OPERATOR
(
OpKeyBuilder
(
"Pooling"
)
.
TypeConstraint
<
half
>
(
"T"
)
.
Build
(),
PoolingOp
<
DeviceType
::
OPENCL
,
half
>
);
}
// namespace mace
mace/ops/pooling_test.cc
浏览文件 @
a38641be
...
...
@@ -174,7 +174,7 @@ TEST_F(PoolingOpTest, OPENCLSimpleMaxPooling3S2) {
SimpleMaxPooling3S2
<
OPENCL
>
();
}
template
<
DeviceType
D
>
template
<
DeviceType
D
,
typename
T
>
static
void
MaxPooling3S2
(
const
std
::
vector
<
index_t
>
&
input_shape
,
const
std
::
vector
<
int
>
strides
,
Padding
padding
)
{
...
...
@@ -188,17 +188,18 @@ static void MaxPooling3S2(const std::vector<index_t> &input_shape,
.
AddIntsArg
(
"strides"
,
strides
)
.
AddIntArg
(
"padding"
,
padding
)
.
AddIntsArg
(
"dilations"
,
{
1
,
1
})
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
input_shape
);
net
.
AddRandomInput
<
D
,
T
>
(
"Input"
,
input_shape
);
// run on cpu
net
.
RunOp
();
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT
);
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
.
Output
(
"OutputImage"
)
...
...
@@ -207,11 +208,12 @@ static void MaxPooling3S2(const std::vector<index_t> &input_shape,
.
AddIntsArg
(
"strides"
,
strides
)
.
AddIntArg
(
"padding"
,
padding
)
.
AddIntsArg
(
"dilations"
,
{
1
,
1
})
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
ExpectTensorNear
<
T
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
}
// TODO(chenghui) : there is a bug.
...
...
@@ -221,17 +223,24 @@ static void MaxPooling3S2(const std::vector<index_t> &input_shape,
//}
TEST_F
(
PoolingOpTest
,
OPENCLAlignedMaxPooling3S2
)
{
MaxPooling3S2
<
OPENCL
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
,
float
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
float
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
float
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
,
float
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLHalfAlignedMaxPooling3S2
)
{
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
64
,
32
,
32
},
{
1
,
1
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
64
,
32
,
32
},
{
2
,
2
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLUnalignedMaxPooling3S2
)
{
MaxPooling3S2
<
OPENCL
>
({
3
,
41
,
43
,
47
},
{
1
,
1
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
>
({
3
,
41
,
43
,
47
},
{
2
,
2
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
>
({
3
,
41
,
43
,
47
},
{
1
,
1
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
>
({
3
,
41
,
43
,
47
},
{
2
,
2
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
41
,
43
,
47
},
{
1
,
1
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
41
,
43
,
47
},
{
2
,
2
},
Padding
::
VALID
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
41
,
43
,
47
},
{
1
,
1
},
Padding
::
SAME
);
MaxPooling3S2
<
OPENCL
,
half
>
({
3
,
41
,
43
,
47
},
{
2
,
2
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
AVG_VALID
)
{
...
...
@@ -297,7 +306,7 @@ TEST_F(PoolingOpTest, OPENCLSimpleAvgPooling) {
SimpleAvgPoolingTest
<
OPENCL
>
();
}
template
<
DeviceType
D
>
template
<
DeviceType
D
,
typename
T
>
static
void
AvgPoolingTest
(
const
std
::
vector
<
index_t
>
&
shape
,
const
std
::
vector
<
int
>
&
kernels
,
const
std
::
vector
<
int
>
&
strides
,
...
...
@@ -322,7 +331,7 @@ static void AvgPoolingTest(const std::vector<index_t> &shape,
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT
);
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
.
Output
(
"OutputImage"
)
...
...
@@ -331,30 +340,41 @@ static void AvgPoolingTest(const std::vector<index_t> &shape,
.
AddIntsArg
(
"strides"
,
strides
)
.
AddIntArg
(
"padding"
,
padding
)
.
AddIntsArg
(
"dilations"
,
{
1
,
1
})
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.0
01
);
ExpectTensorNear
<
float
,
T
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.
01
);
}
TEST_F
(
PoolingOpTest
,
OPENCLAlignedAvgPooling
)
{
AvgPoolingTest
<
OPENCL
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
SAME
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLHalfAlignedAvgPooling
)
{
AvgPoolingTest
<
OPENCL
,
half
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
half
>
({
3
,
15
,
15
,
128
},
{
4
,
4
},
{
4
,
4
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLAlignedLargeKernelAvgPooling
)
{
AvgPoolingTest
<
OPENCL
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
SAME
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLHalfAlignedLargeKernelAvgPooling
)
{
AvgPoolingTest
<
OPENCL
,
half
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
half
>
({
3
,
64
,
64
,
128
},
{
16
,
16
},
{
16
,
16
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLUnAlignedAvgPooling
)
{
AvgPoolingTest
<
OPENCL
>
({
3
,
31
,
37
,
128
},
{
2
,
2
},
{
2
,
2
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
>
({
3
,
31
,
37
,
128
},
{
2
,
2
},
{
2
,
2
},
Padding
::
SAME
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
31
,
37
,
128
},
{
2
,
2
},
{
2
,
2
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
31
,
37
,
128
},
{
2
,
2
},
{
2
,
2
},
Padding
::
SAME
);
}
TEST_F
(
PoolingOpTest
,
OPENCLUnAlignedLargeKernelAvgPooling
)
{
AvgPoolingTest
<
OPENCL
>
({
3
,
31
,
37
,
128
},
{
8
,
8
},
{
8
,
8
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
>
({
3
,
31
,
37
,
128
},
{
8
,
8
},
{
8
,
8
},
Padding
::
SAME
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
31
,
37
,
128
},
{
8
,
8
},
{
8
,
8
},
Padding
::
VALID
);
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
31
,
37
,
128
},
{
8
,
8
},
{
8
,
8
},
Padding
::
SAME
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录