Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
96f486a5
Mace
项目概览
Xiaomi
/
Mace
通知
106
Star
40
Fork
27
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
96f486a5
编写于
1月 10, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor tuning code as dev/prod library
上级
1b871466
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
93 addition
and
43 deletion
+93
-43
mace/core/BUILD
mace/core/BUILD
+3
-1
mace/core/runtime/opencl/opencl_development.cc
mace/core/runtime/opencl/opencl_development.cc
+0
-31
mace/core/runtime/opencl/opencl_production.cc
mace/core/runtime/opencl/opencl_production.cc
+0
-9
mace/utils/BUILD
mace/utils/BUILD
+23
-1
mace/utils/tuner.h
mace/utils/tuner.h
+3
-1
mace/utils/tuner_development.cc
mace/utils/tuner_development.cc
+40
-0
mace/utils/tuner_production.cc
mace/utils/tuner_production.cc
+21
-0
tools/bazel-adb-run.sh
tools/bazel-adb-run.sh
+3
-0
未找到文件。
mace/core/BUILD
浏览文件 @
96f486a5
...
...
@@ -47,6 +47,7 @@ cc_library(
linkopts
=
if_android
([
"-pie"
,
"-ldl"
,
"-lm"
,
]),
deps
=
[
":opencl_headers"
,
...
...
@@ -55,8 +56,10 @@ cc_library(
"//mace/utils:utils_hdrs"
,
"//mace/codegen:generated_version"
,
]
+
if_production_mode
([
"//mace/utils:tuner_prod"
,
"//mace/core:opencl_prod"
,
])
+
if_not_production_mode
([
"//mace/utils:tuner_dev"
,
"//mace/core:opencl_dev"
,
]),
)
...
...
@@ -107,6 +110,5 @@ cc_library(
deps
=
[
":opencl_headers"
,
"//mace/codegen:generated_opencl_prod"
,
"//mace/codegen:generated_tuning_params"
,
],
)
mace/core/runtime/opencl/opencl_development.cc
浏览文件 @
96f486a5
...
...
@@ -7,7 +7,6 @@
#include "mace/core/runtime/opencl/cl2_header.h"
#include "mace/utils/utils.h"
namespace
mace
{
bool
GetSourceOrBinaryProgram
(
const
std
::
string
&
program_name
,
...
...
@@ -30,34 +29,4 @@ bool GetSourceOrBinaryProgram(const std::string &program_name,
return
true
;
}
bool
GetTuningParams
(
const
char
*
path
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
*
param_table
)
{
if
(
path
!=
nullptr
)
{
std
::
ifstream
ifs
(
path
,
std
::
ios
::
binary
|
std
::
ios
::
in
);
if
(
ifs
.
is_open
())
{
int64_t
num_params
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
num_params
),
sizeof
(
num_params
));
while
(
num_params
--
)
{
int32_t
key_size
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
key_size
),
sizeof
(
key_size
));
std
::
string
key
(
key_size
,
' '
);
ifs
.
read
(
&
key
[
0
],
key_size
);
int32_t
params_size
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
params_size
),
sizeof
(
params_size
));
int32_t
params_count
=
params_size
/
sizeof
(
unsigned
int
);
std
::
vector
<
unsigned
int
>
params
(
params_count
);
for
(
int
i
=
0
;
i
<
params_count
;
++
i
)
{
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
params
[
i
]),
sizeof
(
unsigned
int
));
}
param_table
->
emplace
(
key
,
params
);
}
ifs
.
close
();
}
else
{
return
false
;
}
}
return
true
;
}
}
// namespace mace
mace/core/runtime/opencl/opencl_production.cc
浏览文件 @
96f486a5
...
...
@@ -23,13 +23,4 @@ bool GetSourceOrBinaryProgram(const std::string &program_name,
return
true
;
}
bool
GetTuningParams
(
const
char
*
path
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
*
param_table
)
{
extern
const
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
kTuningParamsData
;
for
(
auto
it
=
kTuningParamsData
.
begin
();
it
!=
kTuningParamsData
.
end
();
++
it
)
{
param_table
->
emplace
(
it
->
first
,
std
::
vector
<
unsigned
int
>
(
it
->
second
.
begin
(),
it
->
second
.
end
()));
}
return
true
;
}
}
// namespace mace
mace/utils/BUILD
浏览文件 @
96f486a5
...
...
@@ -47,6 +47,27 @@ cc_library(
],
)
cc_library
(
name
=
"tuner_dev"
,
srcs
=
[
"tuner_development.cc"
,
],
deps
=
[
":tuner"
,
],
)
cc_library
(
name
=
"tuner_prod"
,
srcs
=
[
"tuner_production.cc"
,
],
deps
=
[
":tuner"
,
"//mace/codegen:generated_tuning_params"
,
],
)
cc_test
(
name
=
"tuner_test"
,
testonly
=
1
,
...
...
@@ -55,11 +76,12 @@ cc_test(
],
linkopts
=
if_android
([
"-pie"
,
"-lm"
,
"-lm"
,
# Required by unordered_map
]),
linkstatic
=
1
,
deps
=
[
":tuner"
,
":tuner_dev"
,
"@gtest//:gtest"
,
"@gtest//:gtest_main"
,
],
...
...
mace/utils/tuner.h
浏览文件 @
96f486a5
...
...
@@ -62,7 +62,9 @@ class Tuner {
<<
internal
::
MakeString
(
param_table_
[
obfucated_param_key
]);
return
func
(
param_table_
[
obfucated_param_key
]);
}
else
{
LOG
(
WARNING
)
<<
"Fallback to default parameter: "
<<
param_key
<<
", table size: "
<<
param_table_
.
size
();
#ifndef MACE_DISABLE_NO_TUNING_WARNING
LOG
(
WARNING
)
<<
"Fallback to default parameter: "
<<
param_key
;
#endif
return
func
(
default_param
);
}
}
...
...
mace/utils/tuner_development.cc
0 → 100644
浏览文件 @
96f486a5
#include <fstream>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
namespace
mace
{
bool
GetTuningParams
(
const
char
*
path
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
*
param_table
)
{
if
(
path
!=
nullptr
)
{
std
::
ifstream
ifs
(
path
,
std
::
ios
::
binary
|
std
::
ios
::
in
);
if
(
ifs
.
is_open
())
{
int64_t
num_params
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
num_params
),
sizeof
(
num_params
));
while
(
num_params
--
)
{
int32_t
key_size
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
key_size
),
sizeof
(
key_size
));
std
::
string
key
(
key_size
,
' '
);
ifs
.
read
(
&
key
[
0
],
key_size
);
int32_t
params_size
=
0
;
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
params_size
),
sizeof
(
params_size
));
int32_t
params_count
=
params_size
/
sizeof
(
unsigned
int
);
std
::
vector
<
unsigned
int
>
params
(
params_count
);
for
(
int
i
=
0
;
i
<
params_count
;
++
i
)
{
ifs
.
read
(
reinterpret_cast
<
char
*>
(
&
params
[
i
]),
sizeof
(
unsigned
int
));
}
param_table
->
emplace
(
key
,
params
);
}
ifs
.
close
();
}
else
{
return
false
;
}
}
return
true
;
}
}
// namespace mace
mace/utils/tuner_production.cc
0 → 100644
浏览文件 @
96f486a5
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
namespace
mace
{
bool
GetTuningParams
(
const
char
*
path
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
*
param_table
)
{
extern
const
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
kTuningParamsData
;
for
(
auto
it
=
kTuningParamsData
.
begin
();
it
!=
kTuningParamsData
.
end
();
++
it
)
{
param_table
->
emplace
(
it
->
first
,
std
::
vector
<
unsigned
int
>
(
it
->
second
.
begin
(),
it
->
second
.
end
()));
}
return
true
;
}
}
// namespace mace
tools/bazel-adb-run.sh
浏览文件 @
96f486a5
...
...
@@ -32,12 +32,15 @@ echo "Step 2: Generate version source"
bash mace/tools/git/gen_version_source.sh
${
CODEGEN_DIR
}
/version/version.cc
echo
"Step 3: Build target"
# -D_GLIBCXX_USE_C99_MATH_TR1 is used to solve include error instead
# of linking error which solved by -lm
bazel build
-c
opt
$STRIP
--verbose_failures
$BAZEL_TARGET
\
--crosstool_top
=
//external:android/crosstool
\
--host_crosstool_top
=
@bazel_tools//tools/cpp:toolchain
\
--cpu
=
$ANDROID_ABI
\
--copt
=
"-std=c++11"
\
--copt
=
"-D_GLIBCXX_USE_C99_MATH_TR1"
\
--copt
=
"-DMACE_DISABLE_NO_TUNING_WARNING"
\
--copt
=
"-Werror=return-type"
\
--define
neon
=
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录