Skip to content

Commit ddcd08e

Browse files
committed
Improve portability and add Darwin support
1 parent 4866947 commit ddcd08e

File tree

151 files changed

+2044
-1022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+2044
-1022
lines changed

BUILD renamed to BUILD.bazel

File renamed without changes.

docs/development/how_to_debug.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ MACE also provides model visualization HTML generated in `builds` directory, gen
101101

102102
Debug engine using log
103103
--------------------------
104-
Mace defines two sorts of logs: one is for users (LOG), the other is for developers (VLOG).
104+
MACE implements a similar logging mechanism like `glog <https://github.com/google/glog>`__.
105+
There are two types of logs, LOG for normal logging and VLOG for debugging.
105106

106-
LOG includes four levels, i.e, ``INFO``, ``WARNING``, ``ERROR``, ``FATAL``;
107-
Environment variable ``MACE_CPP_MIN_LOG_LEVEL`` can be set to specify log level of users, e.g.,
108-
``set MACE_CPP_MIN_LOG_LEVEL=0`` will enable ``INFO`` log level, while ``set MACE_CPP_MIN_LOG_LEVEL=4`` will enable ``FATAL`` log level.
107+
LOG includes four levels, sorted by severity level: ``INFO``, ``WARNING``, ``ERROR``, ``FATAL``.
108+
The logging severity threshold can be configured via environment variable, e.g. ``MACE_CPP_MIN_LOG_LEVEL=WARNING`` to set as ``WARNING``.
109+
Only the log messages with equal or above the specified severity threshold will be printed, the default threshold is ``INFO``.
110+
We don't support integer log severity value like `glog <https://github.com/google/glog>`__, because they are confusing with VLOG.
109111

112+
VLOG is verbose logging which is logged as ``LOG(INFO)``. VLOG also has more detailed integer verbose levels, like 0, 1, 2, 3, etc.
113+
The threshold can be configured through environment variable, e.g. ``MACE_CPP_MIN_VLOG_LEVEL=2`` to set as ``2``.
114+
With VLOG, the lower the verbose level, the more likely messages are to be logged. For example, when the threshold is set
115+
to 2, both ``VLOG(1)``, ``VLOG(2)`` log messages will be printed, but ``VLOG(3)`` and highers won't.
110116

111-
VLOG level is specified by numbers, e.g., 0, 1, 2. Environment variable ``MACE_CPP_MIN_VLOG_LEVEL`` can be set to specify vlog level.
112-
Logs with higher levels than which is specified will be printed. So simply specifying a very large level number will make all logs printed.
117+
All expensive logging with ``VLOG`` should be guarded with ``if(VLOG_IS_ON(lvl))`` check to avoid normal run overhead.
113118

114-
By using Mace run tool, vlog level can be easily set by option, e.g.,
119+
By using ``mace_run`` tool, VLOG level can be easily set by option, e.g.,
115120

116121
.. code:: sh
117122
@@ -168,9 +173,3 @@ things may be a little bit complicated.
168173
# then you can use it as host gdb, e.g.,
169174
bt
170175
171-
172-
173-
174-
175-
176-

mace/BUILD renamed to mace/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ config_setting(
66
visibility = ["//visibility:public"],
77
)
88

9+
config_setting(
10+
name = "linux",
11+
define_values = {
12+
"linux": "true",
13+
},
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
config_setting(
18+
name = "darwin",
19+
define_values = {
20+
"darwin": "true",
21+
},
22+
visibility = ["//visibility:public"],
23+
)
24+
925
config_setting(
1026
name = "android_armv7",
1127
values = {
File renamed without changes.

mace/benchmark/benchmark_model.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "gflags/gflags.h"
2424
#include "mace/public/mace.h"
2525
#include "mace/utils/logging.h"
26-
#include "mace/utils/utils.h"
26+
#include "mace/utils/math.h"
2727
#include "mace/benchmark/statistics.h"
2828
#ifdef MODEL_GRAPH_FORMAT_CODE
2929
#include "mace/codegen/engine/mace_engine_factory.h"

mace/benchmark/model_throughput_test.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* --dsp_model_data_file=dsp_model_data.data \
2424
* --run_seconds=10
2525
*/
26-
#include <malloc.h>
27-
#include <stdint.h>
26+
#include <cstdint>
2827
#include <cstdlib>
2928
#include <fstream>
3029
#include <iostream>
@@ -33,7 +32,7 @@
3332

3433
#include "gflags/gflags.h"
3534
#include "mace/public/mace.h"
36-
#include "mace/utils/env_time.h"
35+
#include "mace/port/env.h"
3736
#include "mace/utils/logging.h"
3837
#include "mace/core/types.h"
3938

File renamed without changes.

mace/core/BUILD renamed to mace/core/BUILD.bazel

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ cc_library(
5959
]) + if_neon_enabled([
6060
"-DMACE_ENABLE_NEON",
6161
]),
62-
linkopts = ["-ldl"] + if_android([
63-
"-pie",
64-
"-lm",
65-
]),
62+
linkopts = ["-ldl"],
6663
deps = [
6764
"//mace/codegen:generated_version",
6865
"//mace/proto:mace_cc",
6966
"//mace/utils",
67+
"//mace/port",
7068
"@half//:half",
7169
] + if_opencl_enabled([
7270
":opencl_headers",

mace/core/allocator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
#ifndef MACE_CORE_ALLOCATOR_H_
1616
#define MACE_CORE_ALLOCATOR_H_
1717

18-
#include <stdlib.h>
19-
#include <string.h>
18+
#include <cstdlib>
2019
#include <map>
2120
#include <limits>
2221
#include <vector>
2322
#include <cstring>
2423

25-
#include "mace/core/macros.h"
24+
#include "mace/utils/macros.h"
2625
#include "mace/core/types.h"
2726
#include "mace/core/runtime_failure_mock.h"
2827
#include "mace/public/mace.h"

mace/core/buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#include <functional>
2222

2323
#include "mace/core/allocator.h"
24-
#include "mace/core/macros.h"
2524
#include "mace/core/types.h"
25+
#include "mace/utils/logging.h"
26+
#include "mace/utils/macros.h"
2627

2728
namespace mace {
2829
namespace core {

0 commit comments

Comments
 (0)