Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
5ba3dd5b
Mace
项目概览
慢慢CG
/
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看板
提交
5ba3dd5b
编写于
3月 19, 2018
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor mace/ops code style
上级
360937e9
变更
51
显示空白变更内容
内联
并排
Showing
51 changed file
with
451 addition
and
380 deletion
+451
-380
mace/ops/activation_benchmark.cc
mace/ops/activation_benchmark.cc
+6
-6
mace/ops/activation_test.cc
mace/ops/activation_test.cc
+15
-15
mace/ops/addn_benchmark.cc
mace/ops/addn_benchmark.cc
+1
-1
mace/ops/addn_test.cc
mace/ops/addn_test.cc
+2
-2
mace/ops/batch_norm_benchmark.cc
mace/ops/batch_norm_benchmark.cc
+5
-5
mace/ops/batch_norm_test.cc
mace/ops/batch_norm_test.cc
+30
-30
mace/ops/batch_to_space_benchmark.cc
mace/ops/batch_to_space_benchmark.cc
+1
-1
mace/ops/bias_add_benchmark.cc
mace/ops/bias_add_benchmark.cc
+2
-2
mace/ops/bias_add_test.cc
mace/ops/bias_add_test.cc
+9
-9
mace/ops/channel_shuffle_benchmark.cc
mace/ops/channel_shuffle_benchmark.cc
+1
-1
mace/ops/channel_shuffle_test.cc
mace/ops/channel_shuffle_test.cc
+3
-3
mace/ops/concat_benchmark.cc
mace/ops/concat_benchmark.cc
+2
-2
mace/ops/concat_test.cc
mace/ops/concat_test.cc
+9
-9
mace/ops/conv_2d_benchmark.cc
mace/ops/conv_2d_benchmark.cc
+3
-3
mace/ops/conv_2d_test.cc
mace/ops/conv_2d_test.cc
+38
-38
mace/ops/depthwise_conv2d_benchmark.cc
mace/ops/depthwise_conv2d_benchmark.cc
+3
-3
mace/ops/depthwise_conv2d_test.cc
mace/ops/depthwise_conv2d_test.cc
+12
-12
mace/ops/eltwise_benchmark.cc
mace/ops/eltwise_benchmark.cc
+2
-2
mace/ops/eltwise_test.cc
mace/ops/eltwise_test.cc
+6
-6
mace/ops/folded_batch_norm_test.cc
mace/ops/folded_batch_norm_test.cc
+20
-20
mace/ops/fully_connected.h
mace/ops/fully_connected.h
+2
-0
mace/ops/fully_connected_benchmark.cc
mace/ops/fully_connected_benchmark.cc
+4
-3
mace/ops/fully_connected_test.cc
mace/ops/fully_connected_test.cc
+13
-13
mace/ops/fused_conv_2d.h
mace/ops/fused_conv_2d.h
+1
-0
mace/ops/fused_conv_2d_test.cc
mace/ops/fused_conv_2d_test.cc
+51
-47
mace/ops/global_avg_pooling.h
mace/ops/global_avg_pooling.h
+2
-0
mace/ops/global_avg_pooling_benchmark.cc
mace/ops/global_avg_pooling_benchmark.cc
+5
-2
mace/ops/global_avg_pooling_test.cc
mace/ops/global_avg_pooling_test.cc
+3
-1
mace/ops/matmul_benchmark.cc
mace/ops/matmul_benchmark.cc
+3
-2
mace/ops/matmul_test.cc
mace/ops/matmul_test.cc
+7
-7
mace/ops/ops_test_util.h
mace/ops/ops_test_util.h
+30
-19
mace/ops/pooling.h
mace/ops/pooling.h
+3
-1
mace/ops/pooling_benchmark.cc
mace/ops/pooling_benchmark.cc
+19
-14
mace/ops/pooling_test.cc
mace/ops/pooling_test.cc
+11
-9
mace/ops/reshape.h
mace/ops/reshape.h
+2
-0
mace/ops/reshape_test.cc
mace/ops/reshape_test.cc
+3
-1
mace/ops/resize_bilinear.h
mace/ops/resize_bilinear.h
+3
-3
mace/ops/resize_bilinear_benchmark.cc
mace/ops/resize_bilinear_benchmark.cc
+15
-13
mace/ops/resize_bilinear_test.cc
mace/ops/resize_bilinear_test.cc
+16
-12
mace/ops/slice.h
mace/ops/slice.h
+6
-2
mace/ops/slice_benchmark.cc
mace/ops/slice_benchmark.cc
+15
-11
mace/ops/slice_test.cc
mace/ops/slice_test.cc
+26
-14
mace/ops/softmax.h
mace/ops/softmax.h
+3
-3
mace/ops/softmax_benchmark.cc
mace/ops/softmax_benchmark.cc
+1
-1
mace/ops/softmax_test.cc
mace/ops/softmax_test.cc
+4
-4
mace/ops/space_to_batch.h
mace/ops/space_to_batch.h
+1
-0
mace/ops/space_to_batch_benchmark.cc
mace/ops/space_to_batch_benchmark.cc
+1
-1
mace/ops/space_to_batch_test.cc
mace/ops/space_to_batch_test.cc
+7
-5
mace/ops/winograd_convolution_test.cc
mace/ops/winograd_convolution_test.cc
+21
-20
mace/ops/winograd_inverse_transform.h
mace/ops/winograd_inverse_transform.h
+1
-0
mace/ops/winograd_transform_benchmark.cc
mace/ops/winograd_transform_benchmark.cc
+2
-2
未找到文件。
mace/ops/activation_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,7 +19,7 @@ static void ReluBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluBM"
)
...
...
@@ -79,7 +79,7 @@ static void ReluxBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluxBM"
)
...
...
@@ -142,9 +142,9 @@ static void PreluBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Alpha"
,
{
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Alpha"
,
"AlphaImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Alpha"
,
"AlphaImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Activation"
,
"PreluBM"
)
...
...
@@ -206,7 +206,7 @@ static void TanhBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"TanhBM"
)
...
...
@@ -266,7 +266,7 @@ static void SigmoidBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"SigmoidBM"
)
...
...
mace/ops/activation_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,7 +19,7 @@ void TestSimpleRelu() {
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
,
-
4
,
4
,
-
3
,
3
,
-
2
,
2
,
-
1
,
1
,
0
,
0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluTest"
)
...
...
@@ -32,7 +32,7 @@ void TestSimpleRelu() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"ReluTest"
)
...
...
@@ -65,7 +65,7 @@ void TestUnalignedSimpleRelu() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
{
1
,
3
,
2
,
1
},
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluTest"
)
...
...
@@ -78,7 +78,7 @@ void TestUnalignedSimpleRelu() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"ReluTest"
)
...
...
@@ -114,7 +114,7 @@ void TestSimpleRelux() {
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
,
-
4
,
4
,
-
3
,
3
,
-
2
,
2
,
-
1
,
1
,
0
,
0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluxTest"
)
...
...
@@ -128,7 +128,7 @@ void TestSimpleRelux() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"ReluxTest"
)
...
...
@@ -164,7 +164,7 @@ void TestSimpleReluRelux() {
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
,
-
4
,
4
,
-
3
,
3
,
-
2
,
2
,
-
1
,
1
,
0
,
0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"ReluxTest"
)
...
...
@@ -178,7 +178,7 @@ void TestSimpleReluRelux() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"ReluxTest"
)
...
...
@@ -217,9 +217,9 @@ void TestSimplePrelu() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Alpha"
,
{
2
},
{
2.0
,
3.0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Alpha"
,
"AlphaImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Alpha"
,
"AlphaImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Activation"
,
"PreluTest"
)
...
...
@@ -233,7 +233,7 @@ void TestSimplePrelu() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"PreluTest"
)
...
...
@@ -270,7 +270,7 @@ void TestSimpleTanh() {
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
,
-
4
,
4
,
-
3
,
3
,
-
2
,
2
,
-
1
,
1
,
0
,
0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"TanhTest"
)
...
...
@@ -283,7 +283,7 @@ void TestSimpleTanh() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"TanhTest"
)
...
...
@@ -321,7 +321,7 @@ void TestSimpleSigmoid() {
{
-
7
,
7
,
-
6
,
6
,
-
5
,
5
,
-
4
,
4
,
-
3
,
3
,
-
2
,
2
,
-
1
,
1
,
0
,
0
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Activation"
,
"SigmoidTest"
)
...
...
@@ -334,7 +334,7 @@ void TestSimpleSigmoid() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Activation"
,
"SigmoidTest"
)
...
...
mace/ops/addn_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -20,7 +20,7 @@ static void AddNBenchmark(int iters, int inputs, int n, int h, int w, int c) {
if
(
D
==
DeviceType
::
OPENCL
)
{
for
(
int
i
=
0
;
i
<
inputs
;
++
i
)
{
BufferToImage
<
D
,
T
>
(
net
,
MakeString
(
"Input"
,
i
).
c_str
(),
BufferToImage
<
D
,
T
>
(
&
net
,
MakeString
(
"Input"
,
i
).
c_str
(),
MakeString
(
"InputImage"
,
i
).
c_str
(),
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
...
...
mace/ops/addn_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -92,7 +92,7 @@ void RandomTest() {
// run on gpu
for
(
int
i
=
0
;
i
<
input_num
;
++
i
)
{
BufferToImage
<
D
,
half
>
(
net
,
MakeString
(
"Input"
,
i
),
BufferToImage
<
D
,
half
>
(
&
net
,
MakeString
(
"Input"
,
i
),
MakeString
(
"InputImage"
,
i
),
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
...
...
@@ -108,7 +108,7 @@ void RandomTest() {
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.1
);
...
...
mace/ops/batch_norm_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -23,15 +23,15 @@ static void BatchNorm(
net
.
AddRandomInput
<
D
,
T
>
(
"Var"
,
{
channels
},
true
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormBM"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/batch_norm_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -22,15 +22,15 @@ void Simple() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Var"
,
{
1
},
{
11.67
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -46,7 +46,7 @@ void Simple() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -111,15 +111,15 @@ TEST_F(BatchNormOpTest, SimpleRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -141,7 +141,7 @@ TEST_F(BatchNormOpTest, SimpleRandomOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
@@ -183,15 +183,15 @@ TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -214,7 +214,7 @@ TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.5
);
}
...
...
@@ -256,15 +256,15 @@ TEST_F(BatchNormOpTest, ComplexRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -286,7 +286,7 @@ TEST_F(BatchNormOpTest, ComplexRandomOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
@@ -328,15 +328,15 @@ TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Mean"
,
"MeanImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Mean"
,
"MeanImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Var"
,
"VarImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Var"
,
"VarImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -359,7 +359,7 @@ TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.5
);
}
...
...
mace/ops/batch_to_space_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -14,7 +14,7 @@ static void BMBatchToSpace(
OpsTestNet
net
;
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"BatchToSpaceND"
,
"BatchToSpaceNDTest"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/bias_add_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,9 +19,9 @@ static void BiasAdd(int iters, int batch, int channels, int height, int width) {
net
.
AddRandomInput
<
D
,
T
>
(
"Bias"
,
{
channels
},
true
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BiasAdd"
,
"BiasAddBM"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/bias_add_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,9 +19,9 @@ void BiasAddSimple() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
{
1
},
{
0.5
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BiasAdd"
,
"BiasAddTest"
)
...
...
@@ -33,7 +33,7 @@ void BiasAddSimple() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"BiasAdd"
,
"BiasAddTest"
)
...
...
@@ -89,9 +89,9 @@ TEST_F(BiasAddOpTest, SimpleRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BiasAdd"
,
"BiasAddTest"
)
...
...
@@ -104,7 +104,7 @@ TEST_F(BiasAddOpTest, SimpleRandomOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
@@ -139,9 +139,9 @@ TEST_F(BiasAddOpTest, ComplexRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"BiasAdd"
,
"BiasAddTest"
)
...
...
@@ -154,7 +154,7 @@ TEST_F(BiasAddOpTest, ComplexRandomOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
mace/ops/channel_shuffle_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,7 +19,7 @@ static void ChannelShuffle(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"ChannelShuffle"
,
"ChannelShuffleTest"
)
...
...
mace/ops/channel_shuffle_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -41,7 +41,7 @@ TEST_F(ChannelShuffleOpTest, C16G4_OPENCL) {
"Input"
,
{
1
,
1
,
2
,
16
},
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
27
,
28
,
29
,
30
,
31
});
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
...
...
@@ -55,7 +55,7 @@ TEST_F(ChannelShuffleOpTest, C16G4_OPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
// Transfer output
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
// Check
...
...
mace/ops/concat_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -61,9 +61,9 @@ static void OpenclConcatHelper(int iters,
net
.
AddRandomInput
<
DeviceType
::
OPENCL
,
float
>
(
"Input0"
,
shape0
);
net
.
AddRandomInput
<
DeviceType
::
OPENCL
,
float
>
(
"Input1"
,
shape1
);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Input0"
,
"InputImage0"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Input0"
,
"InputImage0"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Input1"
,
"InputImage1"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Input1"
,
"InputImage1"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Concat"
,
"ConcatBM"
)
.
Input
(
"InputImage0"
)
...
...
mace/ops/concat_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -22,9 +22,9 @@ TEST_F(ConcatOpTest, CPUSimpleHorizon) {
std
::
vector
<
index_t
>
input_shape
=
{
4
,
4
};
std
::
vector
<
float
>
input0
;
GenerateRandomRealTypeData
(
input_shape
,
input0
);
GenerateRandomRealTypeData
(
input_shape
,
&
input0
);
std
::
vector
<
float
>
input1
;
GenerateRandomRealTypeData
(
input_shape
,
input1
);
GenerateRandomRealTypeData
(
input_shape
,
&
input1
);
// Add inputs
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input0"
,
input_shape
,
input0
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input1"
,
input_shape
,
input1
);
...
...
@@ -59,9 +59,9 @@ TEST_F(ConcatOpTest, CPUSimpleVertical) {
std
::
vector
<
index_t
>
input_shape
=
{
4
,
4
};
std
::
vector
<
float
>
input0
;
GenerateRandomRealTypeData
(
input_shape
,
input0
);
GenerateRandomRealTypeData
(
input_shape
,
&
input0
);
std
::
vector
<
float
>
input1
;
GenerateRandomRealTypeData
(
input_shape
,
input1
);
GenerateRandomRealTypeData
(
input_shape
,
&
input1
);
// Add inputs
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input0"
,
input_shape
,
input0
);
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
"Input1"
,
input_shape
,
input1
);
...
...
@@ -102,7 +102,7 @@ TEST_F(ConcatOpTest, CPURandom) {
.
Finalize
(
net
.
NewOperatorDef
());
std
::
vector
<
index_t
>
shape_data
;
GenerateRandomIntTypeData
<
index_t
>
({
dim
},
shape_data
,
1
,
dim
);
GenerateRandomIntTypeData
<
index_t
>
({
dim
},
&
shape_data
,
1
,
dim
);
std
::
vector
<
std
::
vector
<
index_t
>>
input_shapes
(
num_inputs
,
shape_data
);
std
::
vector
<
std
::
vector
<
float
>>
inputs
(
num_inputs
,
std
::
vector
<
float
>
());
std
::
vector
<
float
*>
input_ptrs
(
num_inputs
,
nullptr
);
...
...
@@ -110,7 +110,7 @@ TEST_F(ConcatOpTest, CPURandom) {
for
(
int
i
=
0
;
i
<
num_inputs
;
++
i
)
{
input_shapes
[
i
][
axis
]
=
1
+
rand
()
%
dim
;
concat_axis_size
+=
input_shapes
[
i
][
axis
];
GenerateRandomRealTypeData
(
input_shapes
[
i
],
inputs
[
i
]);
GenerateRandomRealTypeData
(
input_shapes
[
i
],
&
inputs
[
i
]);
input_ptrs
[
i
]
=
inputs
[
i
].
data
();
net
.
AddInputFromArray
<
DeviceType
::
CPU
,
float
>
(
MakeString
(
"Input"
,
i
),
input_shapes
[
i
],
inputs
[
i
]);
...
...
@@ -152,7 +152,7 @@ void OpenclRandomTest(const std::vector<std::vector<index_t>> &shapes,
const
std
::
string
image_name
=
MakeString
(
"InputImage"
,
i
);
concat_axis_size
+=
shapes
[
i
][
axis
];
net
.
AddRandomInput
<
DeviceType
::
OPENCL
,
float
>
(
input_name
,
shapes
[
i
]);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
input_name
,
image_name
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
input_name
,
image_name
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
...
...
@@ -169,7 +169,7 @@ void OpenclRandomTest(const std::vector<std::vector<index_t>> &shapes,
// Run
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
// Check
...
...
mace/ops/conv_2d_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -34,11 +34,11 @@ static void Conv2d(int iters,
net
.
AddRandomInput
<
D
,
float
>
(
"Bias"
,
{
output_channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/conv_2d_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -24,11 +24,11 @@ void TestNHWCSimple3x3VALID() {
net
.
AddInputFromArray
<
D
,
T
>
(
"Bias"
,
{
1
},
{
0.1
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -44,7 +44,7 @@ void TestNHWCSimple3x3VALID() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -81,11 +81,11 @@ void TestNHWCSimple3x3SAME() {
net
.
AddInputFromArray
<
D
,
T
>
(
"Bias"
,
{
1
},
{
0.1
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -101,7 +101,7 @@ void TestNHWCSimple3x3SAME() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -150,9 +150,9 @@ void TestNHWCSimple3x3WithoutBias() {
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -167,7 +167,7 @@ void TestNHWCSimple3x3WithoutBias() {
// Run
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -216,11 +216,11 @@ static void TestNHWCCombined3x3() {
net
.
AddInputFromArray
<
D
,
T
>
(
"Bias"
,
{
2
},
{
0.1
f
,
0.2
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2DTest"
)
...
...
@@ -236,7 +236,7 @@ static void TestNHWCCombined3x3() {
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Conv2D"
,
"Conv2DTest"
)
...
...
@@ -289,11 +289,11 @@ void TestConv1x1() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
{
2
},
{
0.1
f
,
0.2
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2DTest"
)
...
...
@@ -308,7 +308,7 @@ void TestConv1x1() {
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Conv2D"
,
"Conv2DTest"
)
...
...
@@ -381,11 +381,11 @@ static void TestComplexConvNxNS12(const std::vector<index_t> &shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -401,7 +401,7 @@ static void TestComplexConvNxNS12(const std::vector<index_t> &shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
@@ -457,13 +457,13 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &input_shape,
std
::
vector
<
float
>
float_input_data
;
GenerateRandomRealTypeData
({
batch
,
height
,
width
,
input_channels
},
float_input_data
);
&
float_input_data
);
std
::
vector
<
float
>
float_filter_data
;
GenerateRandomRealTypeData
(
{
kernel_h
,
kernel_w
,
output_channels
,
input_channels
},
float_filter_data
);
&
float_filter_data
);
std
::
vector
<
float
>
float_bias_data
;
GenerateRandomRealTypeData
({
output_channels
},
float_bias_data
);
GenerateRandomRealTypeData
({
output_channels
},
&
float_bias_data
);
// Add input data
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
input_channels
},
float_input_data
);
...
...
@@ -479,11 +479,11 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &input_shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
half
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
half
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -499,7 +499,7 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &input_shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.5
);
...
...
@@ -603,11 +603,11 @@ static void TestDilationConvNxN(const std::vector<index_t> &shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -623,7 +623,7 @@ static void TestDilationConvNxN(const std::vector<index_t> &shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
@@ -686,11 +686,11 @@ static void TestArbitraryPadConvNxN(const std::vector<index_t> &shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
...
...
@@ -705,7 +705,7 @@ static void TestArbitraryPadConvNxN(const std::vector<index_t> &shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
mace/ops/depthwise_conv2d_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -33,11 +33,11 @@ static void DepthwiseConv2d(int iters,
net
.
AddRandomInput
<
D
,
float
>
(
"Bias"
,
{
input_channels
*
multiplier
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
DW_CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"DepthwiseConv2d"
,
"DepthwiseConv2dTest"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/depthwise_conv2d_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -25,11 +25,11 @@ void SimpleValidTest() {
"Filter"
,
{
2
,
2
,
2
,
1
},
{
1.0
f
,
2.0
f
,
2.0
f
,
4.0
f
,
3.0
f
,
6.0
f
,
4.0
f
,
8.0
f
});
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
{
2
},
{
.1
f
,
.2
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
DW_CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"DepthwiseConv2d"
,
"DepthwiseConv2DTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -45,7 +45,7 @@ void SimpleValidTest() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -129,11 +129,11 @@ void ComplexValidTest() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
{
6
},
{
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
DW_CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"DepthwiseConv2d"
,
"DepthwiseConv2DTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -149,7 +149,7 @@ void ComplexValidTest() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -240,11 +240,11 @@ void TestNxNS12(const index_t height, const index_t width) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
DW_CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"DepthwiseConv2d"
,
"DepthwiseConv2DTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -260,7 +260,7 @@ void TestNxNS12(const index_t height, const index_t width) {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"DeviceOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"DeviceOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"DepthwiseConv2d"
,
"DepthwiseConv2DTest"
)
...
...
mace/ops/eltwise_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -20,9 +20,9 @@ static void EltwiseBenchmark(
net
.
AddRandomInput
<
D
,
T
>
(
"Input1"
,
{
n
,
h
,
w
,
c
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
half
>
(
net
,
"Input0"
,
"InputImg0"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input0"
,
"InputImg0"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
half
>
(
net
,
"Input1"
,
"InputImg1"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input1"
,
"InputImg1"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Eltwise"
,
"EltwiseTest"
)
.
Input
(
"InputImg0"
)
...
...
mace/ops/eltwise_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -36,9 +36,9 @@ void Simple(const kernels::EltwiseType type,
// Run
net
.
RunOp
(
D
);
}
else
{
BufferToImage
<
D
,
half
>
(
net
,
"Input1"
,
"InputImg1"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input1"
,
"InputImg1"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
half
>
(
net
,
"Input2"
,
"InputImg2"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input2"
,
"InputImg2"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Eltwise"
,
"EltwiseTest"
)
.
Input
(
"InputImg1"
)
...
...
@@ -51,7 +51,7 @@ void Simple(const kernels::EltwiseType type,
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImg"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImg"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
...
...
@@ -120,9 +120,9 @@ void RandomTest(const kernels::EltwiseType type,
// Run
net
.
RunOp
();
BufferToImage
<
D
,
T
>
(
net
,
"Input1"
,
"InputImg1"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input1"
,
"InputImg1"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Input2"
,
"InputImg2"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input2"
,
"InputImg2"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Eltwise"
,
"EltwiseTest"
)
.
Input
(
"InputImg1"
)
...
...
@@ -136,7 +136,7 @@ void RandomTest(const kernels::EltwiseType type,
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImg"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImg"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
if
(
DataTypeToEnum
<
T
>::
value
==
DT_FLOAT
)
{
...
...
mace/ops/folded_batch_norm_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -37,11 +37,11 @@ void Simple() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Offset"
,
{
1
},
offset
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -54,7 +54,7 @@ void Simple() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -203,11 +203,11 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -221,7 +221,7 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
@@ -258,11 +258,11 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -277,7 +277,7 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) {
net
.
RunOp
(
DeviceType
::
OPENCL
);
net
.
Sync
();
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.5
);
}
...
...
@@ -314,11 +314,11 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -331,7 +331,7 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) {
// Run on opencl
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-2
);
}
...
...
@@ -368,11 +368,11 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Scale"
,
"ScaleImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Scale"
,
"ScaleImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
net
,
"Offset"
,
"OffsetImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
half
>
(
&
net
,
"Offset"
,
"OffsetImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FoldedBatchNorm"
,
"FoldedBatchNormTest"
)
...
...
@@ -386,7 +386,7 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) {
// Run on opencl
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.5
);
}
...
...
mace/ops/fully_connected.h
浏览文件 @
5ba3dd5b
...
...
@@ -5,6 +5,8 @@
#ifndef MACE_OPS_FULLY_CONNECTED_H_
#define MACE_OPS_FULLY_CONNECTED_H_
#include <string>
#include "mace/core/operator.h"
#include "mace/kernels/fully_connected.h"
...
...
mace/ops/fully_connected_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -8,6 +8,7 @@
#include "mace/ops/ops_test_util.h"
namespace
mace
{
template
<
DeviceType
D
,
typename
T
>
static
void
FCBenchmark
(
int
iters
,
int
batch
,
int
height
,
int
width
,
int
channel
,
int
out_channel
)
{
...
...
@@ -24,11 +25,11 @@ static void FCBenchmark(
if
(
D
==
DeviceType
::
OPENCL
)
{
const
int
width_size
=
height
*
width
*
channel
;
kernels
::
BufferType
weight_type
=
kernels
::
BufferType
::
WEIGHT_WIDTH
;
BufferToImage
<
D
,
T
>
(
net
,
"Weight"
,
"WeightImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Weight"
,
"WeightImage"
,
weight_type
);
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FC"
,
"FullyConnectedTest"
)
...
...
mace/ops/fully_connected_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -27,11 +27,11 @@ void Simple(const std::vector<index_t> &input_shape,
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
bias_shape
,
bias_value
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Weight"
,
"WeightImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Weight"
,
"WeightImage"
,
kernels
::
BufferType
::
WEIGHT_HEIGHT
);
BufferToImage
<
D
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FC"
,
"FullyConnectedTest"
)
...
...
@@ -45,7 +45,7 @@ void Simple(const std::vector<index_t> &input_shape,
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"FC"
,
"FullyConnectedTest"
)
...
...
@@ -136,11 +136,11 @@ void Complex(const index_t batch,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Weight"
,
"WeightImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Weight"
,
"WeightImage"
,
kernels
::
BufferType
::
WEIGHT_HEIGHT
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FC"
,
"FullyConnectedTest"
)
...
...
@@ -155,7 +155,7 @@ void Complex(const index_t batch,
// Run on opencl
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
if
(
DataTypeToEnum
<
T
>::
value
==
DataType
::
DT_HALF
)
{
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1
);
...
...
@@ -218,11 +218,11 @@ void TestWXFormat(const index_t batch,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"Weight"
,
"WeightImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"Weight"
,
"WeightImage"
,
kernels
::
BufferType
::
WEIGHT_WIDTH
);
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FC"
,
"FullyConnectedTest"
)
...
...
@@ -236,7 +236,7 @@ void TestWXFormat(const index_t batch,
// Run on opencl
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
if
(
DataTypeToEnum
<
T
>::
value
==
DataType
::
DT_HALF
)
{
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1
);
...
...
@@ -263,4 +263,4 @@ TEST_F(FullyConnectedOpTest, OPENCLHalfWidthFormatAligned) {
TestWXFormat
<
half
>
(
1
,
16
,
32
,
32
,
32
);
}
}
}
// namespace mace
mace/ops/fused_conv_2d.h
浏览文件 @
5ba3dd5b
...
...
@@ -6,6 +6,7 @@
#define MACE_OPS_FUSED_CONV_2D_H_
#include <memory>
#include <string>
#include "mace/core/operator.h"
#include "mace/kernels/conv_2d.h"
...
...
mace/ops/fused_conv_2d_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -2,10 +2,12 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <vector>
#include "mace/ops/fused_conv_2d.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
class
FusedConv2dOpTest
:
public
OpsTestBase
{};
...
...
@@ -23,11 +25,11 @@ void TestNHWCSimple3x3VALID() {
net
.
AddInputFromArray
<
D
,
T
>
(
"Bias"
,
{
1
},
{
-
0.1
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -43,7 +45,7 @@ void TestNHWCSimple3x3VALID() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -80,11 +82,11 @@ void TestNHWCSimple3x3SAME() {
net
.
AddInputFromArray
<
D
,
T
>
(
"Bias"
,
{
1
},
{
-
0.1
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -100,7 +102,7 @@ void TestNHWCSimple3x3SAME() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
...
...
@@ -148,9 +150,9 @@ void TestNHWCSimple3x3WithoutBias() {
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -165,7 +167,7 @@ void TestNHWCSimple3x3WithoutBias() {
// Run
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -217,11 +219,11 @@ void TestConv1x1() {
net
.
AddInputFromArray
<
D
,
float
>
(
"Bias"
,
{
2
},
{
0.1
f
,
0.2
f
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
float
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
float
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -236,7 +238,7 @@ void TestConv1x1() {
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -274,14 +276,14 @@ static void TestComplexConvNxNS12(const std::vector<index_t> &shape) {
testing
::
internal
::
LogToStderr
();
auto
func
=
[
&
](
int
kernel_h
,
int
kernel_w
,
int
stride_h
,
int
stride_w
,
Padding
type
)
{
srand
(
time
(
NULL
)
);
unsigned
int
seed
=
time
(
NULL
);
// generate random input
index_t
batch
=
3
+
(
rand
(
)
%
10
);
index_t
batch
=
3
+
(
rand
_r
(
&
seed
)
%
10
);
index_t
height
=
shape
[
0
];
index_t
width
=
shape
[
1
];
index_t
input_channels
=
shape
[
2
]
+
(
rand
(
)
%
10
);
index_t
output_channels
=
shape
[
3
]
+
(
rand
(
)
%
10
);
index_t
input_channels
=
shape
[
2
]
+
(
rand
_r
(
&
seed
)
%
10
);
index_t
output_channels
=
shape
[
3
]
+
(
rand
_r
(
&
seed
)
%
10
);
// Construct graph
OpsTestNet
net
;
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -308,11 +310,11 @@ static void TestComplexConvNxNS12(const std::vector<index_t> &shape) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -328,7 +330,7 @@ static void TestComplexConvNxNS12(const std::vector<index_t> &shape) {
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
@@ -350,14 +352,14 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &shape) {
testing
::
internal
::
LogToStderr
();
auto
func
=
[
&
](
int
kernel_h
,
int
kernel_w
,
int
stride_h
,
int
stride_w
,
Padding
type
)
{
srand
(
time
(
NULL
)
);
unsigned
int
seed
=
time
(
NULL
);
// generate random input
index_t
batch
=
3
+
(
rand
(
)
%
10
);
index_t
batch
=
3
+
(
rand
_r
(
&
seed
)
%
10
);
index_t
height
=
shape
[
0
];
index_t
width
=
shape
[
1
];
index_t
input_channels
=
shape
[
2
]
+
(
rand
(
)
%
10
);
index_t
output_channels
=
shape
[
3
]
+
(
rand
(
)
%
10
);
index_t
input_channels
=
shape
[
2
]
+
(
rand
_r
(
&
seed
)
%
10
);
index_t
output_channels
=
shape
[
3
]
+
(
rand
_r
(
&
seed
)
%
10
);
// Construct graph
OpsTestNet
net
;
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -372,13 +374,13 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &shape) {
std
::
vector
<
float
>
float_input_data
;
GenerateRandomRealTypeData
({
batch
,
height
,
width
,
input_channels
},
float_input_data
);
&
float_input_data
);
std
::
vector
<
float
>
float_filter_data
;
GenerateRandomRealTypeData
(
{
kernel_h
,
kernel_w
,
output_channels
,
input_channels
},
float_filter_data
);
&
float_filter_data
);
std
::
vector
<
float
>
float_bias_data
;
GenerateRandomRealTypeData
({
output_channels
},
float_bias_data
);
GenerateRandomRealTypeData
({
output_channels
},
&
float_bias_data
);
// Add input data
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
input_channels
},
float_input_data
);
...
...
@@ -394,11 +396,11 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &shape) {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
half
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
half
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -414,7 +416,7 @@ static void TestHalfComplexConvNxNS12(const std::vector<index_t> &shape) {
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.2
);
...
...
@@ -472,11 +474,11 @@ static void TestGeneralConvNxNS12(const std::vector<index_t> &image_shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -492,7 +494,7 @@ static void TestGeneralConvNxNS12(const std::vector<index_t> &image_shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
@@ -551,11 +553,11 @@ static void TestAtrousConvNxN(const std::vector<index_t> &shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -571,7 +573,7 @@ static void TestAtrousConvNxN(const std::vector<index_t> &shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
};
...
...
@@ -638,11 +640,11 @@ static void TestGeneralHalfAtrousConv(const std::vector<index_t> &image_shape,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// run on gpu
BufferToImage
<
D
,
half
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
half
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
half
>
(
net
,
"Bias"
,
"BiasImage"
,
BufferToImage
<
D
,
half
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"FusedConv2D"
,
"FusedConv2dTest"
)
...
...
@@ -658,7 +660,7 @@ static void TestGeneralHalfAtrousConv(const std::vector<index_t> &image_shape,
// Run on device
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.7
);
};
...
...
@@ -676,3 +678,5 @@ TEST_F(FusedConv2dOpTest, OPENCL15X15AtrousConvD4) {
TestGeneralHalfAtrousConv
<
DeviceType
::
OPENCL
>
({
63
,
71
},
{
15
,
15
,
16
,
16
},
{
2
,
2
});
}
}
// namespace mace
mace/ops/global_avg_pooling.h
浏览文件 @
5ba3dd5b
...
...
@@ -5,6 +5,8 @@
#ifndef MACE_OPS_GLOBAL_AVG_POOLING_H_
#define MACE_OPS_GLOBAL_AVG_POOLING_H_
#include <vector>
#include "mace/core/operator.h"
#include "mace/kernels/global_avg_pooling.h"
...
...
mace/ops/global_avg_pooling_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -7,8 +7,8 @@
#include "mace/core/testing/test_benchmark.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
using
namespace
mace
::
kernels
;
namespace
mace
{
namespace
kernels
{
template
<
DeviceType
D
>
static
void
GlobalAvgPooling
(
...
...
@@ -53,3 +53,6 @@ static void GlobalAvgPooling(
BM_GLOBAL_AVG_POOLING
(
1
,
3
,
7
,
7
);
BM_GLOBAL_AVG_POOLING
(
1
,
3
,
64
,
64
);
BM_GLOBAL_AVG_POOLING
(
1
,
3
,
256
,
256
);
}
// namespace kernels
}
// namespace mace
mace/ops/global_avg_pooling_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -4,7 +4,7 @@
#include "mace/core/operator.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
class
GlobalAvgPoolingOpTest
:
public
OpsTestBase
{};
...
...
@@ -31,3 +31,5 @@ TEST_F(GlobalAvgPoolingOpTest, 3x7x7_CPU) {
ExpectTensorNear
<
float
>
(
*
expected
,
*
net
.
GetOutput
(
"Output"
),
0.001
);
}
}
// namespace mace
mace/ops/matmul_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -20,8 +20,9 @@ static void MatMulBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"B"
,
{
batch
,
channels
,
out_width
,
1
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"A"
,
"AImage"
,
kernels
::
BufferType
::
IN_OUT_WIDTH
);
BufferToImage
<
D
,
T
>
(
net
,
"B"
,
"BImage"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
BufferToImage
<
D
,
T
>
(
&
net
,
"A"
,
"AImage"
,
kernels
::
BufferType
::
IN_OUT_WIDTH
);
BufferToImage
<
D
,
T
>
(
&
net
,
"B"
,
"BImage"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
OpDefBuilder
(
"MatMul"
,
"MatMulBM"
)
.
Input
(
"AImage"
)
...
...
mace/ops/matmul_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -24,9 +24,9 @@ void Simple(const std::vector<index_t> &A_shape,
net
.
AddInputFromArray
<
D
,
float
>
(
"B"
,
B_shape
,
B_value
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"A"
,
"AImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"A"
,
"AImage"
,
kernels
::
BufferType
::
IN_OUT_WIDTH
);
BufferToImage
<
D
,
float
>
(
net
,
"B"
,
"BImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"B"
,
"BImage"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
OpDefBuilder
(
"MatMul"
,
"MatMulTest"
)
...
...
@@ -38,7 +38,7 @@ void Simple(const std::vector<index_t> &A_shape,
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
}
else
{
OpDefBuilder
(
"MatMul"
,
"MatMulTest"
)
...
...
@@ -124,9 +124,9 @@ void Complex(const index_t batch,
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
// Run on opencl
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"A"
,
"AImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"A"
,
"AImage"
,
kernels
::
BufferType
::
IN_OUT_WIDTH
);
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
net
,
"B"
,
"BImage"
,
BufferToImage
<
DeviceType
::
OPENCL
,
T
>
(
&
net
,
"B"
,
"BImage"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
OpDefBuilder
(
"MatMul"
,
"MatMulTest"
)
...
...
@@ -139,7 +139,7 @@ void Complex(const index_t batch,
// Run on opencl
net
.
RunOp
(
DeviceType
::
OPENCL
);
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
DeviceType
::
OPENCL
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
if
(
DataTypeToEnum
<
T
>::
value
==
DataType
::
DT_HALF
)
{
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-1
);
...
...
@@ -170,4 +170,4 @@ TEST_F(MatMulOpTest, OPENCLHalfUnAlignedWithBatch) {
Complex
<
half
>
(
16
,
32
,
64
,
64
);
Complex
<
half
>
(
31
,
31
,
61
,
67
);
}
}
}
// namespace mace
mace/ops/ops_test_util.h
浏览文件 @
5ba3dd5b
...
...
@@ -2,10 +2,16 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_OPS_TEST_UTIL_H_
#define MACE_OPS_TEST_UTIL_H_
#ifndef MACE_OPS_
OPS_
TEST_UTIL_H_
#define MACE_OPS_
OPS_
TEST_UTIL_H_
#include <functional>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "mace/core/net.h"
...
...
@@ -95,7 +101,7 @@ class OpDefBuilder {
class
OpsTestNet
{
public:
OpsTestNet
()
:
op_registry_
(
new
OperatorRegistry
())
{};
OpsTestNet
()
:
op_registry_
(
new
OperatorRegistry
())
{}
template
<
DeviceType
D
,
typename
T
>
void
AddInputFromArray
(
const
std
::
string
&
name
,
...
...
@@ -204,37 +210,41 @@ class OpsTestBase : public ::testing::Test {
template
<
typename
T
>
void
GenerateRandomRealTypeData
(
const
std
::
vector
<
index_t
>
&
shape
,
std
::
vector
<
T
>
&
res
)
{
std
::
vector
<
T
>
*
res
)
{
MACE_CHECK_NOTNULL
(
res
);
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
normal_distribution
<
float
>
nd
(
0
,
1
);
index_t
size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
res
.
resize
(
size
);
res
->
resize
(
size
);
if
(
DataTypeToEnum
<
T
>::
value
==
DT_HALF
)
{
std
::
generate
(
res
.
begin
(),
res
.
end
(),
std
::
generate
(
res
->
begin
(),
res
->
end
(),
[
&
gen
,
&
nd
]
{
return
half_float
::
half_cast
<
half
>
(
nd
(
gen
));
});
}
else
{
std
::
generate
(
res
.
begin
(),
res
.
end
(),
[
&
gen
,
&
nd
]
{
return
nd
(
gen
);
});
std
::
generate
(
res
->
begin
(),
res
->
end
(),
[
&
gen
,
&
nd
]
{
return
nd
(
gen
);
});
}
}
template
<
typename
T
>
void
GenerateRandomIntTypeData
(
const
std
::
vector
<
index_t
>
&
shape
,
std
::
vector
<
T
>
&
res
,
std
::
vector
<
T
>
*
res
,
const
T
a
=
0
,
const
T
b
=
std
::
numeric_limits
<
T
>::
max
())
{
MACE_CHECK_NOTNULL
(
res
);
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<>
nd
(
a
,
b
);
index_t
size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
res
.
resize
(
size
);
res
->
resize
(
size
);
std
::
generate
(
res
.
begin
(),
res
.
end
(),
[
&
gen
,
&
nd
]
{
return
nd
(
gen
);
});
std
::
generate
(
res
->
begin
(),
res
->
end
(),
[
&
gen
,
&
nd
]
{
return
nd
(
gen
);
});
}
template
<
typename
T
>
...
...
@@ -377,25 +387,26 @@ void ExpectTensorNear(const Tensor &x, const Tensor &y, const double abs_err) {
}
template
<
DeviceType
D
,
typename
T
>
void
BufferToImage
(
OpsTestNet
&
net
,
void
BufferToImage
(
OpsTestNet
*
net
,
const
std
::
string
&
input_name
,
const
std
::
string
&
output_name
,
const
kernels
::
BufferType
type
)
{
MACE_CHECK_NOTNULL
(
net
);
OpDefBuilder
(
"BufferToImage"
,
"BufferToImageTest"
)
.
Input
(
input_name
)
.
Output
(
output_name
)
.
AddIntArg
(
"buffer_type"
,
type
)
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
.
Finalize
(
net
->
NewOperatorDef
());
// Run
net
.
RunOp
(
D
);
net
->
RunOp
(
D
);
net
.
Sync
();
net
->
Sync
();
}
template
<
DeviceType
D
,
typename
T
>
void
ImageToBuffer
(
OpsTestNet
&
net
,
void
ImageToBuffer
(
OpsTestNet
*
net
,
const
std
::
string
&
input_name
,
const
std
::
string
&
output_name
,
const
kernels
::
BufferType
type
)
{
...
...
@@ -404,14 +415,14 @@ void ImageToBuffer(OpsTestNet &net,
.
Output
(
output_name
)
.
AddIntArg
(
"buffer_type"
,
type
)
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
.
Finalize
(
net
->
NewOperatorDef
());
// Run
net
.
RunOp
(
D
);
net
->
RunOp
(
D
);
net
.
Sync
();
net
->
Sync
();
}
}
// namespace mace
#endif // MACE_OPS_TEST_UTIL_H_
#endif // MACE_OPS_
OPS_
TEST_UTIL_H_
mace/ops/pooling.h
浏览文件 @
5ba3dd5b
...
...
@@ -5,6 +5,8 @@
#ifndef MACE_OPS_POOLING_H_
#define MACE_OPS_POOLING_H_
#include <vector>
#include "mace/core/operator.h"
#include "mace/kernels/pooling.h"
#include "mace/ops/conv_pool_2d_base.h"
...
...
@@ -25,7 +27,7 @@ class PoolingOp : public ConvPool2dOpBase<D, T> {
this
->
strides_
.
data
(),
this
->
padding_type_
,
this
->
paddings_
,
this
->
dilations_
.
data
())
{};
this
->
dilations_
.
data
())
{}
bool
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/pooling_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -8,8 +8,8 @@
#include "mace/kernels/conv_pool_2d_util.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
using
namespace
mace
::
kernels
;
namespace
mace
{
namespace
kernels
{
template
<
DeviceType
D
>
static
void
Pooling
(
int
iters
,
...
...
@@ -51,7 +51,8 @@ static void Pooling(int iters,
#define BM_POOLING_MACRO(N, C, H, W, KE, STRIDE, PA, PO, DEVICE) \
static void \
BM_POOLING_##N##_##C##_##H##_##W##_K##KE##S##STRIDE##_##PA##_##PO##_##DEVICE( \
BM_POOLING_##N##_##C##_##H##_##W##_K##KE##S##STRIDE##_##PA##_##PO##_\
##DEVICE( \
int iters) { \
const int64_t tot = static_cast<int64_t>(iters) * N * C * H * W; \
mace::testing::MaccProcessed(tot); \
...
...
@@ -60,7 +61,8 @@ static void Pooling(int iters,
PoolingType::PO); \
} \
BENCHMARK( \
BM_POOLING_##N##_##C##_##H##_##W##_K##KE##S##STRIDE##_##PA##_##PO##_##DEVICE)
BM_POOLING_##N##_##C##_##H##_##W##_K##KE##S##STRIDE##_##PA##_##PO##_\
##DEVICE)
#define BM_POOLING(N, C, H, W, K, S, PA, PO) \
BM_POOLING_MACRO(N, C, H, W, K, S, PA, PO, CPU);
...
...
@@ -70,3 +72,6 @@ BM_POOLING(1, 3, 129, 129, 2, 2, SAME, MAX);
BM_POOLING
(
1
,
3
,
257
,
257
,
2
,
2
,
SAME
,
MAX
);
BM_POOLING
(
1
,
3
,
513
,
513
,
2
,
2
,
SAME
,
MAX
);
BM_POOLING
(
1
,
3
,
1025
,
1025
,
2
,
2
,
SAME
,
MAX
);
}
// namespace kernels
}
// namespace mace
mace/ops/pooling_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -9,7 +9,7 @@
#include "mace/ops/conv_pool_2d_base.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
class
PoolingOpTest
:
public
OpsTestBase
{};
...
...
@@ -133,7 +133,7 @@ static void SimpleMaxPooling3S2() {
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -145,7 +145,7 @@ static void SimpleMaxPooling3S2() {
.
AddIntsArg
(
"dilations"
,
{
1
,
1
})
.
Finalize
(
net
.
NewOperatorDef
());
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
// Run
...
...
@@ -198,7 +198,7 @@ static void MaxPooling3S2(const std::vector<index_t> &input_shape,
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -211,7 +211,7 @@ static void MaxPooling3S2(const std::vector<index_t> &input_shape,
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
T
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.001
);
...
...
@@ -283,7 +283,7 @@ static void SimpleAvgPoolingTest() {
"Input"
,
{
1
,
2
,
8
,
1
},
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
});
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -296,7 +296,7 @@ static void SimpleAvgPoolingTest() {
.
Finalize
(
net
.
NewOperatorDef
());
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
// Check
...
...
@@ -334,7 +334,7 @@ static void AvgPoolingTest(const std::vector<index_t> &shape,
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Pooling"
,
"PoolingTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -347,7 +347,7 @@ static void AvgPoolingTest(const std::vector<index_t> &shape,
.
AddIntArg
(
"T"
,
static_cast
<
int
>
(
DataTypeToEnum
<
T
>::
value
))
.
Finalize
(
net
.
NewOperatorDef
());
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
,
T
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
0.01
);
...
...
@@ -393,3 +393,5 @@ TEST_F(PoolingOpTest, OPENCLUnAlignedLargeKernelAvgPooling) {
AvgPoolingTest
<
OPENCL
,
float
>
({
3
,
31
,
37
,
128
},
{
8
,
8
},
{
8
,
8
},
Padding
::
SAME
);
}
}
// namespace mace
mace/ops/reshape.h
浏览文件 @
5ba3dd5b
...
...
@@ -5,6 +5,8 @@
#ifndef MACE_OPS_RESHAPE_H_
#define MACE_OPS_RESHAPE_H_
#include <vector>
#include "mace/core/operator.h"
#include "mace/kernels/reshape.h"
...
...
mace/ops/reshape_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -6,7 +6,7 @@
#include "mace/core/operator.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
class
ReshapeTest
:
public
OpsTestBase
{};
...
...
@@ -53,3 +53,5 @@ TEST_F(ReshapeTest, Complex) {
TestReshape
({
1
,
2
,
3
,
4
},
{
-
1
,
1
},
{
24
,
1
});
TestReshape
({
1
,
2
,
3
,
4
},
{
1
,
3
,
8
},
{
1
,
3
,
8
});
}
}
// namespace mace
mace/ops/resize_bilinear.h
浏览文件 @
5ba3dd5b
...
...
@@ -2,8 +2,8 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_
RESIZE_BILINEAR_H
#define MACE_
RESIZE_BILINEAR_H
#ifndef MACE_
OPS_RESIZE_BILINEAR_H_
#define MACE_
OPS_RESIZE_BILINEAR_H_
#include "mace/core/operator.h"
#include "mace/kernels/resize_bilinear.h"
...
...
@@ -36,4 +36,4 @@ class ResizeBilinearOp : public Operator<D, T> {
}
// namespace mace
#endif // MACE_
RESIZE_BILINEAR_H
#endif // MACE_
OPS_RESIZE_BILINEAR_H_
mace/ops/resize_bilinear_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -26,7 +26,7 @@ static void ResizeBilinearBenchmark(int iters,
net
.
AddInputFromArray
<
D
,
index_t
>
(
"OutSize"
,
{
2
},
{
output_height
,
output_width
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearBenchmark"
)
.
Input
(
"InputImage"
)
...
...
@@ -59,7 +59,8 @@ static void ResizeBilinearBenchmark(int iters,
#define BM_RESIZE_BILINEAR_MACRO(N, C, H0, W0, H1, W1, TYPE, DEVICE) \
static void \
BM_RESIZE_BILINEAR_##N##_##C##_##H0##_##W0##_##H1##_##W1##_##TYPE##_##DEVICE( \
BM_RESIZE_BILINEAR_##N##_##C##_##H0##_##W0##_##H1##_##W1##_##TYPE##_\
##DEVICE( \
int iters) { \
const int64_t macc = static_cast<int64_t>(iters) * N * C * H1 * W1 * 3; \
const int64_t tot = static_cast<int64_t>(iters) * N * C * H0 * W0; \
...
...
@@ -68,7 +69,8 @@ static void ResizeBilinearBenchmark(int iters,
ResizeBilinearBenchmark<DEVICE, TYPE>(iters, N, C, H0, W0, H1, W1); \
} \
BENCHMARK( \
BM_RESIZE_BILINEAR_##N##_##C##_##H0##_##W0##_##H1##_##W1##_##TYPE##_##DEVICE)
BM_RESIZE_BILINEAR_##N##_##C##_##H0##_##W0##_##H1##_##W1##_##TYPE##_\
##DEVICE)
#define BM_RESIZE_BILINEAR(N, C, H0, W0, H1, W1) \
BM_RESIZE_BILINEAR_MACRO(N, C, H0, W0, H1, W1, float, CPU); \
...
...
mace/ops/resize_bilinear_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -2,11 +2,13 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <vector>
#include "mace/ops/resize_bilinear.h"
#include "mace/core/operator.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
class
ResizeBilinearTest
:
public
OpsTestBase
{};
...
...
@@ -61,17 +63,17 @@ TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) {
template
<
DeviceType
D
>
void
TestRandomResizeBilinear
()
{
srand
(
time
(
nullptr
)
);
unsigned
int
seed
=
time
(
nullptr
);
testing
::
internal
::
LogToStderr
();
for
(
int
round
=
0
;
round
<
10
;
++
round
)
{
int
batch
=
1
+
rand
(
)
%
5
;
int
channels
=
1
+
rand
(
)
%
100
;
int
height
=
1
+
rand
(
)
%
100
;
int
width
=
1
+
rand
(
)
%
100
;
int
in_height
=
1
+
rand
(
)
%
100
;
int
in_width
=
1
+
rand
(
)
%
100
;
int
align_corners
=
rand
(
)
%
1
;
int
batch
=
1
+
rand
_r
(
&
seed
)
%
5
;
int
channels
=
1
+
rand
_r
(
&
seed
)
%
100
;
int
height
=
1
+
rand
_r
(
&
seed
)
%
100
;
int
width
=
1
+
rand
_r
(
&
seed
)
%
100
;
int
in_height
=
1
+
rand
_r
(
&
seed
)
%
100
;
int
in_width
=
1
+
rand
_r
(
&
seed
)
%
100
;
int
align_corners
=
rand
_r
(
&
seed
)
%
1
;
// Construct graph
OpsTestNet
net
;
...
...
@@ -91,7 +93,7 @@ void TestRandomResizeBilinear() {
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"ResizeBilinear"
,
"ResizeBilinearTest"
)
...
...
@@ -103,10 +105,10 @@ void TestRandomResizeBilinear() {
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"DeviceOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"DeviceOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
// TODO support NEON
// TODO
(yejianwu)
support NEON
}
// Check
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"DeviceOutput"
),
0.001
);
...
...
@@ -122,3 +124,5 @@ TEST_F(ResizeBilinearTest, NEONRandomResizeBilinear) {
TEST_F
(
ResizeBilinearTest
,
OPENCLRandomResizeBilinear
)
{
TestRandomResizeBilinear
<
DeviceType
::
OPENCL
>
();
}
}
// namespace mace
mace/ops/slice.h
浏览文件 @
5ba3dd5b
...
...
@@ -5,6 +5,8 @@
#ifndef MACE_OPS_SLICE_H_
#define MACE_OPS_SLICE_H_
#include <vector>
#include "mace/core/operator.h"
#include "mace/kernels/slice.h"
namespace
mace
{
...
...
@@ -16,10 +18,12 @@ class SliceOp : public Operator<D, T> {
:
Operator
<
D
,
T
>
(
op_def
,
ws
)
{}
bool
Run
(
StatsFuture
*
future
)
override
{
MACE_CHECK
(
this
->
OutputSize
()
>=
2
)
<<
"There must be at least two outputs for slicing"
;
MACE_CHECK
(
this
->
OutputSize
()
>=
2
)
<<
"There must be at least two outputs for slicing"
;
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
const
std
::
vector
<
Tensor
*>
output_list
=
this
->
Outputs
();
MACE_CHECK
((
input
->
dim
(
3
)
%
this
->
OutputSize
())
==
0
)
<<
"Outputs do not split input equally."
;
MACE_CHECK
((
input
->
dim
(
3
)
%
this
->
OutputSize
())
==
0
)
<<
"Outputs do not split input equally."
;
functor_
(
input
,
output_list
,
future
);
return
true
;
...
...
mace/ops/slice_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -16,13 +16,16 @@ static void BMSliceHelper(int iters,
// Construct graph
OpsTestNet
net
;
const
index_t
input_size
=
std
::
accumulate
(
input_shape
.
begin
(),
input_shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
const
index_t
input_size
=
std
::
accumulate
(
input_shape
.
begin
(),
input_shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
std
::
vector
<
float
>
input_data
(
input_size
);
GenerateRandomRealTypeData
(
input_shape
,
input_data
);
GenerateRandomRealTypeData
(
input_shape
,
&
input_data
);
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
input_shape
,
input_data
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
auto
builder
=
OpDefBuilder
(
"Slice"
,
"SliceTest"
);
...
...
@@ -56,7 +59,8 @@ static void BMSliceHelper(int iters,
}
#define BM_SLICE_MACRO(N, H, W, C, NO, TYPE, DEVICE) \
static void BM_SLICE_##N##_##H##_##W##_##C##_##NO##_##TYPE##_##DEVICE(int iters) { \
static void \
BM_SLICE_##N##_##H##_##W##_##C##_##NO##_##TYPE##_##DEVICE(int iters) { \
const int64_t tot = static_cast<int64_t>(iters) * N * H * W * C; \
mace::testing::MaccProcessed(tot); \
mace::testing::BytesProcessed(tot *(sizeof(TYPE))); \
...
...
mace/ops/slice_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -2,34 +2,40 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <functional>
#include <vector>
#include "mace/ops/slice.h"
#include "mace/ops/ops_test_util.h"
#include "gmock/gmock.h"
using
namespace
mace
;
namespace
mace
{
class
SliceOpTest
:
public
OpsTestBase
{};
template
<
DeviceType
D
,
typename
T
>
void
RandomTest
(
const
int
num_outputs
)
{
srand
(
time
(
nullptr
)
);
const
index_t
output_channels
=
4
*
(
1
+
rand
(
)
%
10
);
unsigned
int
seed
=
time
(
nullptr
);
const
index_t
output_channels
=
4
*
(
1
+
rand
_r
(
&
seed
)
%
10
);
const
index_t
input_channels
=
num_outputs
*
output_channels
;
const
index_t
batch
=
3
+
(
rand
(
)
%
10
);
const
index_t
height
=
13
+
(
rand
(
)
%
10
);
const
index_t
width
=
17
+
(
rand
(
)
%
10
);
const
index_t
batch
=
3
+
(
rand
_r
(
&
seed
)
%
10
);
const
index_t
height
=
13
+
(
rand
_r
(
&
seed
)
%
10
);
const
index_t
width
=
17
+
(
rand
_r
(
&
seed
)
%
10
);
// Construct graph
OpsTestNet
net
;
std
::
vector
<
index_t
>
input_shape
({
batch
,
height
,
width
,
input_channels
});
const
index_t
input_size
=
std
::
accumulate
(
input_shape
.
begin
(),
input_shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
const
index_t
input_size
=
std
::
accumulate
(
input_shape
.
begin
(),
input_shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
std
::
vector
<
float
>
input_data
(
input_size
);
GenerateRandomRealTypeData
(
input_shape
,
input_data
);
GenerateRandomRealTypeData
(
input_shape
,
&
input_data
);
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
input_shape
,
input_data
);
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
auto
builder
=
OpDefBuilder
(
"Slice"
,
"SliceTest"
);
...
...
@@ -47,7 +53,6 @@ void RandomTest(const int num_outputs) {
builder
=
builder
.
Output
(
MakeString
(
"Output"
,
i
));
}
builder
.
Finalize
(
net
.
NewOperatorDef
());
}
// Run
...
...
@@ -55,15 +60,19 @@ void RandomTest(const int num_outputs) {
if
(
D
==
DeviceType
::
OPENCL
)
{
for
(
int
i
=
0
;
i
<
num_outputs
;
++
i
)
{
ImageToBuffer
<
D
,
float
>
(
net
,
MakeString
(
"OutputImage"
,
i
),
MakeString
(
"Output"
,
i
),
ImageToBuffer
<
D
,
float
>
(
&
net
,
MakeString
(
"OutputImage"
,
i
),
MakeString
(
"Output"
,
i
),
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
}
// Check
std
::
vector
<
index_t
>
expected_shape
({
batch
,
height
,
width
,
output_channels
});
const
index_t
outer_size
=
std
::
accumulate
(
expected_shape
.
begin
(),
expected_shape
.
end
()
-
1
,
1
,
std
::
multiplies
<
index_t
>
());
const
index_t
outer_size
=
std
::
accumulate
(
expected_shape
.
begin
(),
expected_shape
.
end
()
-
1
,
1
,
std
::
multiplies
<
index_t
>
());
const
float
*
input_ptr
=
input_data
.
data
();
const
float
*
output_ptr
;
for
(
int
i
=
0
;
i
<
num_outputs
;
++
i
)
{
...
...
@@ -74,7 +83,8 @@ void RandomTest(const int num_outputs) {
for
(
int
outer_idx
=
0
;
outer_idx
<
outer_size
;
++
outer_idx
)
{
const
int
idx
=
outer_idx
*
input_channels
+
i
*
output_channels
;
for
(
int
j
=
0
;
j
<
output_channels
;
++
j
)
{
ASSERT_NEAR
(
*
output_ptr
++
,
input_ptr
[
idx
+
j
],
1e-2
)
<<
"with output "
<<
i
<<
" index "
<<
idx
+
j
;
ASSERT_NEAR
(
*
output_ptr
++
,
input_ptr
[
idx
+
j
],
1e-2
)
<<
"with output "
<<
i
<<
" index "
<<
idx
+
j
;
}
}
}
...
...
@@ -97,3 +107,5 @@ TEST_F(SliceOpTest, OPENCLHalf) {
RandomTest
<
DeviceType
::
OPENCL
,
half
>
(
4
);
RandomTest
<
DeviceType
::
OPENCL
,
half
>
(
11
);
}
}
// namespace mace
mace/ops/softmax.h
浏览文件 @
5ba3dd5b
...
...
@@ -2,8 +2,8 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_SOFTMAX_H_
#define MACE_SOFTMAX_H_
#ifndef MACE_
OPS_
SOFTMAX_H_
#define MACE_
OPS_
SOFTMAX_H_
#include "mace/core/operator.h"
#include "mace/kernels/softmax.h"
...
...
@@ -36,4 +36,4 @@ class SoftmaxOp : public Operator<D, T> {
}
// namespace mace
#endif // MACE_SOFTMAX_H_
#endif // MACE_
OPS_
SOFTMAX_H_
mace/ops/softmax_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -19,7 +19,7 @@ static void SoftmaxBenchmark(
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Softmax"
,
"SoftmaxBM"
)
...
...
mace/ops/softmax_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -18,7 +18,7 @@ void Simple() {
{
1
,
1
,
1
,
1
,
1
,
2
,
3
,
4
});
if
(
D
==
DeviceType
::
OPENCL
)
{
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Softmax"
,
"SoftmaxTest"
)
...
...
@@ -30,7 +30,7 @@ void Simple() {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
OpDefBuilder
(
"Softmax"
,
"SoftmaxTest"
)
...
...
@@ -69,7 +69,7 @@ void Complex(const std::vector<index_t> &logits_shape) {
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"Output"
));
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"Softmax"
,
"SoftmaxTest"
)
...
...
@@ -81,7 +81,7 @@ void Complex(const std::vector<index_t> &logits_shape) {
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"OPENCLOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"OPENCLOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"OPENCLOutput"
),
1e-5
);
...
...
mace/ops/space_to_batch.h
浏览文件 @
5ba3dd5b
...
...
@@ -6,6 +6,7 @@
#define MACE_OPS_SPACE_TO_BATCH_H_
#include <memory>
#include <vector>
#include "mace/core/operator.h"
#include "mace/kernels/space_to_batch.h"
...
...
mace/ops/space_to_batch_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -15,7 +15,7 @@ static void BMSpaceToBatch(
OpsTestNet
net
;
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"SpaceToBatchND"
,
"SpaceToBatchNDTest"
)
.
Input
(
"InputImage"
)
...
...
mace/ops/space_to_batch_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -6,7 +6,7 @@
#include "gtest/gtest.h"
#include "mace/ops/ops_test_util.h"
using
namespace
mace
;
namespace
mace
{
template
<
DeviceType
D
>
void
RunSpaceToBatch
(
const
std
::
vector
<
index_t
>
&
input_shape
,
...
...
@@ -17,7 +17,7 @@ void RunSpaceToBatch(const std::vector<index_t> &input_shape,
OpsTestNet
net
;
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
input_shape
,
input_data
);
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"SpaceToBatchND"
,
"SpaceToBatchNDTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -29,7 +29,7 @@ void RunSpaceToBatch(const std::vector<index_t> &input_shape,
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
// Check
ExpectTensorNear
<
float
>
(
*
expected
,
*
net
.
GetOutput
(
"Output"
),
1e-8
);
...
...
@@ -45,7 +45,7 @@ void RunBatchToSpace(const std::vector<index_t> &input_shape,
// Add input data
net
.
AddInputFromArray
<
D
,
float
>
(
"Input"
,
input_shape
,
input_data
);
BufferToImage
<
D
,
float
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
float
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"BatchToSpaceND"
,
"BatchToSpaceNDTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -57,7 +57,7 @@ void RunBatchToSpace(const std::vector<index_t> &input_shape,
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
net
,
"OutputImage"
,
"Output"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
// Check
ExpectTensorNear
<
float
>
(
*
expected
,
*
net
.
GetOutput
(
"Output"
),
1e-8
);
...
...
@@ -216,3 +216,5 @@ TEST(SpaceToBatchTest, MultiBatchAndChannelData) {
// {2, 2, 2, 2},
// space_tensor.get());
//}
}
// namespace mace
mace/ops/winograd_convolution_test.cc
浏览文件 @
5ba3dd5b
...
...
@@ -13,8 +13,9 @@ class WinogradConvlutionTest : public OpsTestBase {};
void
TransposeFilter
(
const
std
::
vector
<
float
>
&
input
,
const
std
::
vector
<
index_t
>
&
input_shape
,
std
::
vector
<
float
>
&
output
)
{
output
.
resize
(
input
.
size
());
std
::
vector
<
float
>
*
output
)
{
MACE_CHECK_NOTNULL
(
output
);
output
->
resize
(
input
.
size
());
const
float
*
input_ptr
=
input
.
data
();
for
(
index_t
h
=
0
;
h
<
input_shape
[
0
];
++
h
)
{
...
...
@@ -24,7 +25,7 @@ void TransposeFilter(const std::vector<float> &input,
int
offset
=
((
oc
*
input_shape
[
3
]
+
ic
)
*
input_shape
[
0
]
+
h
)
*
input_shape
[
1
]
+
w
;
output
[
offset
]
=
*
input_ptr
;
(
*
output
)
[
offset
]
=
*
input_ptr
;
++
input_ptr
;
}
}
...
...
@@ -46,16 +47,16 @@ void WinogradConvolution(const index_t batch,
// Add input data
std
::
vector
<
float
>
filter_data
;
std
::
vector
<
index_t
>
filter_shape
=
{
3
,
3
,
out_channels
,
in_channels
};
GenerateRandomRealTypeData
<
float
>
(
filter_shape
,
filter_data
);
GenerateRandomRealTypeData
<
float
>
(
filter_shape
,
&
filter_data
);
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
in_channels
});
net
.
AddInputFromArray
<
D
,
float
>
(
"Filter"
,
filter_shape
,
filter_data
);
net
.
AddRandomInput
<
D
,
T
>
(
"Bias"
,
{
out_channels
});
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
.
Input
(
"InputImage"
)
.
Input
(
"FilterImage"
)
...
...
@@ -69,7 +70,7 @@ void WinogradConvolution(const index_t batch,
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"ConvOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"ConvOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"ConvOutput"
));
...
...
@@ -78,10 +79,10 @@ void WinogradConvolution(const index_t batch,
// Winograd convolution
// transform filter
std
::
vector
<
float
>
wino_filter_data
;
TransposeFilter
(
filter_data
,
filter_shape
,
wino_filter_data
);
TransposeFilter
(
filter_data
,
filter_shape
,
&
wino_filter_data
);
net
.
AddInputFromArray
<
D
,
float
>
(
"WinoFilterData"
,
{
out_channels
,
in_channels
,
3
,
3
},
wino_filter_data
);
BufferToImage
<
D
,
T
>
(
net
,
"WinoFilterData"
,
"WinoFilter"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"WinoFilterData"
,
"WinoFilter"
,
kernels
::
BufferType
::
WINOGRAD_FILTER
);
// transform input
...
...
@@ -119,7 +120,7 @@ void WinogradConvolution(const index_t batch,
net
.
RunOp
(
D
);
net
.
Sync
();
ImageToBuffer
<
D
,
float
>
(
net
,
"WinoOutputImage"
,
"WinoOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"WinoOutputImage"
,
"WinoOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
if
(
DataTypeToEnum
<
T
>::
value
==
DataType
::
DT_HALF
)
{
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"WinoOutput"
),
1e-1
);
...
...
@@ -163,16 +164,16 @@ void WinogradConvolutionWithPad(const index_t batch,
// Add input data
std
::
vector
<
float
>
filter_data
;
std
::
vector
<
index_t
>
filter_shape
=
{
3
,
3
,
out_channels
,
in_channels
};
GenerateRandomRealTypeData
<
float
>
(
filter_shape
,
filter_data
);
GenerateRandomRealTypeData
<
float
>
(
filter_shape
,
&
filter_data
);
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
in_channels
});
net
.
AddInputFromArray
<
D
,
float
>
(
"Filter"
,
filter_shape
,
filter_data
);
net
.
AddRandomInput
<
D
,
T
>
(
"Bias"
,
{
out_channels
});
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
net
,
"Filter"
,
"FilterImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Filter"
,
"FilterImage"
,
kernels
::
BufferType
::
CONV2D_FILTER
);
BufferToImage
<
D
,
T
>
(
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
BufferToImage
<
D
,
T
>
(
&
net
,
"Bias"
,
"BiasImage"
,
kernels
::
BufferType
::
ARGUMENT
);
OpDefBuilder
(
"Conv2D"
,
"Conv2dTest"
)
.
Input
(
"InputImage"
)
.
Input
(
"FilterImage"
)
...
...
@@ -186,7 +187,7 @@ void WinogradConvolutionWithPad(const index_t batch,
net
.
RunOp
(
D
);
// Transfer output
ImageToBuffer
<
D
,
T
>
(
net
,
"OutputImage"
,
"ConvOutput"
,
ImageToBuffer
<
D
,
T
>
(
&
net
,
"OutputImage"
,
"ConvOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
Tensor
expected
;
expected
.
Copy
(
*
net
.
GetOutput
(
"ConvOutput"
));
...
...
@@ -195,10 +196,10 @@ void WinogradConvolutionWithPad(const index_t batch,
// Winograd convolution
// transform filter
std
::
vector
<
float
>
wino_filter_data
;
TransposeFilter
(
filter_data
,
filter_shape
,
wino_filter_data
);
TransposeFilter
(
filter_data
,
filter_shape
,
&
wino_filter_data
);
net
.
AddInputFromArray
<
D
,
float
>
(
"WinoFilterData"
,
{
out_channels
,
in_channels
,
3
,
3
},
wino_filter_data
);
BufferToImage
<
D
,
T
>
(
net
,
"WinoFilterData"
,
"WinoFilter"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"WinoFilterData"
,
"WinoFilter"
,
kernels
::
BufferType
::
WINOGRAD_FILTER
);
// transform input
...
...
@@ -236,7 +237,7 @@ void WinogradConvolutionWithPad(const index_t batch,
net
.
RunOp
(
D
);
net
.
Sync
();
ImageToBuffer
<
D
,
float
>
(
net
,
"WinoOutputImage"
,
"WinoOutput"
,
ImageToBuffer
<
D
,
float
>
(
&
net
,
"WinoOutputImage"
,
"WinoOutput"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
if
(
DataTypeToEnum
<
T
>::
value
==
DataType
::
DT_HALF
)
{
ExpectTensorNear
<
float
>
(
expected
,
*
net
.
GetOutput
(
"WinoOutput"
),
1e-1
);
...
...
@@ -250,4 +251,4 @@ TEST_F(WinogradConvlutionTest, UnAlignedConvolutionPad2) {
WinogradConvolutionWithPad
<
DeviceType
::
OPENCL
,
float
>
(
1
,
32
,
32
,
96
,
109
,
2
);
}
}
}
// namespace mace
mace/ops/winograd_inverse_transform.h
浏览文件 @
5ba3dd5b
...
...
@@ -6,6 +6,7 @@
#define MACE_OPS_WINOGRAD_INVERSE_TRANSFORM_H_
#include <memory>
#include <string>
#include "mace/core/operator.h"
#include "mace/kernels/activation.h"
...
...
mace/ops/winograd_transform_benchmark.cc
浏览文件 @
5ba3dd5b
...
...
@@ -15,7 +15,7 @@ static void BMWinogradTransform(
OpsTestNet
net
;
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
batch
,
height
,
width
,
channels
});
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
OpDefBuilder
(
"WinogradTransform"
,
"WinogradTransformTest"
)
.
Input
(
"InputImage"
)
...
...
@@ -62,7 +62,7 @@ static void BMWinogradInverseTransform(
OpsTestNet
net
;
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
{
16
,
channels
,
p
,
1
});
BufferToImage
<
D
,
T
>
(
net
,
"Input"
,
"InputImage"
,
BufferToImage
<
D
,
T
>
(
&
net
,
"Input"
,
"InputImage"
,
kernels
::
BufferType
::
IN_OUT_HEIGHT
);
OpDefBuilder
(
"WinogradInverseTransform"
,
"WinogradInverseTransformTest"
)
.
Input
(
"InputImage"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录