diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 11bc1c2e95d2476c63bfb1ec037b19d45d3cf734..a574449d3bb81a73566dd2cfaae935b7c991d9c9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -144,7 +144,7 @@ model_tests: - CONF_FILE=mace-models/mobilenet-v2/mobilenet-v2-host.yml - > python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=file --model_data_format=file || exit 1; - python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; + python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=1 --validate --model_graph_format=file --model_data_format=file --address_sanitizer || exit 1; python tools/converter.py run --config=${CONF_FILE} --target_socs=$TARGET_SOCS --example --round=1 --validate --model_graph_format=file --model_data_format=file || exit 1; python tools/converter.py benchmark --config=${CONF_FILE} --target_socs=$TARGET_SOCS --round=5 --model_graph_format=file --model_data_format=file || exit 1; python tools/converter.py convert --config=${CONF_FILE} --target_socs=$TARGET_SOCS --model_graph_format=code --model_data_format=file || exit 1; diff --git a/mace/core/device.cc b/mace/core/device.cc index 177b443ba25c729c54a49f4d77cc09cfac952879..535b7193633cf6881fea54f129c0485ddc3ed585 100644 --- a/mace/core/device.cc +++ b/mace/core/device.cc @@ -15,16 +15,17 @@ #include "mace/core/device.h" #include "mace/core/buffer.h" +#include "mace/utils/memory.h" namespace mace { CPUDevice::CPUDevice(const int num_threads, const CPUAffinityPolicy policy, const bool use_gemmlowp) - : cpu_runtime_(new CPURuntime(num_threads, - policy, - use_gemmlowp)), - scratch_buffer_(new ScratchBuffer(GetCPUAllocator())) {} + : cpu_runtime_(make_unique(num_threads, + policy, + use_gemmlowp)), + scratch_buffer_(make_unique(GetCPUAllocator())) {} CPUDevice::~CPUDevice() = default; diff --git a/mace/core/net.cc b/mace/core/net.cc index 365bb353e6de3d5872e2ac75965183b403a09890..cf9940788f187c81fca72772e6331ac485e24ef2 100644 --- a/mace/core/net.cc +++ b/mace/core/net.cc @@ -28,6 +28,7 @@ #include "mace/utils/logging.h" #include "mace/utils/macros.h" #include "mace/utils/math.h" +#include "mace/utils/memory.h" #include "mace/utils/timer.h" #ifdef MACE_ENABLE_OPENCL @@ -77,7 +78,7 @@ std::unique_ptr SerialNet::CreateOperation( // Create the Operation DeviceType target_device_type = target_device_->device_type(); DeviceType device_type = DeviceType::CPU; - construct_context->set_device(cpu_device_); + construct_context->set_device(cpu_device_.get()); construct_context->set_operator_def(op_def); construct_context->set_output_mem_type(MemoryType::CPU_BUFFER); // Get available devices @@ -129,9 +130,10 @@ SerialNet::SerialNet(const OpRegistryBase *op_registry, ws_(ws), target_device_(target_device), cpu_device_( - new CPUDevice(target_device->cpu_runtime()->num_threads(), - target_device->cpu_runtime()->policy(), - target_device->cpu_runtime()->use_gemmlowp())) { + make_unique( + target_device->cpu_runtime()->num_threads(), + target_device->cpu_runtime()->policy(), + target_device->cpu_runtime()->use_gemmlowp())) { MACE_LATENCY_LOGGER(1, "Constructing SerialNet"); // output tensor : related information std::unordered_map output_map; @@ -380,7 +382,7 @@ MaceStatus SerialNet::Init() { if (device_type == target_device_->device_type()) { init_context.set_device(target_device_); } else { - init_context.set_device(cpu_device_); + init_context.set_device(cpu_device_.get()); } // Initialize the operation MACE_RETURN_IF_ERROR(op->Init(&init_context)); @@ -391,7 +393,7 @@ MaceStatus SerialNet::Init() { MaceStatus SerialNet::Run(RunMetadata *run_metadata) { MACE_MEMORY_LOGGING_GUARD(); MACE_LATENCY_LOGGER(1, "Running net"); - OpContext context(ws_, cpu_device_); + OpContext context(ws_, cpu_device_.get()); for (auto iter = operators_.begin(); iter != operators_.end(); ++iter) { auto &op = *iter; DeviceType device_type = op->device_type(); @@ -404,7 +406,7 @@ MaceStatus SerialNet::Run(RunMetadata *run_metadata) { if (device_type == target_device_->device_type()) { context.set_device(target_device_); } else { - context.set_device(cpu_device_); + context.set_device(cpu_device_.get()); } CallStats call_stats; diff --git a/mace/core/net.h b/mace/core/net.h index cafd1a7fe46e47c64a79bd6e8b4208114062d889..788eb611a54158791f988d446153b4b50ef8a59e 100644 --- a/mace/core/net.h +++ b/mace/core/net.h @@ -66,7 +66,7 @@ class SerialNet : public NetBase { Workspace *ws_; Device *target_device_; // CPU is base device. - Device *cpu_device_; + std::unique_ptr cpu_device_; std::vector > operators_; MACE_DISABLE_COPY_AND_ASSIGN(SerialNet); diff --git a/tools/device.py b/tools/device.py index 42936a9b48b45e5c0a4a1e122dc42364713efecf..0ff868f482cf0a9d6d7e69cd854a10ee863d51ae 100644 --- a/tools/device.py +++ b/tools/device.py @@ -208,6 +208,7 @@ class DeviceWrapper: p = subprocess.Popen( [ "env", + "ASAN_OPTIONS=detect_leaks=1", "LD_LIBRARY_PATH=%s" % libmace_dynamic_lib_path, "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_RUNTIME_FAILURE_RATIO=%f" % runtime_failure_ratio, diff --git a/tools/sh_commands.py b/tools/sh_commands.py index ac00dc66f77a8a3996a9276160e6411b01d60aef..aa46a8ac6b4ea2562de5dd990b4bbc45cf4d8d22 100644 --- a/tools/sh_commands.py +++ b/tools/sh_commands.py @@ -304,8 +304,8 @@ def bazel_build(target, bazel_args += ("--config", "asan") else: bazel_args += ("--config", "optimization") - if symbol_hidden: - bazel_args += ("--config", "symbol_hidden") + if symbol_hidden: + bazel_args += ("--config", "symbol_hidden") if extra_args: bazel_args += (extra_args,) six.print_(bazel_args)