From d01c9dc2320bdc1c218843e38e3e53f72b64142c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 8 Nov 2018 15:49:08 +0900 Subject: [PATCH] Register subtensor info to tensor builder (#3519) Register subtensor info to tensor builder if - Tensor is subtensor of other tensor - Backend support subtensor allocation Signed-off-by: Hyeongseok Oh --- runtimes/neurun/src/linear/Linear.cc | 37 ++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/runtimes/neurun/src/linear/Linear.cc b/runtimes/neurun/src/linear/Linear.cc index e2c3315..59a0050 100644 --- a/runtimes/neurun/src/linear/Linear.cc +++ b/runtimes/neurun/src/linear/Linear.cc @@ -21,6 +21,8 @@ #include "graph/operation/LowerInfo.h" #include "backend/interface/IStageGenerator.h" #include "internal/Convert.h" +#include "backend/interface/IConfig.h" +#include "backend/common/operand/SubTensorInfo.h" #include "logging.h" @@ -85,13 +87,34 @@ backend::TensorBuilderSet Linear::planTensors() uses_map[ind]++; } - // Prepare tensor builders to be returned - const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); - iterTensorBuilders(ind, [&tensor_builders, &info](const graph::operand::Index &ind, - ITensorBuilderPtr tensor_builder) { - tensor_builder->registerTensorInfo(ind, info); + for (auto backend : obj.lower_info()->def_backends()) + { + bool isSubTensor = false; + auto tensor_builder = backend->tensor_builder(); + + if (backend->config()->SupportSubTensorAlloc()) + { + const auto parentInfo = obj.parent_info(); + if (parentInfo != nullptr) + { + isSubTensor = true; + } + } + + if (isSubTensor) + { + const backend::operand::SubTensorInfo info(obj); + tensor_builder->registerSubTensorInfo(ind, info); + } + else + { + const auto info = ::internal::asTensorInfo(obj.shape(), obj.typeInfo()); + tensor_builder->registerTensorInfo(ind, info); + } + + // Prepare tensor builders to be returned tensor_builders.insert(tensor_builder); - }); + } }); // If a tensor is model output, increase the use of the tensor. @@ -156,6 +179,8 @@ backend::TensorBuilderSet Linear::planTensors() assert(uses_map[ind] > 0); #endif + // Set subtensor information + // Todo: move this phase outside as optimization phase return tensor_builders; } -- 2.7.4