提交 e62b5380 编写于 作者: L liuqi

model.template : Use functions to create tensors to solve -fvar-tracking-assignments

上级 e5c26b12
......@@ -48,7 +48,7 @@ class MemoryOptimizer(object):
mem_id = self.idle_mem.pop()
if not op.output_shape:
print('There is no output shape information to do memory optimization.')
print('WARNING: There is no output shape information to do memory optimization.')
return
op.mem_id = mem_id
self.op_mem[self._op_to_tensor(op)] = mem_id
......
......@@ -4,13 +4,21 @@
//
{% if mode == 0 %}
#include <vector>
#include "mace/core/mace.h"
namespace {{tag}}{
alignas(4) unsigned char {{ tensor.name }}[] = {
{% for d in tensor.data %}{{"0x%02X, " % d }}{%endfor%}
alignas(4) unsigned char {{ tensor_info.name }}[] = {
{% for d in tensor_info.data %}{{"0x%02X, " % d }}{%endfor%}
};
void Create{{tensor.name}}(std::vector<mace::TensorProto> &tensors) {
tensors.emplace_back(mace::TensorProto(
{{ tensor.name|tojson }}, {{ tensor.name }},
{ {{ tensor.dims|join(', ') }} }, {{ tensor.data_type }}, {{ tensor.node_id }}));
}
} // namespace {{tag}}
{% elif mode == 1 %}
......@@ -92,7 +100,7 @@ void CreateOperator{{i}}(mace::OperatorDef &op) {
namespace {{tag}} {
{% for tensor in tensors %}
extern unsigned char {{ tensor.name }}[];
extern void Create{{ tensor.name }}(std::vector<mace::TensorProto> &tensors);
{% endfor %}
......@@ -156,9 +164,7 @@ static void CreateTensors(std::vector<mace::TensorProto> &tensors) {
{% for tensor in net.tensors %}
tensors.emplace_back(mace::TensorProto(
{{ tensor.name|tojson }}, {{ tag + '::' + tensor.name }},
{ {{ tensor.dims|join(', ') }} }, {{ tensor.data_type }}, {{ tensor.node_id }}));
{{tag}}::Create{{tensor.name}}(tensors);
{% endfor %}
}
......
......@@ -102,7 +102,8 @@ def convert_to_source(net_def, template, confuse, model_tag, output):
# generate tensor source files
for t in net_def.tensors:
source = j2_env.get_template(template_name).render(
tensor = TensorInfo(t),
tensor_info = TensorInfo(t),
tensor = t,
tag = model_tag,
mode = 0,
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册