Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
af787702
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,发现更多精彩内容 >>
提交
af787702
编写于
3月 21, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'code-style' into 'master'
Format code. See merge request !316
上级
90eea482
78bea4fc
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
246 addition
and
181 deletion
+246
-181
mace/benchmark/benchmark_model.cc
mace/benchmark/benchmark_model.cc
+64
-44
mace/benchmark/model_throughput_test.cc
mace/benchmark/model_throughput_test.cc
+29
-19
mace/benchmark/stat_summarizer.cc
mace/benchmark/stat_summarizer.cc
+12
-7
mace/benchmark/stat_summarizer.h
mace/benchmark/stat_summarizer.h
+8
-4
mace/codegen/opencl/opencl_compiled_program.cc
mace/codegen/opencl/opencl_compiled_program.cc
+1
-1
mace/codegen/tuning/tuning_params.cc
mace/codegen/tuning/tuning_params.cc
+1
-1
mace/examples/mace_run.cc
mace/examples/mace_run.cc
+51
-37
mace/public/mace.h
mace/public/mace.h
+8
-7
mace/utils/command_line_flags.cc
mace/utils/command_line_flags.cc
+45
-43
mace/utils/command_line_flags.h
mace/utils/command_line_flags.h
+5
-5
mace/utils/env_time.h
mace/utils/env_time.h
+3
-3
mace/utils/logging.h
mace/utils/logging.h
+2
-1
mace/utils/memory_logging.h
mace/utils/memory_logging.h
+3
-1
mace/utils/string_util.h
mace/utils/string_util.h
+3
-3
mace/utils/tuner.h
mace/utils/tuner.h
+1
-3
mace/utils/tuner_development.cc
mace/utils/tuner_development.cc
+3
-0
mace/utils/tuner_production.cc
mace/utils/tuner_production.cc
+3
-0
mace/utils/tuner_test.cc
mace/utils/tuner_test.cc
+1
-1
mace/utils/utils.h
mace/utils/utils.h
+2
-0
mace/utils/utils_test.cc
mace/utils/utils_test.cc
+1
-1
未找到文件。
mace/benchmark/benchmark_model.cc
浏览文件 @
af787702
...
...
@@ -2,16 +2,18 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include "gflags/gflags.h"
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
#include "mace/benchmark/stat_summarizer.h"
#include <sys/time.h>
#include <cstdlib>
#include <fstream>
#include <thread>
#include <numeric>
#include <sys/time.h>
#include <thread> // NOLINT(build/c++11)
#include "gflags/gflags.h"
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
#include "mace/benchmark/stat_summarizer.h"
namespace
mace
{
namespace
MACE_MODEL_TAG
{
...
...
@@ -24,10 +26,11 @@ extern NetDef CreateNet(const unsigned char *model_data);
extern
const
std
::
string
ModelChecksum
();
}
}
}
// namespace MACE_MODEL_TAG
}
// namespace mace
namespace
mace
{
namespace
benchmark
{
namespace
str_util
{
std
::
vector
<
std
::
string
>
Split
(
const
std
::
string
&
str
,
char
delims
)
{
...
...
@@ -64,8 +67,6 @@ bool SplitAndParseToInts(const std::string &str,
}
// namespace str_util
namespace
benchmark
{
void
ParseShape
(
const
std
::
string
&
str
,
std
::
vector
<
int64_t
>
*
shape
)
{
std
::
string
tmp
=
str
;
while
(
!
tmp
.
empty
())
{
...
...
@@ -96,18 +97,19 @@ inline int64_t NowMicros() {
bool
RunInference
(
MaceEngine
*
engine
,
const
std
::
vector
<
mace
::
MaceInputInfo
>
&
input_infos
,
std
::
map
<
std
::
string
,
float
*>
&
output_infos
,
std
::
map
<
std
::
string
,
float
*>
*
output_infos
,
StatSummarizer
*
summarizer
,
int64_t
*
inference_time_us
)
{
MACE_CHECK_NOTNULL
(
output_infos
);
RunMetadata
run_metadata
;
RunMetadata
*
run_metadata_ptr
=
nullptr
;
if
(
summarizer
)
{
run_metadata_ptr
=
&
run_metadata
;
}
if
(
input_infos
.
size
()
==
1
&&
output_infos
.
size
()
==
1
)
{
if
(
input_infos
.
size
()
==
1
&&
output_infos
->
size
()
==
1
)
{
const
int64_t
start_time
=
NowMicros
();
bool
s
=
engine
->
Run
(
input_infos
[
0
].
data
,
input_infos
[
0
].
shape
,
output_infos
.
begin
()
->
second
,
run_metadata_ptr
);
output_infos
->
begin
()
->
second
,
run_metadata_ptr
);
const
int64_t
end_time
=
NowMicros
();
if
(
!
s
)
{
...
...
@@ -117,7 +119,7 @@ bool RunInference(MaceEngine *engine,
*
inference_time_us
=
end_time
-
start_time
;
}
else
{
const
int64_t
start_time
=
NowMicros
();
bool
s
=
engine
->
Run
(
input_infos
,
output_infos
,
run_metadata_ptr
);
bool
s
=
engine
->
Run
(
input_infos
,
*
output_infos
,
run_metadata_ptr
);
const
int64_t
end_time
=
NowMicros
();
if
(
!
s
)
{
...
...
@@ -136,13 +138,14 @@ bool RunInference(MaceEngine *engine,
bool
Run
(
MaceEngine
*
engine
,
const
std
::
vector
<
mace
::
MaceInputInfo
>
&
input_infos
,
std
::
map
<
std
::
string
,
float
*>
&
output_infos
,
std
::
map
<
std
::
string
,
float
*>
*
output_infos
,
StatSummarizer
*
summarizer
,
int
num_runs
,
double
max_time_sec
,
int64_t
sleep_sec
,
int64_t
*
total_time_us
,
int64_t
*
actual_num_runs
)
{
MACE_CHECK_NOTNULL
(
output_infos
);
*
total_time_us
=
0
;
LOG
(
INFO
)
<<
"Running benchmark for max "
<<
num_runs
<<
" iterators, max "
...
...
@@ -156,7 +159,8 @@ bool Run(MaceEngine *engine,
bool
util_max_time
=
(
num_runs
<=
0
);
for
(
int
i
=
0
;
util_max_time
||
i
<
num_runs
;
++
i
)
{
int64_t
inference_time_us
=
0
;
bool
s
=
RunInference
(
engine
,
input_infos
,
output_infos
,
summarizer
,
&
inference_time_us
);
bool
s
=
RunInference
(
engine
,
input_infos
,
output_infos
,
summarizer
,
&
inference_time_us
);
stat
.
UpdateStat
(
inference_time_us
);
(
*
total_time_us
)
+=
inference_time_us
;
++
(
*
actual_num_runs
);
...
...
@@ -183,15 +187,18 @@ bool Run(MaceEngine *engine,
}
DEFINE_string
(
device
,
"CPU"
,
"Device [CPU|OPENCL]"
);
DEFINE_string
(
input_node
,
"input_node0,input_node1"
,
"input nodes, separated by comma"
);
DEFINE_string
(
output_node
,
"output_node0,output_node1"
,
"output nodes, separated by comma"
);
DEFINE_string
(
input_node
,
"input_node0,input_node1"
,
"input nodes, separated by comma"
);
DEFINE_string
(
output_node
,
"output_node0,output_node1"
,
"output nodes, separated by comma"
);
DEFINE_string
(
input_shape
,
""
,
"input shape, separated by colon and comma"
);
DEFINE_string
(
output_shape
,
""
,
"output shape, separated by colon and comma"
);
DEFINE_string
(
input_file
,
""
,
"input file name"
);
DEFINE_int32
(
max_num_runs
,
100
,
"number of runs max"
);
DEFINE_string
(
max_time
,
"10.0"
,
"length to run max"
);
DEFINE_string
(
inference_delay
,
"-1"
,
"delay between runs in seconds"
);
DEFINE_string
(
inter_benchmark_delay
,
"-1"
,
"delay between benchmarks in seconds"
);
DEFINE_string
(
inter_benchmark_delay
,
"-1"
,
"delay between benchmarks in seconds"
);
DEFINE_string
(
benchmark_name
,
""
,
"benchmark name"
);
DEFINE_bool
(
show_run_order
,
true
,
"whether to list stats by run order"
);
DEFINE_int32
(
run_order_limit
,
0
,
"how many items to show by run order"
);
...
...
@@ -203,15 +210,18 @@ DEFINE_bool(show_type, true, "whether to list stats by op type");
DEFINE_bool
(
show_summary
,
true
,
"whether to show a summary of the stats"
);
DEFINE_bool
(
show_flops
,
true
,
"whether to estimate the model's FLOPs"
);
DEFINE_int32
(
warmup_runs
,
1
,
"how many runs to initialize model"
);
DEFINE_string
(
model_data_file
,
""
,
"model data file name, used when EMBED_MODEL_DATA set to 0"
);
DEFINE_string
(
model_data_file
,
""
,
"model data file name, used when EMBED_MODEL_DATA set to 0"
);
DEFINE_string
(
gpu_type
,
"ADRENO"
,
"ADRENO/MALI"
);
DEFINE_int32
(
gpu_perf_hint
,
2
,
"0:DEFAULT/1:LOW/2:NORMAL/3:HIGH"
);
DEFINE_int32
(
gpu_priority_hint
,
1
,
"0:DEFAULT/1:LOW/2:NORMAL/3:HIGH"
);
DEFINE_int32
(
omp_num_threads
,
8
,
"num of openmp threads"
);
DEFINE_int32
(
cpu_power_option
,
0
,
"0:DEFAULT/1:HIGH_PERFORMANCE/2:BATTERY_SAVE"
);
DEFINE_int32
(
cpu_power_option
,
0
,
"0:DEFAULT/1:HIGH_PERFORMANCE/2:BATTERY_SAVE"
);
int
Main
(
int
argc
,
char
**
argv
)
{
MACE_CHECK
(
FLAGS_device
!=
"HEXAGON"
,
"Model benchmark tool do not support DSP."
);
MACE_CHECK
(
FLAGS_device
!=
"HEXAGON"
,
"Model benchmark tool do not support DSP."
);
gflags
::
SetUsageMessage
(
"some usage message"
);
gflags
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
...
...
@@ -228,12 +238,14 @@ int Main(int argc, char **argv) {
LOG
(
INFO
)
<<
"output shapes: ["
<<
FLAGS_output_shape
<<
"]"
;
LOG
(
INFO
)
<<
"Warmup runs: ["
<<
FLAGS_warmup_runs
<<
"]"
;
LOG
(
INFO
)
<<
"Num runs: ["
<<
FLAGS_max_num_runs
<<
"]"
;
LOG
(
INFO
)
<<
"Inter-inference delay (seconds): ["
<<
FLAGS_inference_delay
<<
"]"
;
LOG
(
INFO
)
<<
"Inter-benchmark delay (seconds): ["
<<
FLAGS_inter_benchmark_delay
<<
"]"
;
LOG
(
INFO
)
<<
"Inter-inference delay (seconds): ["
<<
FLAGS_inference_delay
<<
"]"
;
LOG
(
INFO
)
<<
"Inter-benchmark delay (seconds): ["
<<
FLAGS_inter_benchmark_delay
<<
"]"
;
const
long
in
t
inter_inference_sleep_seconds
=
const
int64_
t
inter_inference_sleep_seconds
=
std
::
strtol
(
FLAGS_inference_delay
.
c_str
(),
nullptr
,
10
);
const
long
in
t
inter_benchmark_sleep_seconds
=
const
int64_
t
inter_benchmark_sleep_seconds
=
std
::
strtol
(
FLAGS_inter_benchmark_delay
.
c_str
(),
nullptr
,
10
);
const
double
max_benchmark_time_seconds
=
std
::
strtod
(
FLAGS_max_time
.
c_str
(),
nullptr
);
...
...
@@ -252,7 +264,7 @@ int Main(int argc, char **argv) {
stats
.
reset
(
new
StatSummarizer
(
stats_options
));
DeviceType
device_type
=
CPU
;
if
(
FLAGS_device
==
"OPENCL"
)
{
if
(
FLAGS_device
==
"OPENCL"
)
{
device_type
=
OPENCL
;
}
...
...
@@ -264,17 +276,20 @@ int Main(int argc, char **argv) {
gpu_type
,
static_cast
<
GPUPerfHint
>
(
FLAGS_gpu_perf_hint
),
static_cast
<
GPUPriorityHint
>
(
FLAGS_gpu_priority_hint
));
}
else
if
(
device_type
==
CPU
)
{
}
else
if
(
device_type
==
CPU
)
{
mace
::
ConfigOmpThreadsAndAffinity
(
FLAGS_omp_num_threads
,
static_cast
<
CPUPowerOption
>
(
FLAGS_cpu_power_option
));
}
std
::
vector
<
std
::
string
>
input_names
=
str_util
::
Split
(
FLAGS_input_node
,
','
);
std
::
vector
<
std
::
string
>
output_names
=
str_util
::
Split
(
FLAGS_output_node
,
','
);
std
::
vector
<
std
::
string
>
input_shapes
=
str_util
::
Split
(
FLAGS_input_shape
,
':'
);
std
::
vector
<
std
::
string
>
output_shapes
=
str_util
::
Split
(
FLAGS_output_shape
,
':'
);
std
::
vector
<
std
::
string
>
input_names
=
str_util
::
Split
(
FLAGS_input_node
,
','
);
std
::
vector
<
std
::
string
>
output_names
=
str_util
::
Split
(
FLAGS_output_node
,
','
);
std
::
vector
<
std
::
string
>
input_shapes
=
str_util
::
Split
(
FLAGS_input_shape
,
':'
);
std
::
vector
<
std
::
string
>
output_shapes
=
str_util
::
Split
(
FLAGS_output_shape
,
':'
);
const
size_t
input_count
=
input_shapes
.
size
();
const
size_t
output_count
=
output_shapes
.
size
();
...
...
@@ -298,10 +313,12 @@ int Main(int argc, char **argv) {
for
(
size_t
i
=
0
;
i
<
input_count
;
++
i
)
{
int64_t
input_size
=
std
::
accumulate
(
input_shape_vec
[
i
].
begin
(),
input_shape_vec
[
i
].
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
input_shape_vec
[
i
].
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
input_datas
[
i
].
reset
(
new
float
[
input_size
]);
// load input
std
::
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
input_names
[
i
]),
std
::
ios
::
in
|
std
::
ios
::
binary
);
std
::
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
input_names
[
i
]),
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
in_file
.
is_open
())
{
in_file
.
read
(
reinterpret_cast
<
char
*>
(
input_datas
[
i
].
get
()),
input_size
*
sizeof
(
float
));
...
...
@@ -317,7 +334,8 @@ int Main(int argc, char **argv) {
}
for
(
size_t
i
=
0
;
i
<
output_count
;
++
i
)
{
int64_t
output_size
=
std
::
accumulate
(
output_shape_vec
[
i
].
begin
(),
output_shape_vec
[
i
].
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
output_shape_vec
[
i
].
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
output_datas
[
i
].
reset
(
new
float
[
output_size
]);
output_infos
[
output_names
[
i
]]
=
output_datas
[
i
].
get
();
}
...
...
@@ -328,7 +346,8 @@ int Main(int argc, char **argv) {
if
(
input_count
==
1
&&
output_count
==
1
)
{
engine_ptr
.
reset
(
new
mace
::
MaceEngine
(
&
net_def
,
device_type
));
}
else
{
engine_ptr
.
reset
(
new
mace
::
MaceEngine
(
&
net_def
,
device_type
,
input_names
,
output_names
));
engine_ptr
.
reset
(
new
mace
::
MaceEngine
(
&
net_def
,
device_type
,
input_names
,
output_names
));
}
if
(
device_type
==
DeviceType
::
OPENCL
)
{
mace
::
MACE_MODEL_TAG
::
UnloadModelData
(
model_data
);
...
...
@@ -340,7 +359,8 @@ int Main(int argc, char **argv) {
int64_t
num_warmup_runs
=
0
;
if
(
FLAGS_warmup_runs
>
0
)
{
bool
status
=
Run
(
engine_ptr
.
get
(),
input_infos
,
output_infos
,
nullptr
,
FLAGS_warmup_runs
,
-
1.0
,
Run
(
engine_ptr
.
get
(),
input_infos
,
&
output_infos
,
nullptr
,
FLAGS_warmup_runs
,
-
1.0
,
inter_inference_sleep_seconds
,
&
warmup_time_us
,
&
num_warmup_runs
);
if
(
!
status
)
{
LOG
(
ERROR
)
<<
"Failed at warm up run"
;
...
...
@@ -354,7 +374,7 @@ int Main(int argc, char **argv) {
int64_t
no_stat_time_us
=
0
;
int64_t
no_stat_runs
=
0
;
bool
status
=
Run
(
engine_ptr
.
get
(),
input_infos
,
output_infos
,
Run
(
engine_ptr
.
get
(),
input_infos
,
&
output_infos
,
nullptr
,
FLAGS_max_num_runs
,
max_benchmark_time_seconds
,
inter_inference_sleep_seconds
,
&
no_stat_time_us
,
&
no_stat_runs
);
if
(
!
status
)
{
...
...
@@ -363,7 +383,7 @@ int Main(int argc, char **argv) {
int64_t
stat_time_us
=
0
;
int64_t
stat_runs
=
0
;
status
=
Run
(
engine_ptr
.
get
(),
input_infos
,
output_infos
,
status
=
Run
(
engine_ptr
.
get
(),
input_infos
,
&
output_infos
,
stats
.
get
(),
FLAGS_max_num_runs
,
max_benchmark_time_seconds
,
inter_inference_sleep_seconds
,
&
stat_time_us
,
&
stat_runs
);
if
(
!
status
)
{
...
...
@@ -372,8 +392,8 @@ int Main(int argc, char **argv) {
LOG
(
INFO
)
<<
"Average inference timings in us: "
<<
"Warmup: "
<<
(
FLAGS_warmup_runs
>
0
?
warmup_time_us
/
FLAGS_warmup_runs
:
0
)
<<
", "
<<
"no stats: "
<<
no_stat_time_us
/
no_stat_runs
<<
", "
<<
(
FLAGS_warmup_runs
>
0
?
warmup_time_us
/
FLAGS_warmup_runs
:
0
)
<<
"
, "
<<
"
no stats: "
<<
no_stat_time_us
/
no_stat_runs
<<
", "
<<
"with stats: "
<<
stat_time_us
/
stat_runs
;
stats
->
PrintOperatorStats
();
...
...
@@ -381,7 +401,7 @@ int Main(int argc, char **argv) {
return
0
;
}
}
//
namespace benchmark
}
//
namespace mace
}
// namespace benchmark
}
// namespace mace
int
main
(
int
argc
,
char
**
argv
)
{
mace
::
benchmark
::
Main
(
argc
,
argv
);
}
mace/benchmark/model_throughput_test.cc
浏览文件 @
af787702
...
...
@@ -19,16 +19,13 @@
#include <fstream>
#include <iostream>
#include <numeric>
#include <thread>
#include <thread>
// NOLINT(build/c++11)
#include "gflags/gflags.h"
#include "mace/public/mace.h"
#include "mace/utils/env_time.h"
#include "mace/utils/logging.h"
using
namespace
std
;
using
namespace
mace
;
namespace
mace
{
#ifdef MACE_CPU_MODEL_TAG
...
...
@@ -73,15 +70,15 @@ extern const std::string ModelChecksum();
}
// namespace MACE_DSP_MODEL_TAG
#endif
}
// namespace mace
namespace
benchmark
{
void
ParseShape
(
const
st
ring
&
str
,
vector
<
int64_t
>
*
shape
)
{
string
tmp
=
str
;
void
ParseShape
(
const
st
d
::
string
&
str
,
std
::
vector
<
int64_t
>
*
shape
)
{
st
d
::
st
ring
tmp
=
str
;
while
(
!
tmp
.
empty
())
{
int
dim
=
atoi
(
tmp
.
data
());
shape
->
push_back
(
dim
);
size_t
next_offset
=
tmp
.
find
(
","
);
if
(
next_offset
==
string
::
npos
)
{
if
(
next_offset
==
st
d
::
st
ring
::
npos
)
{
break
;
}
else
{
tmp
=
tmp
.
substr
(
next_offset
+
1
);
...
...
@@ -89,7 +86,7 @@ void ParseShape(const string &str, vector<int64_t> *shape) {
}
}
DeviceType
ParseDeviceType
(
const
string
&
device_str
)
{
DeviceType
ParseDeviceType
(
const
st
d
::
st
ring
&
device_str
)
{
if
(
device_str
.
compare
(
"CPU"
)
==
0
)
{
return
DeviceType
::
CPU
;
}
else
if
(
device_str
.
compare
(
"NEON"
)
==
0
)
{
...
...
@@ -111,20 +108,23 @@ DEFINE_string(gpu_model_data_file, "", "gpu model data file name");
DEFINE_string
(
dsp_model_data_file
,
""
,
"dsp model data file name"
);
DEFINE_int32
(
run_seconds
,
10
,
"run seconds"
);
int
m
ain
(
int
argc
,
char
**
argv
)
{
int
M
ain
(
int
argc
,
char
**
argv
)
{
gflags
::
SetUsageMessage
(
"some usage message"
);
gflags
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
LOG
(
INFO
)
<<
"mace version: "
<<
MaceVersion
();
LOG
(
INFO
)
<<
"mace git version: "
<<
MaceGitVersion
();
#ifdef MACE_CPU_MODEL_TAG
LOG
(
INFO
)
<<
"cpu model checksum: "
<<
mace
::
MACE_CPU_MODEL_TAG
::
ModelChecksum
();
LOG
(
INFO
)
<<
"cpu model checksum: "
<<
mace
::
MACE_CPU_MODEL_TAG
::
ModelChecksum
();
#endif
#ifdef MACE_GPU_MODEL_TAG
LOG
(
INFO
)
<<
"gpu model checksum: "
<<
mace
::
MACE_GPU_MODEL_TAG
::
ModelChecksum
();
LOG
(
INFO
)
<<
"gpu model checksum: "
<<
mace
::
MACE_GPU_MODEL_TAG
::
ModelChecksum
();
#endif
#ifdef MACE_DSP_MODEL_TAG
LOG
(
INFO
)
<<
"dsp model checksum: "
<<
mace
::
MACE_DSP_MODEL_TAG
::
ModelChecksum
();
LOG
(
INFO
)
<<
"dsp model checksum: "
<<
mace
::
MACE_DSP_MODEL_TAG
::
ModelChecksum
();
#endif
LOG
(
INFO
)
<<
"input_shape: "
<<
FLAGS_input_shape
;
LOG
(
INFO
)
<<
"output_shape: "
<<
FLAGS_output_shape
;
...
...
@@ -134,8 +134,8 @@ int main(int argc, char **argv) {
LOG
(
INFO
)
<<
"dsp_model_data_file: "
<<
FLAGS_dsp_model_data_file
;
LOG
(
INFO
)
<<
"run_seconds: "
<<
FLAGS_run_seconds
;
vector
<
int64_t
>
input_shape_vec
;
vector
<
int64_t
>
output_shape_vec
;
std
::
vector
<
int64_t
>
input_shape_vec
;
std
::
vector
<
int64_t
>
output_shape_vec
;
ParseShape
(
FLAGS_input_shape
,
&
input_shape_vec
);
ParseShape
(
FLAGS_output_shape
,
&
output_shape_vec
);
...
...
@@ -151,7 +151,7 @@ int main(int argc, char **argv) {
std
::
unique_ptr
<
float
[]
>
dsp_output_data
(
new
float
[
output_size
]);
// load input
ifstream
in_file
(
FLAGS_input_file
,
ios
::
in
|
ios
::
binary
);
std
::
ifstream
in_file
(
FLAGS_input_file
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
in_file
.
is_open
())
{
in_file
.
read
(
reinterpret_cast
<
char
*>
(
input_data
.
get
()),
input_size
*
sizeof
(
float
));
...
...
@@ -166,7 +166,8 @@ int main(int argc, char **argv) {
/* --------------------- CPU init ----------------------- */
LOG
(
INFO
)
<<
"Load & init cpu model and warm up"
;
const
unsigned
char
*
cpu_model_data
=
mace
::
MACE_CPU_MODEL_TAG
::
LoadModelData
(
FLAGS_cpu_model_data_file
.
c_str
());
mace
::
MACE_CPU_MODEL_TAG
::
LoadModelData
(
FLAGS_cpu_model_data_file
.
c_str
());
NetDef
cpu_net_def
=
mace
::
MACE_CPU_MODEL_TAG
::
CreateNet
(
cpu_model_data
);
mace
::
MaceEngine
cpu_engine
(
&
cpu_net_def
,
DeviceType
::
CPU
);
...
...
@@ -182,7 +183,8 @@ int main(int argc, char **argv) {
/* --------------------- GPU init ----------------------- */
LOG
(
INFO
)
<<
"Load & init gpu model and warm up"
;
const
unsigned
char
*
gpu_model_data
=
mace
::
MACE_GPU_MODEL_TAG
::
LoadModelData
(
FLAGS_gpu_model_data_file
.
c_str
());
mace
::
MACE_GPU_MODEL_TAG
::
LoadModelData
(
FLAGS_gpu_model_data_file
.
c_str
());
NetDef
gpu_net_def
=
mace
::
MACE_GPU_MODEL_TAG
::
CreateNet
(
gpu_model_data
);
mace
::
MaceEngine
gpu_engine
(
&
gpu_net_def
,
DeviceType
::
OPENCL
);
...
...
@@ -199,7 +201,8 @@ int main(int argc, char **argv) {
/* --------------------- DSP init ----------------------- */
LOG
(
INFO
)
<<
"Load & init dsp model and warm up"
;
const
unsigned
char
*
dsp_model_data
=
mace
::
MACE_DSP_MODEL_TAG
::
LoadModelData
(
FLAGS_gpu_model_data_file
.
c_str
());
mace
::
MACE_DSP_MODEL_TAG
::
LoadModelData
(
FLAGS_gpu_model_data_file
.
c_str
());
NetDef
dsp_net_def
=
mace
::
MACE_DSP_MODEL_TAG
::
CreateNet
(
dsp_model_data
);
mace
::
MaceEngine
dsp_engine
(
&
dsp_net_def
,
DeviceType
::
HEXAGON
);
...
...
@@ -278,4 +281,11 @@ int main(int argc, char **argv) {
#endif
LOG
(
INFO
)
<<
"Total throughput: "
<<
total_throughput
<<
" f/s"
;
return
0
;
}
}
// namespace benchmark
}
// namespace mace
int
main
(
int
argc
,
char
**
argv
)
{
mace
::
benchmark
::
Main
(
argc
,
argv
);
}
mace/benchmark/stat_summarizer.cc
浏览文件 @
af787702
...
...
@@ -3,14 +3,18 @@
//
#include "mace/benchmark/stat_summarizer.h"
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
#include <iomanip>
#include <queue>
#include <iostream>
#include <queue>
#include <utility>
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
namespace
mace
{
namespace
benchmark
{
StatSummarizer
::
StatSummarizer
(
const
StatSummarizerOptions
&
options
)
:
options_
(
options
)
{}
...
...
@@ -90,7 +94,7 @@ std::string StatSummarizer::HeaderString(const std::string &title) const {
stream
<<
"============================== "
<<
title
<<
" =============================="
<<
std
::
endl
;
InitField
(
stream
,
1
4
)
<<
"[node type]"
;
InitField
(
stream
,
2
4
)
<<
"[node type]"
;
InitField
(
stream
,
9
)
<<
"[start]"
;
InitField
(
stream
,
9
)
<<
"[first]"
;
InitField
(
stream
,
9
)
<<
"[avg ms]"
;
...
...
@@ -114,7 +118,7 @@ std::string StatSummarizer::ColumnString(const StatSummarizer::Detail &detail,
const
int64_t
times_called
=
detail
.
times_called
/
num_runs
();
std
::
stringstream
stream
;
InitField
(
stream
,
1
4
)
<<
detail
.
type
;
InitField
(
stream
,
2
4
)
<<
detail
.
type
;
InitField
(
stream
,
9
)
<<
start_ms
;
InitField
(
stream
,
9
)
<<
first_time_ms
;
InitField
(
stream
,
9
)
<<
avg_time_ms
;
...
...
@@ -224,7 +228,7 @@ std::string StatSummarizer::GetStatsByNodeType() const {
std
::
pair
<
std
::
string
,
int64_t
>
(
node_type
.
first
,
mem_used
));
}
InitField
(
stream
,
1
4
)
<<
"[Node type]"
;
InitField
(
stream
,
2
4
)
<<
"[Node type]"
;
InitField
(
stream
,
9
)
<<
"[count]"
;
InitField
(
stream
,
10
)
<<
"[avg ms]"
;
InitField
(
stream
,
11
)
<<
"[avg %]"
;
...
...
@@ -248,7 +252,7 @@ std::string StatSummarizer::GetStatsByNodeType() const {
((
entry
.
first
/
static_cast
<
float
>
(
accumulated_us
))
*
100.0
f
);
cdf
+=
percentage
;
InitField
(
stream
,
1
4
)
<<
node_type
;
InitField
(
stream
,
2
4
)
<<
node_type
;
InitField
(
stream
,
9
)
<<
node_type_map_count
[
node_type
];
InitField
(
stream
,
10
)
<<
time_per_run_ms
;
InitField
(
stream
,
10
)
<<
percentage
<<
"%"
;
...
...
@@ -317,4 +321,5 @@ void StatSummarizer::PrintOperatorStats() const {
}
}
}
// namespace benchmark
}
// namespace mace
mace/benchmark/stat_summarizer.h
浏览文件 @
af787702
...
...
@@ -2,10 +2,11 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_
TOOLS_
BENCHMARK_STAT_SUMMARIZER_H_
#define MACE_
TOOLS_
BENCHMARK_STAT_SUMMARIZER_H_
#ifndef MACE_BENCHMARK_STAT_SUMMARIZER_H_
#define MACE_BENCHMARK_STAT_SUMMARIZER_H_
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <map>
...
...
@@ -17,6 +18,8 @@ namespace mace {
class
RunMetadata
;
namespace
benchmark
{
template
<
typename
ValueType
,
typename
HighPrecisionValueType
=
double
>
class
Stat
{
public:
...
...
@@ -194,6 +197,7 @@ class StatSummarizer {
StatSummarizerOptions
options_
;
};
}
// namespace mace
}
// namespace benchmark
}
// namespace mace
#endif // MACE_
TOOLS_
BENCHMARK_STAT_SUMMARIZER_H_
#endif // MACE_BENCHMARK_STAT_SUMMARIZER_H_
mace/codegen/opencl/opencl_compiled_program.cc
浏览文件 @
af787702
...
...
@@ -13,4 +13,4 @@ namespace mace {
extern
const
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
char
>>
kCompiledProgramMap
=
{};
}
// namespace
}
// namespace
mace
mace/codegen/tuning/tuning_params.cc
浏览文件 @
af787702
...
...
@@ -13,4 +13,4 @@ namespace mace {
extern
const
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
int
>>
kTuningParamsData
=
{};
}
// namespace
}
// namespace
mace
mace/examples/mace_run.cc
浏览文件 @
af787702
...
...
@@ -16,8 +16,6 @@
*/
#include <malloc.h>
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
...
...
@@ -28,9 +26,6 @@
#include "mace/utils/env_time.h"
#include "mace/utils/logging.h"
using
namespace
std
;
using
namespace
mace
;
namespace
mace
{
namespace
MACE_MODEL_TAG
{
...
...
@@ -45,6 +40,8 @@ extern const std::string ModelChecksum();
}
// namespace MACE_MODEL_TAG
}
// namespace mace
namespace
mace
{
namespace
examples
{
namespace
str_util
{
...
...
@@ -65,13 +62,13 @@ std::vector<std::string> Split(const std::string &str, char delims) {
}
// namespace str_util
void
ParseShape
(
const
st
ring
&
str
,
vector
<
int64_t
>
*
shape
)
{
string
tmp
=
str
;
void
ParseShape
(
const
st
d
::
string
&
str
,
std
::
vector
<
int64_t
>
*
shape
)
{
st
d
::
st
ring
tmp
=
str
;
while
(
!
tmp
.
empty
())
{
int
dim
=
atoi
(
tmp
.
data
());
shape
->
push_back
(
dim
);
size_t
next_offset
=
tmp
.
find
(
","
);
if
(
next_offset
==
string
::
npos
)
{
if
(
next_offset
==
st
d
::
st
ring
::
npos
)
{
break
;
}
else
{
tmp
=
tmp
.
substr
(
next_offset
+
1
);
...
...
@@ -87,7 +84,7 @@ std::string FormatName(const std::string input) {
return
res
;
}
DeviceType
ParseDeviceType
(
const
string
&
device_str
)
{
DeviceType
ParseDeviceType
(
const
st
d
::
st
ring
&
device_str
)
{
if
(
device_str
.
compare
(
"CPU"
)
==
0
)
{
return
DeviceType
::
CPU
;
}
else
if
(
device_str
.
compare
(
"NEON"
)
==
0
)
{
...
...
@@ -101,7 +98,7 @@ DeviceType ParseDeviceType(const string &device_str) {
}
}
GPUType
ParseGPUType
(
const
string
&
gpu_type_str
)
{
GPUType
ParseGPUType
(
const
st
d
::
st
ring
&
gpu_type_str
)
{
if
(
gpu_type_str
.
compare
(
"ADRENO"
)
==
0
)
{
return
GPUType
::
ADRENO
;
}
else
if
(
gpu_type_str
.
compare
(
"MALI"
)
==
0
)
{
...
...
@@ -158,12 +155,18 @@ struct mallinfo LogMallinfoChange(struct mallinfo prev) {
return
curr
;
}
DEFINE_string
(
input_node
,
"input_node0,input_node1"
,
"input nodes, separated by comma"
);
DEFINE_string
(
input_shape
,
"1,224,224,3:1,1,1,10"
,
"input shapes, separated by colon and comma"
);
DEFINE_string
(
output_node
,
"output_node0,output_node1"
,
"output nodes, separated by comma"
);
DEFINE_string
(
output_shape
,
"1,224,224,2:1,1,1,10"
,
"output shapes, separated by colon and comma"
);
DEFINE_string
(
input_file
,
""
,
"input file name | input file prefix for multiple inputs."
);
DEFINE_string
(
output_file
,
""
,
"output file name | output file prefix for multiple outputs"
);
DEFINE_string
(
input_node
,
"input_node0,input_node1"
,
"input nodes, separated by comma"
);
DEFINE_string
(
input_shape
,
"1,224,224,3:1,1,1,10"
,
"input shapes, separated by colon and comma"
);
DEFINE_string
(
output_node
,
"output_node0,output_node1"
,
"output nodes, separated by comma"
);
DEFINE_string
(
output_shape
,
"1,224,224,2:1,1,1,10"
,
"output shapes, separated by colon and comma"
);
DEFINE_string
(
input_file
,
""
,
"input file name | input file prefix for multiple inputs."
);
DEFINE_string
(
output_file
,
""
,
"output file name | output file prefix for multiple outputs"
);
DEFINE_string
(
model_data_file
,
""
,
"model data file name, used when EMBED_MODEL_DATA set to 0"
);
DEFINE_string
(
device
,
"OPENCL"
,
"CPU/NEON/OPENCL/HEXAGON"
);
...
...
@@ -174,7 +177,8 @@ DEFINE_string(gpu_type, "ADRENO", "ADRENO/MALI");
DEFINE_int32
(
gpu_perf_hint
,
2
,
"0:DEFAULT/1:LOW/2:NORMAL/3:HIGH"
);
DEFINE_int32
(
gpu_priority_hint
,
1
,
"0:DEFAULT/1:LOW/2:NORMAL/3:HIGH"
);
DEFINE_int32
(
omp_num_threads
,
8
,
"num of openmp threads"
);
DEFINE_int32
(
cpu_power_option
,
0
,
"0:DEFAULT/1:HIGH_PERFORMANCE/2:BATTERY_SAVE"
);
DEFINE_int32
(
cpu_power_option
,
0
,
"0:DEFAULT/1:HIGH_PERFORMANCE/2:BATTERY_SAVE"
);
bool
SingleInputAndOutput
(
const
std
::
vector
<
int64_t
>
&
input_shape
,
const
std
::
vector
<
int64_t
>
&
output_shape
)
{
...
...
@@ -197,8 +201,7 @@ bool SingleInputAndOutput(const std::vector<int64_t> &input_shape,
gpu_type
,
static_cast
<
GPUPerfHint
>
(
FLAGS_gpu_perf_hint
),
static_cast
<
GPUPriorityHint
>
(
FLAGS_gpu_priority_hint
));
}
else
if
(
device_type
==
DeviceType
::
CPU
)
{
}
else
if
(
device_type
==
DeviceType
::
CPU
)
{
mace
::
ConfigOmpThreadsAndAffinity
(
FLAGS_omp_num_threads
,
static_cast
<
CPUPowerOption
>
(
FLAGS_cpu_power_option
));
...
...
@@ -227,7 +230,8 @@ bool SingleInputAndOutput(const std::vector<int64_t> &input_shape,
std
::
unique_ptr
<
float
[]
>
output_data
(
new
float
[
output_size
]);
// load input
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
FLAGS_input_node
),
ios
::
in
|
ios
::
binary
);
std
::
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
FLAGS_input_node
),
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
in_file
.
is_open
())
{
in_file
.
read
(
reinterpret_cast
<
char
*>
(
input_data
.
get
()),
input_size
*
sizeof
(
float
));
...
...
@@ -262,7 +266,7 @@ bool SingleInputAndOutput(const std::vector<int64_t> &input_shape,
if
(
output_data
!=
nullptr
)
{
std
::
string
output_name
=
FLAGS_output_file
+
"_"
+
FormatName
(
FLAGS_output_node
);
ofstream
out_file
(
output_name
,
ios
::
binary
);
std
::
ofstream
out_file
(
output_name
,
std
::
ios
::
binary
);
out_file
.
write
((
const
char
*
)
(
output_data
.
get
()),
output_size
*
sizeof
(
float
));
out_file
.
flush
();
...
...
@@ -279,10 +283,11 @@ bool SingleInputAndOutput(const std::vector<int64_t> &input_shape,
return
true
;
}
bool
MultipleInputOrOutput
(
const
std
::
vector
<
std
::
string
>
&
input_names
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>
&
input_shapes
,
const
std
::
vector
<
std
::
string
>
&
output_names
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>
&
output_shapes
)
{
bool
MultipleInputOrOutput
(
const
std
::
vector
<
std
::
string
>
&
input_names
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>
&
input_shapes
,
const
std
::
vector
<
std
::
string
>
&
output_names
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>
&
output_shapes
)
{
// load model
int64_t
t0
=
NowMicros
();
const
unsigned
char
*
model_data
=
...
...
@@ -302,8 +307,7 @@ bool MultipleInputOrOutput(const std::vector<std::string> &input_names,
gpu_type
,
static_cast
<
GPUPerfHint
>
(
FLAGS_gpu_perf_hint
),
static_cast
<
GPUPriorityHint
>
(
FLAGS_gpu_priority_hint
));
}
else
if
(
device_type
==
DeviceType
::
CPU
)
{
}
else
if
(
device_type
==
DeviceType
::
CPU
)
{
mace
::
ConfigOmpThreadsAndAffinity
(
FLAGS_omp_num_threads
,
static_cast
<
CPUPowerOption
>
(
FLAGS_cpu_power_option
));
...
...
@@ -333,7 +337,8 @@ bool MultipleInputOrOutput(const std::vector<std::string> &input_names,
std
::
multiplies
<
int64_t
>
());
input_datas
[
i
].
reset
(
new
float
[
input_size
]);
// load input
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
input_names
[
i
]),
ios
::
in
|
ios
::
binary
);
std
::
ifstream
in_file
(
FLAGS_input_file
+
"_"
+
FormatName
(
input_names
[
i
]),
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
in_file
.
is_open
())
{
in_file
.
read
(
reinterpret_cast
<
char
*>
(
input_datas
[
i
].
get
()),
input_size
*
sizeof
(
float
));
...
...
@@ -377,8 +382,9 @@ bool MultipleInputOrOutput(const std::vector<std::string> &input_names,
}
for
(
size_t
i
=
0
;
i
<
output_count
;
++
i
)
{
std
::
string
output_name
=
FLAGS_output_file
+
"_"
+
FormatName
(
output_names
[
i
]);
ofstream
out_file
(
output_name
,
ios
::
binary
);
std
::
string
output_name
=
FLAGS_output_file
+
"_"
+
FormatName
(
output_names
[
i
]);
std
::
ofstream
out_file
(
output_name
,
std
::
ios
::
binary
);
int64_t
output_size
=
std
::
accumulate
(
output_shapes
[
i
].
begin
(),
output_shapes
[
i
].
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
...
...
@@ -395,7 +401,7 @@ bool MultipleInputOrOutput(const std::vector<std::string> &input_names,
return
true
;
}
int
m
ain
(
int
argc
,
char
**
argv
)
{
int
M
ain
(
int
argc
,
char
**
argv
)
{
gflags
::
SetUsageMessage
(
"some usage message"
);
gflags
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
...
...
@@ -419,14 +425,17 @@ int main(int argc, char **argv) {
LOG
(
INFO
)
<<
"cpu_power_option: "
<<
FLAGS_cpu_power_option
;
std
::
vector
<
std
::
string
>
input_names
=
str_util
::
Split
(
FLAGS_input_node
,
','
);
std
::
vector
<
std
::
string
>
output_names
=
str_util
::
Split
(
FLAGS_output_node
,
','
);
std
::
vector
<
std
::
string
>
input_shapes
=
str_util
::
Split
(
FLAGS_input_shape
,
':'
);
std
::
vector
<
std
::
string
>
output_shapes
=
str_util
::
Split
(
FLAGS_output_shape
,
':'
);
std
::
vector
<
std
::
string
>
output_names
=
str_util
::
Split
(
FLAGS_output_node
,
','
);
std
::
vector
<
std
::
string
>
input_shapes
=
str_util
::
Split
(
FLAGS_input_shape
,
':'
);
std
::
vector
<
std
::
string
>
output_shapes
=
str_util
::
Split
(
FLAGS_output_shape
,
':'
);
const
size_t
input_count
=
input_shapes
.
size
();
const
size_t
output_count
=
output_shapes
.
size
();
std
::
vector
<
vector
<
int64_t
>>
input_shape_vec
(
input_count
);
std
::
vector
<
vector
<
int64_t
>>
output_shape_vec
(
output_count
);
std
::
vector
<
std
::
vector
<
int64_t
>>
input_shape_vec
(
input_count
);
std
::
vector
<
std
::
vector
<
int64_t
>>
output_shape_vec
(
output_count
);
for
(
size_t
i
=
0
;
i
<
input_count
;
++
i
)
{
ParseShape
(
input_shapes
[
i
],
&
input_shape_vec
[
i
]);
}
...
...
@@ -447,9 +456,14 @@ int main(int argc, char **argv) {
output_shape_vec
);
}
}
if
(
ret
)
{
if
(
ret
)
{
return
0
;
}
else
{
return
-
1
;
}
}
}
// namespace examples
}
// namespace mace
int
main
(
int
argc
,
char
**
argv
)
{
mace
::
examples
::
Main
(
argc
,
argv
);
}
mace/public/mace.h
浏览文件 @
af787702
...
...
@@ -2,8 +2,8 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_
CORE
_MACE_H_
#define MACE_
CORE
_MACE_H_
#ifndef MACE_
PUBLIC
_MACE_H_
#define MACE_
PUBLIC
_MACE_H_
#include <cstdint>
#include <map>
...
...
@@ -169,7 +169,7 @@ class NodeInput {
class
OutputShape
{
public:
OutputShape
();
OutputShape
(
const
std
::
vector
<
int64_t
>
&
dims
);
OutputShape
(
const
std
::
vector
<
int64_t
>
&
dims
);
// NOLINT(runtime/explicit)
void
CopyFrom
(
const
OutputShape
&
from
);
public:
...
...
@@ -409,9 +409,10 @@ class MaceEngine {
float
*
output
,
RunMetadata
*
run_metadata
);
// Multiple input or output
bool
Run
(
const
std
::
vector
<
MaceInputInfo
>
&
input
,
std
::
map
<
std
::
string
,
float
*>
&
output
,
RunMetadata
*
run_metadata
=
nullptr
);
bool
Run
(
const
std
::
vector
<
MaceInputInfo
>
&
input
,
std
::
map
<
std
::
string
,
float
*>
&
output
,
// NOLINT(runtime/references)
RunMetadata
*
run_metadata
=
nullptr
);
MaceEngine
(
const
MaceEngine
&
)
=
delete
;
MaceEngine
&
operator
=
(
const
MaceEngine
&
)
=
delete
;
...
...
@@ -425,4 +426,4 @@ class MaceEngine {
}
// namespace mace
#endif // MACE_
CORE
_MACE_H_
#endif // MACE_
PUBLIC
_MACE_H_
mace/utils/command_line_flags.cc
浏览文件 @
af787702
...
...
@@ -3,32 +3,32 @@
//
#include "mace/utils/command_line_flags.h"
#include "mace/utils/logging.h"
#include <cstring>
#include <iomanip>
namespace
mace
{
namespace
{
#include "mace/utils/logging.h"
using
namespace
std
;
namespace
mace
{
namespace
utils
{
bool
StringConsume
(
string
&
arg
,
const
string
&
x
)
{
if
((
arg
.
size
()
>=
x
.
size
())
&&
(
memcmp
(
arg
.
data
(),
x
.
data
(),
x
.
size
())
==
0
))
{
arg
=
arg
.
substr
(
x
.
size
());
bool
StringConsume
(
const
std
::
string
&
x
,
std
::
string
*
arg
)
{
MACE_CHECK_NOTNULL
(
arg
);
if
((
arg
->
size
()
>=
x
.
size
())
&&
(
memcmp
(
arg
->
data
(),
x
.
data
(),
x
.
size
())
==
0
))
{
*
arg
=
arg
->
substr
(
x
.
size
());
return
true
;
}
return
false
;
}
bool
ParseStringFlag
(
string
arg
,
string
flag
,
string
*
dst
,
bool
ParseStringFlag
(
st
d
::
st
ring
arg
,
st
d
::
st
ring
flag
,
st
d
::
st
ring
*
dst
,
bool
*
value_parsing_ok
)
{
*
value_parsing_ok
=
true
;
if
(
StringConsume
(
arg
,
"--"
)
&&
StringConsume
(
arg
,
fla
g
)
&&
StringConsume
(
arg
,
"="
))
{
if
(
StringConsume
(
"--"
,
&
arg
)
&&
StringConsume
(
flag
,
&
ar
g
)
&&
StringConsume
(
"="
,
&
arg
))
{
*
dst
=
arg
;
return
true
;
}
...
...
@@ -36,13 +36,13 @@ bool ParseStringFlag(string arg,
return
false
;
}
bool
ParseInt32Flag
(
string
arg
,
string
flag
,
bool
ParseInt32Flag
(
st
d
::
st
ring
arg
,
st
d
::
st
ring
flag
,
int32_t
*
dst
,
bool
*
value_parsing_ok
)
{
*
value_parsing_ok
=
true
;
if
(
StringConsume
(
arg
,
"--"
)
&&
StringConsume
(
arg
,
fla
g
)
&&
StringConsume
(
arg
,
"="
))
{
if
(
StringConsume
(
"--"
,
&
arg
)
&&
StringConsume
(
flag
,
&
ar
g
)
&&
StringConsume
(
"="
,
&
arg
))
{
char
extra
;
if
(
sscanf
(
arg
.
data
(),
"%d%c"
,
dst
,
&
extra
)
!=
1
)
{
LOG
(
ERROR
)
<<
"Couldn't interpret value "
<<
arg
<<
" for flag "
<<
flag
...
...
@@ -55,13 +55,13 @@ bool ParseInt32Flag(string arg,
return
false
;
}
bool
ParseInt64Flag
(
string
arg
,
string
flag
,
long
long
*
dst
,
bool
ParseInt64Flag
(
st
d
::
st
ring
arg
,
st
d
::
st
ring
flag
,
int64_t
*
dst
,
bool
*
value_parsing_ok
)
{
*
value_parsing_ok
=
true
;
if
(
StringConsume
(
arg
,
"--"
)
&&
StringConsume
(
arg
,
fla
g
)
&&
StringConsume
(
arg
,
"="
))
{
if
(
StringConsume
(
"--"
,
&
arg
)
&&
StringConsume
(
flag
,
&
ar
g
)
&&
StringConsume
(
"="
,
&
arg
))
{
char
extra
;
if
(
sscanf
(
arg
.
data
(),
"%lld%c"
,
dst
,
&
extra
)
!=
1
)
{
LOG
(
ERROR
)
<<
"Couldn't interpret value "
<<
arg
<<
" for flag "
<<
flag
...
...
@@ -74,9 +74,10 @@ bool ParseInt64Flag(string arg,
return
false
;
}
bool
ParseBoolFlag
(
string
arg
,
string
flag
,
bool
*
dst
,
bool
*
value_parsing_ok
)
{
bool
ParseBoolFlag
(
std
::
string
arg
,
std
::
string
flag
,
bool
*
dst
,
bool
*
value_parsing_ok
)
{
*
value_parsing_ok
=
true
;
if
(
StringConsume
(
arg
,
"--"
)
&&
StringConsume
(
arg
,
fla
g
))
{
if
(
StringConsume
(
"--"
,
&
arg
)
&&
StringConsume
(
flag
,
&
ar
g
))
{
if
(
arg
.
empty
())
{
*
dst
=
true
;
return
true
;
...
...
@@ -99,13 +100,13 @@ bool ParseBoolFlag(string arg, string flag, bool *dst, bool *value_parsing_ok) {
return
false
;
}
bool
ParseFloatFlag
(
string
arg
,
string
flag
,
bool
ParseFloatFlag
(
st
d
::
st
ring
arg
,
st
d
::
st
ring
flag
,
float
*
dst
,
bool
*
value_parsing_ok
)
{
*
value_parsing_ok
=
true
;
if
(
StringConsume
(
arg
,
"--"
)
&&
StringConsume
(
arg
,
fla
g
)
&&
StringConsume
(
arg
,
"="
))
{
if
(
StringConsume
(
"--"
,
&
arg
)
&&
StringConsume
(
flag
,
&
ar
g
)
&&
StringConsume
(
"="
,
&
arg
))
{
char
extra
;
if
(
sscanf
(
arg
.
data
(),
"%f%c"
,
dst
,
&
extra
)
!=
1
)
{
LOG
(
ERROR
)
<<
"Couldn't interpret value "
<<
arg
<<
" for flag "
<<
flag
...
...
@@ -118,47 +119,48 @@ bool ParseFloatFlag(string arg,
return
false
;
}
}
// namespace
}
// namespace
utils
Flag
::
Flag
(
const
char
*
name
,
int
*
dst
,
const
string
&
usage_text
)
Flag
::
Flag
(
const
char
*
name
,
int
*
dst
,
const
st
d
::
st
ring
&
usage_text
)
:
name_
(
name
),
type_
(
TYPE_INT
),
int_value_
(
dst
),
usage_text_
(
usage_text
)
{}
Flag
::
Flag
(
const
char
*
name
,
long
long
*
dst
,
const
string
&
usage_text
)
Flag
::
Flag
(
const
char
*
name
,
int64_t
*
dst
,
const
std
::
string
&
usage_text
)
:
name_
(
name
),
type_
(
TYPE_INT64
),
int64_value_
(
dst
),
usage_text_
(
usage_text
)
{}
Flag
::
Flag
(
const
char
*
name
,
bool
*
dst
,
const
string
&
usage_text
)
Flag
::
Flag
(
const
char
*
name
,
bool
*
dst
,
const
st
d
::
st
ring
&
usage_text
)
:
name_
(
name
),
type_
(
TYPE_BOOL
),
bool_value_
(
dst
),
usage_text_
(
usage_text
)
{}
Flag
::
Flag
(
const
char
*
name
,
st
ring
*
dst
,
const
string
&
usage_text
)
Flag
::
Flag
(
const
char
*
name
,
st
d
::
string
*
dst
,
const
std
::
string
&
usage_text
)
:
name_
(
name
),
type_
(
TYPE_STRING
),
string_value_
(
dst
),
usage_text_
(
usage_text
)
{}
Flag
::
Flag
(
const
char
*
name
,
float
*
dst
,
const
string
&
usage_text
)
Flag
::
Flag
(
const
char
*
name
,
float
*
dst
,
const
st
d
::
st
ring
&
usage_text
)
:
name_
(
name
),
type_
(
TYPE_FLOAT
),
float_value_
(
dst
),
usage_text_
(
usage_text
)
{}
bool
Flag
::
Parse
(
string
arg
,
bool
*
value_parsing_ok
)
const
{
bool
Flag
::
Parse
(
st
d
::
st
ring
arg
,
bool
*
value_parsing_ok
)
const
{
bool
result
=
false
;
if
(
type_
==
TYPE_INT
)
{
result
=
ParseInt32Flag
(
arg
,
name_
,
int_value_
,
value_parsing_ok
);
result
=
utils
::
ParseInt32Flag
(
arg
,
name_
,
int_value_
,
value_parsing_ok
);
}
else
if
(
type_
==
TYPE_INT64
)
{
result
=
ParseInt64Flag
(
arg
,
name_
,
int64_value_
,
value_parsing_ok
);
result
=
utils
::
ParseInt64Flag
(
arg
,
name_
,
int64_value_
,
value_parsing_ok
);
}
else
if
(
type_
==
TYPE_BOOL
)
{
result
=
ParseBoolFlag
(
arg
,
name_
,
bool_value_
,
value_parsing_ok
);
result
=
utils
::
ParseBoolFlag
(
arg
,
name_
,
bool_value_
,
value_parsing_ok
);
}
else
if
(
type_
==
TYPE_STRING
)
{
result
=
ParseStringFlag
(
arg
,
name_
,
string_value_
,
value_parsing_ok
);
result
=
utils
::
ParseStringFlag
(
arg
,
name_
,
string_value_
,
value_parsing_ok
);
}
else
if
(
type_
==
TYPE_FLOAT
)
{
result
=
ParseFloatFlag
(
arg
,
name_
,
float_value_
,
value_parsing_ok
);
result
=
utils
::
ParseFloatFlag
(
arg
,
name_
,
float_value_
,
value_parsing_ok
);
}
return
result
;
}
...
...
@@ -169,7 +171,7 @@ bool Flag::Parse(string arg, bool *value_parsing_ok) const {
bool
result
=
true
;
std
::
vector
<
char
*>
unknown_flags
;
for
(
int
i
=
1
;
i
<
*
argc
;
++
i
)
{
if
(
string
(
argv
[
i
])
==
"--"
)
{
if
(
st
d
::
st
ring
(
argv
[
i
])
==
"--"
)
{
while
(
i
<
*
argc
)
{
unknown_flags
.
push_back
(
argv
[
i
]);
++
i
;
...
...
@@ -202,8 +204,8 @@ bool Flag::Parse(string arg, bool *value_parsing_ok) const {
return
result
&&
(
*
argc
<
2
||
strcmp
(
argv
[
1
],
"--help"
)
!=
0
);
}
/*static*/
string
Flags
::
Usage
(
const
string
&
cmdline
,
const
std
::
vector
<
Flag
>
&
flag_list
)
{
std
::
string
Flags
::
Usage
(
const
std
::
string
&
cmdline
,
const
std
::
vector
<
Flag
>
&
flag_list
)
{
std
::
stringstream
usage_text
;
usage_text
<<
"usage: "
<<
cmdline
<<
std
::
endl
;
...
...
mace/utils/command_line_flags.h
浏览文件 @
af787702
...
...
@@ -2,8 +2,8 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_
CORE_COMMAND_LINE_FLAGS_H
#define MACE_
CORE_COMMAND_LINE_FLAGS_H
#ifndef MACE_
UTILS_COMMAND_LINE_FLAGS_H_
#define MACE_
UTILS_COMMAND_LINE_FLAGS_H_
#include <string>
#include <vector>
...
...
@@ -13,7 +13,7 @@ namespace mace {
class
Flag
{
public:
Flag
(
const
char
*
name
,
int
*
dst1
,
const
std
::
string
&
usage_text
);
Flag
(
const
char
*
name
,
long
long
*
dst1
,
const
std
::
string
&
usage_text
);
Flag
(
const
char
*
name
,
int64_t
*
dst1
,
const
std
::
string
&
usage_text
);
Flag
(
const
char
*
name
,
bool
*
dst
,
const
std
::
string
&
usage_text
);
Flag
(
const
char
*
name
,
std
::
string
*
dst
,
const
std
::
string
&
usage_text
);
Flag
(
const
char
*
name
,
float
*
dst
,
const
std
::
string
&
usage_text
);
...
...
@@ -26,7 +26,7 @@ class Flag {
std
::
string
name_
;
enum
{
TYPE_INT
,
TYPE_INT64
,
TYPE_BOOL
,
TYPE_STRING
,
TYPE_FLOAT
}
type_
;
int
*
int_value_
;
long
long
*
int64_value_
;
int64_t
*
int64_value_
;
bool
*
bool_value_
;
std
::
string
*
string_value_
;
float
*
float_value_
;
...
...
@@ -50,4 +50,4 @@ class Flags {
}
// namespace mace
#endif // MACE_
CORE_COMMAND_LINE_FLAGS_H
#endif // MACE_
UTILS_COMMAND_LINE_FLAGS_H_
mace/utils/env_time.h
浏览文件 @
af787702
...
...
@@ -2,8 +2,8 @@
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_UTILS_ENV_TIME_H
#define MACE_UTILS_ENV_TIME_H
#ifndef MACE_UTILS_ENV_TIME_H
_
#define MACE_UTILS_ENV_TIME_H
_
#include <stdint.h>
#include <sys/time.h>
...
...
@@ -19,4 +19,4 @@ inline int64_t NowMicros() {
}
// namespace mace
#endif // MACE_UTILS_ENV_TIME_H
#endif // MACE_UTILS_ENV_TIME_H
_
mace/utils/logging.h
浏览文件 @
af787702
...
...
@@ -9,6 +9,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <utility>
#include "mace/public/mace.h"
#include "mace/utils/env_time.h"
...
...
@@ -122,7 +123,7 @@ class LatencyLogger {
VLOG
(
vlog_level_
)
<<
message_
<<
" latency: "
<<
stop_micros
-
start_micros_
<<
" us"
;
}
}
;
}
private:
const
int
vlog_level_
;
...
...
mace/utils/memory_logging.h
浏览文件 @
af787702
...
...
@@ -6,13 +6,15 @@
#define MACE_UTILS_MEMORY_LOGGING_H_
#include <malloc.h>
#include <string>
#include "mace/utils/logging.h"
namespace
mace
{
class
MallinfoChangeLogger
{
public:
MallinfoChangeLogger
(
const
std
::
string
&
name
)
:
name_
(
name
)
{
explicit
MallinfoChangeLogger
(
const
std
::
string
&
name
)
:
name_
(
name
)
{
prev_
=
mallinfo
();
}
~
MallinfoChangeLogger
()
{
...
...
mace/utils/string_util.h
浏览文件 @
af787702
...
...
@@ -10,7 +10,7 @@
#include <vector>
namespace
mace
{
namespace
{
namespace
string_util
{
inline
void
MakeStringInternal
(
std
::
stringstream
&
/*ss*/
)
{}
...
...
@@ -27,12 +27,12 @@ inline void MakeStringInternal(std::stringstream &ss,
MakeStringInternal
(
ss
,
args
...);
}
}
// namespace
}
// namespace
string_util
template
<
typename
...
Args
>
std
::
string
MakeString
(
const
Args
&
...
args
)
{
std
::
stringstream
ss
;
MakeStringInternal
(
ss
,
args
...);
string_util
::
MakeStringInternal
(
ss
,
args
...);
return
ss
.
str
();
}
...
...
mace/utils/tuner.h
浏览文件 @
af787702
...
...
@@ -17,8 +17,6 @@
#include "mace/utils/timer.h"
#include "mace/utils/utils.h"
namespace
{}
// namespace
namespace
mace
{
extern
bool
GetTuningParams
(
...
...
@@ -127,7 +125,7 @@ class Tuner {
const
std
::
function
<
RetType
(
const
std
::
vector
<
param_type
>
&
,
Timer
*
,
std
::
vector
<
param_type
>
*
)
>
&
func
,
std
::
vector
<
param_type
>
&
params
,
const
std
::
vector
<
param_type
>
&
params
,
Timer
*
timer
,
int
num_runs
,
double
*
time_us
,
...
...
mace/utils/tuner_development.cc
浏览文件 @
af787702
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <fstream>
#include <map>
#include <string>
...
...
mace/utils/tuner_production.cc
浏览文件 @
af787702
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <map>
#include <string>
#include <unordered_map>
...
...
mace/utils/tuner_test.cc
浏览文件 @
af787702
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <thread>
#include <thread>
// NOLINT(build/c++11)
#include "gtest/gtest.h"
...
...
mace/utils/utils.h
浏览文件 @
af787702
...
...
@@ -7,6 +7,8 @@
#include <sys/time.h>
#include <sstream>
#include <string>
#include <utility>
namespace
mace
{
template
<
typename
Integer
>
...
...
mace/utils/utils_test.cc
浏览文件 @
af787702
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <thread>
#include <thread>
// NOLINT(build/c++11)
#include "gtest/gtest.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录