Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
01287a08
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
01287a08
编写于
2月 27, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sync mace changes and add latency logging
上级
a5bdbc62
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
28 deletion
+52
-28
python/tools/model.template
python/tools/model.template
+52
-28
未找到文件。
python/tools/model.template
浏览文件 @
01287a08
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录