提交 d7658a6e 编写于 作者: L Liangliang He

Fix nullptr in mace_run when build with code mode

上级 cabe5cbe
......@@ -90,7 +90,7 @@ For android, you can use `ndk-stack tools <https://developer.android.com/ndk/gui
.. code:: sh
adb logcat | $NDK/ndk-stack -sym /path/to/local/binary/directory/
adb logcat | $ANDROID_NDK_HOME/ndk-stack -sym /path/to/local/binary/directory/
Debug memory usage
......
......@@ -25,6 +25,7 @@
#include "mace/port/file_system.h"
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/math.h"
#include "mace/benchmark/statistics.h"
#ifdef MODEL_GRAPH_FORMAT_CODE
......@@ -284,7 +285,8 @@ int Main(int argc, char **argv) {
std::shared_ptr<mace::MaceEngine> engine;
MaceStatus create_engine_status;
// Create Engine
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_file != "") {
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(FLAGS_model_file.c_str(),
......@@ -294,7 +296,8 @@ int Main(int argc, char **argv) {
}
}
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_data_file != "") {
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(
......
......@@ -31,6 +31,7 @@
#include "mace/port/file_system.h"
#include "mace/public/mace.h"
#include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/string_util.h"
// if convert model to code.
#ifdef MODEL_GRAPH_FORMAT_CODE
......@@ -201,7 +202,8 @@ bool RunModel(const std::vector<std::string> &input_names,
std::shared_ptr<mace::MaceEngine> engine;
MaceStatus create_engine_status;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_file != "") {
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(FLAGS_model_file.c_str(),
......@@ -211,7 +213,8 @@ bool RunModel(const std::vector<std::string> &input_names,
}
}
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_data_file != "") {
auto fs = GetFileSystem();
auto status = fs->NewReadOnlyMemoryRegionFromFile(
......
......@@ -27,8 +27,21 @@ class ReadOnlyMemoryRegion {
public:
ReadOnlyMemoryRegion() = default;
virtual ~ReadOnlyMemoryRegion() = default;
virtual const void *data() = 0;
virtual uint64_t length() = 0;
virtual const void *data() const = 0;
virtual uint64_t length() const = 0;
};
class ReadOnlyBufferMemoryRegion : public ReadOnlyMemoryRegion {
public:
ReadOnlyBufferMemoryRegion() : data_(nullptr), length_(0) {}
ReadOnlyBufferMemoryRegion(const void *data, uint64_t length) :
data_(data), length_(length) {}
const void *data() const override { return data_; }
uint64_t length() const override { return length_; }
private:
const void *data_;
uint64_t length_;
};
class FileSystem {
......
......@@ -38,8 +38,8 @@ class PosixReadOnlyMemoryRegion : public ReadOnlyMemoryRegion {
munmap(const_cast<void *>(addr_), length_);
}
};
const void *data() override { return addr_; };
uint64_t length() override { return length_; };
const void *data() const override { return addr_; };
uint64_t length() const override { return length_; };
private:
const void *addr_;
......
......@@ -37,6 +37,7 @@
#include "mace/port/env.h"
#include "mace/port/file_system.h"
#include "mace/utils/logging.h"
#include "mace/utils/memory.h"
#include "mace/utils/string_util.h"
#ifdef MODEL_GRAPH_FORMAT_CODE
......@@ -244,7 +245,8 @@ bool RunModel(const std::string &model_name,
}
#endif // MACE_ENABLE_OPENCL
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_graph_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_file != "") {
auto fs = GetFileSystem();
status = fs->NewReadOnlyMemoryRegionFromFile(FLAGS_model_file.c_str(),
......@@ -254,7 +256,8 @@ bool RunModel(const std::string &model_name,
}
}
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data;
std::unique_ptr<mace::port::ReadOnlyMemoryRegion> model_weights_data =
make_unique<mace::port::ReadOnlyBufferMemoryRegion>();
if (FLAGS_model_data_file != "") {
auto fs = GetFileSystem();
status = fs->NewReadOnlyMemoryRegionFromFile(FLAGS_model_data_file.c_str(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册