Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
b7155afc
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b7155afc
编写于
9月 27, 2017
作者:
李
李寅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add openmp as compiler opt
上级
44cdbb67
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
45 deletion
+66
-45
mace/core/proto_utils.cc
mace/core/proto_utils.cc
+2
-0
mace/kernels/BUILD
mace/kernels/BUILD
+2
-2
mace/kernels/neon/conv_2d_neon_1x1.cc
mace/kernels/neon/conv_2d_neon_1x1.cc
+2
-2
mace/kernels/neon/conv_2d_neon_3x3.cc
mace/kernels/neon/conv_2d_neon_3x3.cc
+57
-38
mace/ops/BUILD
mace/ops/BUILD
+3
-3
未找到文件。
mace/core/proto_utils.cc
浏览文件 @
b7155afc
...
@@ -314,6 +314,8 @@ const Argument& GetArgument(const OperatorDef& def, const string& name) {
...
@@ -314,6 +314,8 @@ const Argument& GetArgument(const OperatorDef& def, const string& name) {
}
}
MACE_CHECK
(
false
,
"Argument named "
,
name
,
"does not exist in operator "
,
MACE_CHECK
(
false
,
"Argument named "
,
name
,
"does not exist in operator "
,
ProtoDebugString
(
def
));
ProtoDebugString
(
def
));
// should not reach here, just make compiler happy
return
std
::
move
(
Argument
());
}
}
bool
GetFlagArgument
(
const
OperatorDef
&
def
,
bool
GetFlagArgument
(
const
OperatorDef
&
def
,
...
...
mace/kernels/BUILD
浏览文件 @
b7155afc
...
@@ -17,8 +17,8 @@ cc_library(
...
@@ -17,8 +17,8 @@ cc_library(
deps
=
[
deps
=
[
"//mace/core:core"
,
"//mace/core:core"
,
],
],
copts
=
[
'-std=c++11'
],
copts
=
[
'-std=c++11'
,
"-fopenmp"
,
],
linkopts
=
[
"-fopenmp"
]
+
if_android
([
"-lm"
]),
linkopts
=
if_android
([
"-lm"
]),
)
)
cc_test
(
cc_test
(
...
...
mace/kernels/neon/conv_2d_neon_1x1.cc
浏览文件 @
b7155afc
...
@@ -35,10 +35,10 @@ void Conv2dNeonK1x1S1(const float *input, // NCHW
...
@@ -35,10 +35,10 @@ void Conv2dNeonK1x1S1(const float *input, // NCHW
const
index_t
loop_remaining
=
total_pixels
&
7
;
const
index_t
loop_remaining
=
total_pixels
&
7
;
// benchmark omp collapsed(2)
// benchmark omp collapsed(2)
#pragma omp parallel for collapse(2)
for
(
index_t
n
=
0
;
n
<
batch
;
++
n
)
{
for
(
index_t
n
=
0
;
n
<
batch
;
++
n
)
{
const
float
*
filter_ptr
=
filter
;
#pragma omp parallel for
for
(
index_t
c
=
0
;
c
<
channels
;
++
c
)
{
for
(
index_t
c
=
0
;
c
<
channels
;
++
c
)
{
const
float
*
filter_ptr
=
filter
;
// TODO Will GCC opt these out?
// TODO Will GCC opt these out?
float
*
channel_output_start
=
float
*
channel_output_start
=
output
+
n
*
channels
*
height
*
width
+
c
*
height
*
width
;
output
+
n
*
channels
*
height
*
width
+
c
*
height
*
width
;
...
...
mace/kernels/neon/conv_2d_neon_3x3.cc
浏览文件 @
b7155afc
...
@@ -8,37 +8,6 @@
...
@@ -8,37 +8,6 @@
namespace
mace
{
namespace
mace
{
namespace
kernels
{
namespace
kernels
{
#define KERNEL_HEAD_CODE \
int output_batch = output_shape[0]; \
int output_channels = output_shape[1]; \
int output_height = output_shape[2]; \
int output_width = output_shape[3]; \
int input_batch = input_shape[0]; \
int input_channels = input_shape[1]; \
int input_height = input_shape[2]; \
int input_width = input_shape[3]; \
int multiplier = filter_shape == nullptr ? 0 : (filter_shape[0] / input_channels); \
int filter_in_channels = filter_shape == nullptr ? input_channels : filter_shape[1]; \
for (int b = 0; b < output_batch; ++b) { \
float *output_ptr_base = output + b * output_channels * output_height * output_width; \
for (int oc = 0; oc < output_channels; ++oc) { \
const float *filter_ptr = filter + oc * filter_in_channels * kFilterSize; \
const float *input_ptr = input + b * input_channels * input_height * input_width; \
if (filter_shape != nullptr) { \
input_ptr += (oc / multiplier) * input_height * input_width; \
} \
float *output_ptr = output_ptr_base + oc * output_height * output_width; \
std::fill(output_ptr, output_ptr + output_height * output_width, bias ? bias[oc] : 0); \
for (int ic = 0; ic < filter_in_channels; ++ic) { \
float32x4_t n_filter_v[3] = {vld1q_f32(filter_ptr), vld1q_f32(filter_ptr+3), vld1q_f32(filter_ptr+6)};
#define KERNEL_TAIL_CODE \
filter_ptr += kFilterSize; \
input_ptr += input_height * input_width; \
} \
} \
}
static
const
int
kRegisterSize
=
4
;
static
const
int
kRegisterSize
=
4
;
static
const
int
kFilterSize
=
9
;
static
const
int
kFilterSize
=
9
;
...
@@ -52,7 +21,29 @@ void Conv2dNeonK3x3S1(const float *input, // NCHW
...
@@ -52,7 +21,29 @@ void Conv2dNeonK3x3S1(const float *input, // NCHW
int
height_count
=
(
output_shape
[
2
]
>>
1
)
<<
1
;
int
height_count
=
(
output_shape
[
2
]
>>
1
)
<<
1
;
KERNEL_HEAD_CODE
int
output_batch
=
output_shape
[
0
];
int
output_channels
=
output_shape
[
1
];
int
output_height
=
output_shape
[
2
];
int
output_width
=
output_shape
[
3
];
int
input_batch
=
input_shape
[
0
];
int
input_channels
=
input_shape
[
1
];
int
input_height
=
input_shape
[
2
];
int
input_width
=
input_shape
[
3
];
int
multiplier
=
filter_shape
==
nullptr
?
0
:
(
filter_shape
[
0
]
/
input_channels
);
int
filter_in_channels
=
filter_shape
==
nullptr
?
input_channels
:
filter_shape
[
1
];
#pragma omp parallel for collapse(2)
for
(
int
b
=
0
;
b
<
output_batch
;
++
b
)
{
for
(
int
oc
=
0
;
oc
<
output_channels
;
++
oc
)
{
float
*
output_ptr_base
=
output
+
b
*
output_channels
*
output_height
*
output_width
;
const
float
*
filter_ptr
=
filter
+
oc
*
filter_in_channels
*
kFilterSize
;
const
float
*
input_ptr
=
input
+
b
*
input_channels
*
input_height
*
input_width
;
if
(
filter_shape
!=
nullptr
)
{
input_ptr
+=
(
oc
/
multiplier
)
*
input_height
*
input_width
;
}
float
*
output_ptr
=
output_ptr_base
+
oc
*
output_height
*
output_width
;
std
::
fill
(
output_ptr
,
output_ptr
+
output_height
*
output_width
,
bias
?
bias
[
oc
]
:
0
);
for
(
int
ic
=
0
;
ic
<
filter_in_channels
;
++
ic
)
{
float32x4_t
n_filter_v
[
3
]
=
{
vld1q_f32
(
filter_ptr
),
vld1q_f32
(
filter_ptr
+
3
),
vld1q_f32
(
filter_ptr
+
6
)};
const
float
*
row_ptr_v
[
kRegisterSize
]
=
{
const
float
*
row_ptr_v
[
kRegisterSize
]
=
{
input_ptr
,
input_ptr
+
input_width
,
input_ptr
,
input_ptr
+
input_width
,
...
@@ -212,7 +203,11 @@ void Conv2dNeonK3x3S1(const float *input, // NCHW
...
@@ -212,7 +203,11 @@ void Conv2dNeonK3x3S1(const float *input, // NCHW
}
}
}
}
KERNEL_TAIL_CODE
filter_ptr
+=
kFilterSize
;
input_ptr
+=
input_height
*
input_width
;
}
}
}
}
}
void
Conv2dNeonK3x3S2
(
const
float
*
input
,
// NCHW
void
Conv2dNeonK3x3S2
(
const
float
*
input
,
// NCHW
...
@@ -224,7 +219,30 @@ void Conv2dNeonK3x3S2(const float *input, // NCHW
...
@@ -224,7 +219,30 @@ void Conv2dNeonK3x3S2(const float *input, // NCHW
const
index_t
*
output_shape
)
{
const
index_t
*
output_shape
)
{
int
tail_step
=
2
*
(
input_shape
[
3
]
-
output_shape
[
3
]);
int
tail_step
=
2
*
(
input_shape
[
3
]
-
output_shape
[
3
]);
KERNEL_HEAD_CODE
int
output_batch
=
output_shape
[
0
];
int
output_channels
=
output_shape
[
1
];
int
output_height
=
output_shape
[
2
];
int
output_width
=
output_shape
[
3
];
int
input_batch
=
input_shape
[
0
];
int
input_channels
=
input_shape
[
1
];
int
input_height
=
input_shape
[
2
];
int
input_width
=
input_shape
[
3
];
int
multiplier
=
filter_shape
==
nullptr
?
0
:
(
filter_shape
[
0
]
/
input_channels
);
int
filter_in_channels
=
filter_shape
==
nullptr
?
input_channels
:
filter_shape
[
1
];
#pragma omp parallel for collapse(2)
for
(
int
b
=
0
;
b
<
output_batch
;
++
b
)
{
for
(
int
oc
=
0
;
oc
<
output_channels
;
++
oc
)
{
float
*
output_ptr_base
=
output
+
b
*
output_channels
*
output_height
*
output_width
;
const
float
*
filter_ptr
=
filter
+
oc
*
filter_in_channels
*
kFilterSize
;
const
float
*
input_ptr
=
input
+
b
*
input_channels
*
input_height
*
input_width
;
if
(
filter_shape
!=
nullptr
)
{
input_ptr
+=
(
oc
/
multiplier
)
*
input_height
*
input_width
;
}
float
*
output_ptr
=
output_ptr_base
+
oc
*
output_height
*
output_width
;
std
::
fill
(
output_ptr
,
output_ptr
+
output_height
*
output_width
,
bias
?
bias
[
oc
]
:
0
);
for
(
int
ic
=
0
;
ic
<
filter_in_channels
;
++
ic
)
{
float32x4_t
n_filter_v
[
3
]
=
{
vld1q_f32
(
filter_ptr
),
vld1q_f32
(
filter_ptr
+
3
),
vld1q_f32
(
filter_ptr
+
6
)};
const
float
*
row_ptr_v
[
3
]
=
{
const
float
*
row_ptr_v
[
3
]
=
{
input_ptr
,
input_ptr
+
input_width
,
input_ptr
+
2
*
input_width
input_ptr
,
input_ptr
+
input_width
,
input_ptr
+
2
*
input_width
...
@@ -291,10 +309,11 @@ void Conv2dNeonK3x3S2(const float *input, // NCHW
...
@@ -291,10 +309,11 @@ void Conv2dNeonK3x3S2(const float *input, // NCHW
}
}
}
}
KERNEL_TAIL_CODE
filter_ptr
+=
kFilterSize
;
input_ptr
+=
input_height
*
input_width
;
}
}
}
}
}
#undef KERNEL_HEAD_CODE
#undef KERNEL_TAIL_CODE
}
// namespace kernels
}
// namespace kernels
}
// namespace mace
}
// namespace mace
mace/ops/BUILD
浏览文件 @
b7155afc
...
@@ -34,7 +34,7 @@ cc_library(
...
@@ -34,7 +34,7 @@ cc_library(
[
"*.h"
],
[
"*.h"
],
exclude
=
[
"ops_test_util.h"
],
exclude
=
[
"ops_test_util.h"
],
),
),
copts
=
[
"-std=c++11"
],
copts
=
[
"-std=c++11"
,
"-fopenmp"
,
],
deps
=
[
deps
=
[
"//mace/core"
,
"//mace/core"
,
"//mace/kernels"
,
"//mace/kernels"
,
...
@@ -50,7 +50,7 @@ cc_test(
...
@@ -50,7 +50,7 @@ cc_test(
[
"*_test.cc"
],
[
"*_test.cc"
],
),
),
copts
=
[
"-std=c++11"
],
copts
=
[
"-std=c++11"
],
linkopts
=
if_android
([
"-ldl"
]),
linkopts
=
[
"-fopenmp"
,]
+
if_android
([
"-ldl"
]),
linkstatic
=
1
,
linkstatic
=
1
,
deps
=
[
deps
=
[
":ops"
,
":ops"
,
...
@@ -64,7 +64,7 @@ cc_test(
...
@@ -64,7 +64,7 @@ cc_test(
testonly
=
1
,
testonly
=
1
,
srcs
=
glob
([
"*_benchmark.cc"
]),
srcs
=
glob
([
"*_benchmark.cc"
]),
copts
=
[
"-std=c++11"
],
copts
=
[
"-std=c++11"
],
linkopts
=
if_android
([
"-ldl"
]),
linkopts
=
[
"-fopenmp"
,]
+
if_android
([
"-ldl"
]),
linkstatic
=
1
,
linkstatic
=
1
,
deps
=
[
deps
=
[
":ops"
,
":ops"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录