提交 0381a4d6 编写于 作者: L liuqi

BUG: fix memory leak in SerialNet(96 bytes)

上级 04db6237
......@@ -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;
......
......@@ -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<CPURuntime>(num_threads,
policy,
use_gemmlowp)),
scratch_buffer_(make_unique<ScratchBuffer>(GetCPUAllocator())) {}
CPUDevice::~CPUDevice() = default;
......
......@@ -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<Operation> 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<CPUDevice>(
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<std::string, InternalOutputInfo> 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;
......
......@@ -66,7 +66,7 @@ class SerialNet : public NetBase {
Workspace *ws_;
Device *target_device_;
// CPU is base device.
Device *cpu_device_;
std::unique_ptr<Device> cpu_device_;
std::vector<std::unique_ptr<Operation> > operators_;
MACE_DISABLE_COPY_AND_ASSIGN(SerialNet);
......
......@@ -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,
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册