From c78591d16eefe85abe7bdb9f0e3d2a0c6153dfae Mon Sep 17 00:00:00 2001 From: Sergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics Date: Fri, 15 Nov 2019 16:10:25 +0300 Subject: [PATCH] [neurun] Remove unnecessary map in base_loader (#8955) Set Operand data right when creating it from Tensor, `_tensor_to_operand` map is not needed. Signed-off-by: Sergei Barannikov --- runtime/neurun/frontend/base_loader/base_loader.h | 36 ++++++----------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/runtime/neurun/frontend/base_loader/base_loader.h b/runtime/neurun/frontend/base_loader/base_loader.h index e25b209..f474e85 100644 --- a/runtime/neurun/frontend/base_loader/base_loader.h +++ b/runtime/neurun/frontend/base_loader/base_loader.h @@ -67,8 +67,6 @@ protected: model::Activation convertActivation(ActivationFunctionType type); model::DataType tensorTypeToDataType(TensorType type); - // Load data from buffer to tensor on index - void loadConstantTensor(const Buffer *buffer, const uint32_t &index); // Create operands form tflite::Tensor void loadOperand(const Tensor *tensor); void loadOperationIO(const Operator *op, model::OperandIndexSequence &inputs, @@ -123,8 +121,6 @@ protected: std::vector _buffer; // Reference on loadable Graph graph::Graph &_graph; - // Mapping from tensor index to Graph OperandIndex - std::map _tensor_to_operand; // Mapping from operator pointer to subgraph pointer std::map _op_to_subgraph; const Model *_model; @@ -212,9 +208,15 @@ void BaseLoader::loadOperand(const Tensor *tensor) model::TypeInfo type_info(data_type); // Create operand const auto &operand_index = _graph.addOperand(shape, type_info); - // Buffer index - if (tensor->buffer() != 0) - _tensor_to_operand[tensor->buffer()] = operand_index; + + // Constant tensors are indicated by non-empty data. + const auto *data = _model->buffers()->Get(tensor->buffer())->data(); + if (data != nullptr) + { + auto ptr = nnfw::cpp14::make_unique(data->data(), data->size()); + _graph.setOperandValue(operand_index, std::move(ptr)); + } + // Name unused // auto name = tensor->name(); // Quantization @@ -989,20 +991,6 @@ void BaseLoader::loadOperation(const Operator *op) } template -void BaseLoader::loadConstantTensor(const Buffer *buffer, - const uint32_t &index) -{ - const auto *data = buffer->data(); - if (data != nullptr) - { - auto ptr = nnfw::cpp14::make_unique(data->data(), data->size()); - const auto &operand_index = _tensor_to_operand[index]; - auto &operand = _graph.operands().at(operand_index); - operand.data(std::move(ptr)); - } -} - -template void BaseLoader::loadModel() { static_cast(this)->verify(); @@ -1011,7 +999,6 @@ void BaseLoader::loadModel() // const auto version = _model->version(); // Description unused // const auto *description = _model->description(); - const auto *buffers = _model->buffers(); // Metabuffer unsued // const auto *metadata_buffer = _model->metadata_buffer(); // Load subgraphs and mapping from op to subgraph @@ -1025,11 +1012,6 @@ void BaseLoader::loadModel() static_cast(this)->loadSubgraph(subgraph); } - // Load buffers with constant tensors - for (uint32_t ind = 0; ind < buffers->size(); ind++) - { - loadConstantTensor(buffers->Get(ind), ind); - } _graph.finishBuilding(); } -- 2.7.4