提交 01287a08 编写于 作者: L Liangliang He

Sync mace changes and add latency logging

上级 a5bdbc62
......@@ -3,16 +3,23 @@
// Generated by the mace converter. DO NOT EDIT!
//
{% if mode == 0 %}
#include <vector>
#include "mace/core/public/mace.h"
#include <string>
#include "mace/public/mace.h"
#include "mace/utils/env_time.h"
#include "mace/utils/logging.h"
{% if mode == 0 %}
namespace mace {
namespace {{tag}} {
void Create{{tensor.name}}(std::vector<mace::ConstTensor> &tensors, const unsigned char *model_data) {
void Create{{tensor.name}}(std::vector<mace::ConstTensor> &tensors,
const unsigned char *model_data) {
MACE_LATENCY_LOGGER(2, "Create tensor {{ tensor.name }}");
tensors.emplace_back(mace::ConstTensor(
{{ tensor.name|tojson }}, const_cast<unsigned char *>(model_data) + {{ offset }},
{{ tensor.name|tojson }}, model_data + {{ offset }},
{ {{ tensor.dims|join(', ') }} }, {{ tensor_info.data_type }}, {{ tensor.node_id }}));
}
......@@ -21,34 +28,51 @@ void Create{{tensor.name}}(std::vector<mace::ConstTensor> &tensors, const unsign
{% elif mode == 1 %}
{% if not embed_model_data %}
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
{% endif %}
namespace mace {
namespace {{tag}} {
{% if embed_model_data %}
alignas(4) unsigned char model_data[{{ model_data_size }}] = {
alignas(4) const unsigned char model_data[{{ model_data_size }}] = {
{% for d in model_data %}{{"0x%02X, " % d }}{%endfor%}
};
{% endif %}
unsigned char *LoadModelData(const char *model_data_file) {
const unsigned char *LoadModelData(const char *model_data_file) {
{% if embed_model_data %}
return model_data;
{% else %}
int fd=open(model_data_file, O_RDONLY);
unsigned char *model_data = (unsigned char *)mmap(nullptr, {{ model_data_size }}, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
int fd = open(model_data_file, O_RDONLY);
MACE_CHECK(fd >= 0, "Failed to open model data file ",
model_data_file, ", error code: ", errno);
const unsigned char *model_data =
static_cast<const unsigned char *>(mmap(nullptr, {{ model_data_size }},
PROT_READ, MAP_PRIVATE, fd, 0));
MACE_CHECK(model_data != MAP_FAILED, "Failed to map model data file ",
model_data_file, ", error code: ", errno);
int ret = close(fd);
MACE_CHECK(ret == 0, "Failed to close model data file ",
model_data_file, ", error code: ", errno);
return model_data;
{% endif %}
}
void UnloadModelData(unsigned char *model_data) {
void UnloadModelData(const unsigned char *model_data) {
{% if not embed_model_data %}
munmap(model_data, {{ model_data_size }});
int ret = munmap(const_cast<unsigned char *>(model_data),
{{ model_data_size }});
MACE_CHECK(ret == 0, "Failed to unmap model data file, error code: ", errno);
{% endif %}
}
......@@ -56,11 +80,10 @@ void UnloadModelData(unsigned char *model_data) {
} // namespace mace
{% elif mode == 2 %}
#include <vector>
#include <string>
#include "mace/core/public/mace.h"
namespace mace {
namespace {
void UpdateOp(mace::OperatorDef &op,
const std::string &name,
const std::string &type,
......@@ -75,7 +98,9 @@ void UpdateOp(mace::OperatorDef &op,
op.set_output_type(output_types);
op.set_node_id(node_id);
}
}
} // namespace
} // namespace mace
namespace mace {
namespace {{tag}} {
......@@ -83,6 +108,8 @@ namespace {{tag}} {
{% for i in range(start, end) %}
void CreateOperator{{i}}(mace::OperatorDef &op) {
MACE_LATENCY_LOGGER(2, "Create operator ", op.name());
mace::Argument *arg = nullptr;
{% for arg in net.op[i].arg %}
......@@ -149,7 +176,6 @@ void CreateOperator{{i}}(mace::OperatorDef &op) {
}
{% endif %}
{% endif %}
}
{% endfor %}
......@@ -158,15 +184,13 @@ void CreateOperator{{i}}(mace::OperatorDef &op) {
} // namespace mace
{% else %}
#include <vector>
#include <string>
#include "mace/core/public/mace.h"
namespace mace {
namespace {{tag}} {
{% for tensor in tensors %}
extern void Create{{ tensor.name }}(std::vector<mace::ConstTensor> &tensors, const unsigned char *model_data);
extern void Create{{ tensor.name }}(std::vector<mace::ConstTensor> &tensors,
const unsigned char *model_data);
{% endfor %}
......@@ -175,8 +199,6 @@ extern void CreateOperator{{i}}(mace::OperatorDef &op);
{% endfor %}
} // namespace {{ tag }}
} // namespace mace
namespace {
......@@ -233,22 +255,24 @@ void CreateOutputInfo(mace::NetDef &net_def) {
{% endif %}
void CreateOperators(std::vector<mace::OperatorDef> &ops) {
MACE_LATENCY_LOGGER(1, "Create operators");
ops.resize({{ net.op|length }});
{% for i in range(net.op|length) %}
mace::{{tag}}::CreateOperator{{i}}(ops[{{i}}]);
{% endfor %}
}
void CreateTensors(std::vector<mace::ConstTensor> &tensors, const unsigned char *model_data) {
void CreateTensors(std::vector<mace::ConstTensor> &tensors,
const unsigned char *model_data) {
MACE_LATENCY_LOGGER(1, "Create tensors");
tensors.reserve({{ net.tensors|length }});
{% for tensor in net.tensors %}
mace::{{tag}}::Create{{tensor.name}}(tensors, model_data);
{% endfor %}
}
......@@ -266,12 +290,12 @@ void CreateMemoryArena(mace::MemoryArena &mem_arena) {
}
{% endif %}
}
} // namespace
namespace mace {
namespace {{tag}} {
NetDef CreateNet(const unsigned char *model_data) {
MACE_LATENCY_LOGGER(1, "Create net {{ net.name}}");
NetDef net_def;
net_def.set_name("{{ net.name}}");
net_def.set_version("{{ net.version }}");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册