diff --git a/mace/core/mace.cc b/mace/core/mace.cc index 5248318164b6ec34dff05a12c3ec54bd87c4c916..557ef20fe16abbdb13b0ffbecc6ca2cdca9a52e0 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -153,7 +153,9 @@ void OperatorDef::CopyFrom(const OperatorDef &from) { output_type_.resize(from_data_type.size()); std::copy(from_data_type.begin(), from_data_type.end(), output_type_.begin()); - mem_id_ = from.mem_id(); + auto mem_ids = from.mem_id(); + mem_id_.resize(mem_ids.size()); + std::copy(mem_ids.begin(), mem_ids.end(), mem_id_.begin()); // nnlib node_id_ = from.node_id(); @@ -186,13 +188,11 @@ void OperatorDef::set_type(const std::string &type_) { } bool OperatorDef::has_type() const { return (has_bits_ & 0x00000002u) != 0; } void OperatorDef::set_has_type() { has_bits_ |= 0x00000002u; } -int OperatorDef::mem_id() const { return mem_id_; } -void OperatorDef::set_mem_id(const int mem_id) { - set_has_mem_id(); - mem_id_ = mem_id; +const std::vector &OperatorDef::mem_id() const { return mem_id_; } +void OperatorDef::set_mem_id(const std::vector &value) { + mem_id_.resize(value.size()); + std::copy(value.begin(), value.end(), mem_id_.begin()); } -bool OperatorDef::has_mem_id() const { return (has_bits_ & 0x00000004u) != 0; } -void OperatorDef::set_has_mem_id() { has_bits_ |= 0x00000004u; } uint32_t OperatorDef::node_id() const { return node_id_; } void OperatorDef::set_node_id(uint32_t node_id) { node_id_ = node_id; } uint32_t OperatorDef::op_id() const { return op_id_; } diff --git a/mace/core/workspace.cc b/mace/core/workspace.cc index 1cfa1802f07ab1bf6e44d8e86518ef7667575263..1e927c3eff627a9cb4b6e9cb70d76133bbab03c8 100644 --- a/mace/core/workspace.cc +++ b/mace/core/workspace.cc @@ -116,7 +116,7 @@ void Workspace::CreateImageOutputTensor(const NetDef &net_def) { // As DSP may have different data output type for each op, // we stick to the same concept. for (auto &op : net_def.op()) { - if (op.has_mem_id()) { + if (! op.mem_id().empty()){ const DataType op_dtype = static_cast( ArgumentHelper::GetSingleArgument( op, "T", static_cast(DT_FLOAT))); @@ -135,18 +135,19 @@ void Workspace::CreateImageOutputTensor(const NetDef &net_def) { } VLOG(3) << "Preallocate image to tensors"; for (auto &op : net_def.op()) { - if (op.has_mem_id()) { - std::unique_ptr tensor( - new Tensor(preallocated_allocator_.GetBuffer(op.mem_id()), dtype)); - tensor->SetSourceOpName(op.name()); - VLOG(3) - << "Tensor: " << op.name() << "(" << op.type() << ")" - << "; Mem: " << op.mem_id() << "; Image shape: " - << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[0] - << ", " - << dynamic_cast(tensor->UnderlyingBuffer()) - ->image_shape()[1]; - tensor_map_[op.output(0)] = std::move(tensor); + if (!op.mem_id().empty()) { + auto mem_ids = op.mem_id(); + for (auto mem_id : mem_ids) { + std::unique_ptr tensor + (new Tensor(preallocated_allocator_.GetBuffer(mem_id), dtype)); + tensor->SetSourceOpName(op.name()); + VLOG(3) << "Tensor: " << op.name() << "(" << op.type() << ")" << "; Mem: " + << mem_id << "; Image shape: " + << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[0] + << ", " + << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[1]; + tensor_map_[op.output(0)] = std::move(tensor); + } } } } diff --git a/mace/public/mace.h b/mace/public/mace.h index 5d4ad299e7e842d07a801c6d074b948150e6f484..3c8fc778a709d228d369e3321ca730dc8f086f94 100644 --- a/mace/public/mace.h +++ b/mace/public/mace.h @@ -174,9 +174,8 @@ class OperatorDef { const std::string &type() const; void set_type(const std::string &type_); bool has_type() const; - int mem_id() const; - void set_mem_id(const int mem_id); - bool has_mem_id() const; + const std::vector &mem_id() const; + void set_mem_id(const std::vector &value); uint32_t node_id() const; void set_node_id(uint32_t node_id); uint32_t op_id() const; @@ -220,7 +219,7 @@ class OperatorDef { std::vector output_shape_; std::vector output_type_; - int mem_id_; + std::vector mem_id_; // nnlib uint32_t node_id_;