From c6f608fef035b94343ff9f4ffd29a065f8f0ba90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Fri, 7 Sep 2018 10:00:00 +0900 Subject: [PATCH] [neurun] Implement Lowering operands (#2630) This commit implements lowering for operands in `Graph::lower`. operands lowering does the following: - Normalize to 4D shape (rank greater than 4 does not supported) - Collect info of operand layouts for def/use Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/Graph.cc | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index 8783210..cc6d43c 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -8,7 +8,10 @@ #include "nnfw/std/memory.h" #include "linear/Linear.h" #include "operation/LowerInfo.h" +#include "operand/LowerInfo.h" +#include "operand/Shape4DConvert.h" #include "codegen/BackendResolver.h" +#include "backend/IBackendConfig.h" namespace neurun { @@ -111,10 +114,67 @@ void Graph::lower(void) // Lower { + // operand::LowerInfo holder + std::unordered_map> operands_lower_info; + + _operands.iterate([&](const operand::Index &index, const operand::Object &object) { + operands_lower_info[index] = + nnfw::make_unique(operand::asShape4D(object.shape())); + }); + auto _backend_resolver = codegen::BackendResolver(_operands); + _operations.iterate([&](const operation::Index &, operation::Node &node) { auto backend = _backend_resolver.getBackend(typeid(node)); + + // Operation LowerInfo node.lower_info(nnfw::make_unique(backend)); + + // LowerInfo for in/output operands + for (auto operand : node.getInputs()) + { + auto &&lower_info = operands_lower_info.at(operand); + lower_info->addUseLayout(backend.config()->getOperandLayout()); + } + for (auto operand : node.getOutputs()) + { + auto &&lower_info = operands_lower_info.at(operand); + lower_info->addDefLayout(backend.config()->getOperandLayout()); + } + }); + + // Set LowerInfo for each operand from the operand::LowerInfo holder + _operands.iterate([&](const operand::Index &index, operand::Object &object) { + object.lower_info(std::move(operands_lower_info[index])); + + // Dump operand LowerInfo + { + auto layouts_to_string = [](const operand::LayoutSet &layouts) { + std::string str; + for (auto layout : layouts) + { + const char *name = ""; + if (layout == operand::Layout::NHWC) + name = "NHWC"; + if (layout == operand::Layout::NCHW) + name = "NCHW"; + str += name; + str += " "; + } + return "{ " + str + "}"; + }; + + const auto &lower_info = object.lower_info(); + const auto &shape = lower_info->shape(); + std::string def_layouts = layouts_to_string(lower_info->def_layouts()); + std::string use_layouts = layouts_to_string(lower_info->use_layouts()); + VERBOSE(Lower) << "* Operand #" << index.value() << " LowerInfo" << std::endl; + VERBOSE(Lower) << " - 4D Shape (NHWC) : { " << shape.n() << " " << shape.h() << " " + << shape.w() << " " << shape.c() << " " + << "}" << std::endl; + VERBOSE(Lower) << " - Def Layout : " << def_layouts << std::endl; + VERBOSE(Lower) << " - Use Layout : " << use_layouts << std::endl; + } }); } -- 2.7.4