From c4db2c1e6c354857564c7407b9d7d5fa54a220a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Siva=20Sai=20Vaddipati/System=20SW=20/SRI-Bangalore/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 5 Nov 2018 12:44:35 +0530 Subject: [PATCH] [neurun] Structural changes for ops (#3436) This commit follows the discussions on #3250 Signed-off-by: Siva Sai --- .../src/backend/acl_cl/InitializerGenerator.cc | 27 +++++++------- .../src/backend/acl_cl/InitializerGenerator.h | 12 +++---- .../neurun/src/backend/acl_cl/StageGenerator.cc | 42 +++++++++++----------- .../neurun/src/backend/acl_cl/StageGenerator.h | 18 +++++----- .../neurun/src/backend/cpu/InitializerGenerator.cc | 27 +++++++------- .../neurun/src/backend/cpu/InitializerGenerator.h | 12 +++---- runtimes/neurun/src/backend/cpu/StageGenerator.cc | 42 +++++++++++----------- runtimes/neurun/src/backend/cpu/StageGenerator.h | 18 +++++----- .../src/backend/interface/IInitializerGenerator.h | 27 +++++--------- .../neurun/src/backend/interface/IStageGenerator.h | 18 +++++----- runtimes/neurun/src/codegen/BackendResolver.h | 10 +++--- runtimes/neurun/src/codegen/Planner.cc | 18 +++++----- runtimes/neurun/src/codegen/Planner.h | 18 +++++----- runtimes/neurun/src/frontend/model.cc | 14 ++++---- runtimes/neurun/src/graph/dumper/Dumper.cc | 18 +++++----- runtimes/neurun/src/graph/dumper/Dumper.h | 18 +++++----- runtimes/neurun/src/graph/operation/Add.h | 22 ++++++------ runtimes/neurun/src/graph/operation/AvgPool2D.cc | 10 ++---- runtimes/neurun/src/graph/operation/AvgPool2D.h | 38 +++++++++----------- runtimes/neurun/src/graph/operation/Concat.cc | 7 ++-- runtimes/neurun/src/graph/operation/Concat.h | 17 ++++----- runtimes/neurun/src/graph/operation/Conv2D.cc | 10 ++---- runtimes/neurun/src/graph/operation/Conv2D.h | 40 +++++++++------------ .../neurun/src/graph/operation/FullyConnected.cc | 7 ++-- .../neurun/src/graph/operation/FullyConnected.h | 29 +++++++-------- runtimes/neurun/src/graph/operation/MaxPool2D.cc | 10 ++---- runtimes/neurun/src/graph/operation/MaxPool2D.h | 40 +++++++++------------ runtimes/neurun/src/graph/operation/NOP.cc | 7 ++-- runtimes/neurun/src/graph/operation/NOP.h | 7 ++-- runtimes/neurun/src/graph/operation/NodeVisitor.h | 18 +++++----- runtimes/neurun/src/graph/operation/Op.lst | 16 ++++----- runtimes/neurun/src/graph/operation/Permute.cc | 7 ++-- runtimes/neurun/src/graph/operation/Permute.h | 7 ++-- runtimes/neurun/src/graph/operation/Reshape.cc | 7 ++-- runtimes/neurun/src/graph/operation/Reshape.h | 19 +++++----- runtimes/neurun/src/graph/operation/Softmax.cc | 7 ++-- runtimes/neurun/src/graph/operation/Softmax.h | 26 ++++++-------- .../src/graph/pass/PermutationInsertionPass.cc | 2 +- runtimes/neurun/test/graph/operation/SetIO.cc | 4 +-- 39 files changed, 304 insertions(+), 392 deletions(-) diff --git a/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.cc b/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.cc index 51048ce..be3d280 100644 --- a/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.cc @@ -34,28 +34,27 @@ InitializerGenerator::InitializerGenerator(const neurun::graph::operand::Set &ct // DO NOTHING } -Initializer InitializerGenerator::generate(const graph::operation::Conv2D::Implicit::Node &node) +Initializer InitializerGenerator::generate(const graph::operation::Conv2DNode &node) { - using graph::operation::Conv2D::Implicit::Input; + using graph::operation::Conv2DNode; Initializer ret; - ret.push_back({node.getInputs().at(Input::KERNEL), generateWeight(node)}); - ret.push_back({node.getInputs().at(Input::BIAS), generateBias(node)}); + ret.push_back({node.getInputs().at(Conv2DNode::Input::KERNEL), generateWeight(node)}); + ret.push_back({node.getInputs().at(Conv2DNode::Input::BIAS), generateBias(node)}); return ret; } -Initializer InitializerGenerator::generate(const graph::operation::FullyConnected::Node &node) +Initializer InitializerGenerator::generate(const graph::operation::FullyConnectedNode &node) { - using graph::operation::FullyConnected::Input; + using graph::operation::FullyConnectedNode; Initializer ret; - ret.push_back({node.getInputs().at(Input::WEIGHT), generateWeight(node)}); - ret.push_back({node.getInputs().at(Input::BIAS), generateBias(node)}); + ret.push_back({node.getInputs().at(FullyConnectedNode::Input::WEIGHT), generateWeight(node)}); + ret.push_back({node.getInputs().at(FullyConnectedNode::Input::BIAS), generateBias(node)}); return ret; } -InitializerFn -InitializerGenerator::generateWeight(const graph::operation::Conv2D::Implicit::Node &node) +InitializerFn InitializerGenerator::generateWeight(const graph::operation::Conv2DNode &node) { const auto ker_index{node.getInputs().at(1)}; @@ -75,8 +74,7 @@ InitializerGenerator::generateWeight(const graph::operation::Conv2D::Implicit::N }; } -InitializerFn -InitializerGenerator::generateWeight(const graph::operation::FullyConnected::Node &node) +InitializerFn InitializerGenerator::generateWeight(const graph::operation::FullyConnectedNode &node) { const auto weight_index{node.getInputs().at(1)}; const auto input_index{node.getInputs().at(0)}; @@ -114,8 +112,7 @@ InitializerGenerator::generateWeight(const graph::operation::FullyConnected::Nod }; } -InitializerFn -InitializerGenerator::generateBias(const graph::operation::Conv2D::Implicit::Node &node) +InitializerFn InitializerGenerator::generateBias(const graph::operation::Conv2DNode &node) { // TODO Refactor so we can reuse the common code @@ -139,7 +136,7 @@ InitializerGenerator::generateBias(const graph::operation::Conv2D::Implicit::Nod }; } -InitializerFn InitializerGenerator::generateBias(const graph::operation::FullyConnected::Node &node) +InitializerFn InitializerGenerator::generateBias(const graph::operation::FullyConnectedNode &node) { const auto bias_index{node.getInputs().at(2)}; diff --git a/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.h b/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.h index e259013..bf076f6 100644 --- a/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.h +++ b/runtimes/neurun/src/backend/acl_cl/InitializerGenerator.h @@ -34,15 +34,15 @@ public: InitializerGenerator(const neurun::graph::operand::Set &ctx); public: - Initializer generate(const graph::operation::Conv2D::Implicit::Node &node) override; - Initializer generate(const graph::operation::FullyConnected::Node &node) override; + Initializer generate(const graph::operation::Conv2DNode &node) override; + Initializer generate(const graph::operation::FullyConnectedNode &node) override; private: - InitializerFn generateWeight(const graph::operation::Conv2D::Implicit::Node &node); - InitializerFn generateWeight(const graph::operation::FullyConnected::Node &node); + InitializerFn generateWeight(const graph::operation::Conv2DNode &node); + InitializerFn generateWeight(const graph::operation::FullyConnectedNode &node); - InitializerFn generateBias(const graph::operation::Conv2D::Implicit::Node &node); - InitializerFn generateBias(const graph::operation::FullyConnected::Node &node); + InitializerFn generateBias(const graph::operation::Conv2DNode &node); + InitializerFn generateBias(const graph::operation::FullyConnectedNode &node); private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc index a2200fb..b8e5181 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc @@ -120,14 +120,14 @@ StageGenerator::StageGenerator(const neurun::graph::operand::Set &ctx, // DO NOTHING } -Stage StageGenerator::generate(const graph::operation::Conv2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::Conv2DNode &node) { - using namespace graph::operation::Conv2D::Implicit; + using graph::operation::Conv2DNode; const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(Input::INPUT)}; - const auto ker_index{node.getInputs().at(Input::KERNEL)}; - const auto bias_index{node.getInputs().at(Input::BIAS)}; + const auto ifm_index{node.getInputs().at(Conv2DNode::Input::INPUT)}; + const auto ker_index{node.getInputs().at(Conv2DNode::Input::KERNEL)}; + const auto bias_index{node.getInputs().at(Conv2DNode::Input::BIAS)}; const auto vstride_index{node.param().vstride_index}; const auto hstride_index{node.param().hstride_index}; @@ -199,10 +199,10 @@ Stage StageGenerator::generate(const graph::operation::Conv2D::Implicit::Node &n }; } -Stage StageGenerator::generate(const graph::operation::MaxPool2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::MaxPool2DNode &node) { const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(graph::operation::MaxPool2D::Implicit::Input::INPUT)}; + const auto ifm_index{node.getInputs().at(graph::operation::MaxPool2DNode::Input::INPUT)}; const auto kh_index{node.param().kh_index}; const auto kw_index{node.param().kw_index}; @@ -285,10 +285,10 @@ Stage StageGenerator::generate(const graph::operation::MaxPool2D::Implicit::Node }; } -Stage StageGenerator::generate(const graph::operation::AvgPool2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::AvgPool2DNode &node) { const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(graph::operation::AvgPool2D::Implicit::Input::INPUT)}; + const auto ifm_index{node.getInputs().at(graph::operation::AvgPool2DNode::Input::INPUT)}; const auto kh_index{node.param().kh_index}; const auto kw_index{node.param().kw_index}; @@ -375,7 +375,7 @@ Stage StageGenerator::generate(const graph::operation::AvgPool2D::Implicit::Node }; } -Stage StageGenerator::generate(const graph::operation::Concat::Node &node) +Stage StageGenerator::generate(const graph::operation::ConcatNode &node) { const auto ofm_index{node.getOutputs().at(0)}; const auto axis_index{node.param().axis_index}; @@ -417,14 +417,14 @@ Stage StageGenerator::generate(const graph::operation::Concat::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::FullyConnected::Node &node) +Stage StageGenerator::generate(const graph::operation::FullyConnectedNode &node) { - using namespace graph::operation::FullyConnected; + using graph::operation::FullyConnectedNode; const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(Input::INPUT)}; - const auto weight_index{node.getInputs().at(Input::WEIGHT)}; - const auto bias_index{node.getInputs().at(Input::BIAS)}; + const auto input_index{node.getInputs().at(FullyConnectedNode::Input::INPUT)}; + const auto weight_index{node.getInputs().at(FullyConnectedNode::Input::WEIGHT)}; + const auto bias_index{node.getInputs().at(FullyConnectedNode::Input::BIAS)}; const auto activation_index{node.param().activation_index}; // Construct operation parameters @@ -466,10 +466,10 @@ Stage StageGenerator::generate(const graph::operation::FullyConnected::Node &nod }; } -Stage StageGenerator::generate(const graph::operation::Reshape::Node &node) +Stage StageGenerator::generate(const graph::operation::ReshapeNode &node) { const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(graph::operation::Reshape::Input::INPUT)}; + const auto input_index{node.getInputs().at(graph::operation::ReshapeNode::Input::INPUT)}; struct Param { @@ -496,10 +496,10 @@ Stage StageGenerator::generate(const graph::operation::Reshape::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::Softmax::Node &node) +Stage StageGenerator::generate(const graph::operation::SoftmaxNode &node) { const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(graph::operation::Softmax::Input::INPUT)}; + const auto input_index{node.getInputs().at(graph::operation::SoftmaxNode::Input::INPUT)}; const auto scale_index{node.param().scale_index}; assert(_ctx.at(scale_index).shape().rank() == 0); @@ -531,13 +531,13 @@ Stage StageGenerator::generate(const graph::operation::Softmax::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::NOP::Node & /* node */) +Stage StageGenerator::generate(const graph::operation::NOPNode & /* node */) { // DO NOTHING return nullptr; } -Stage StageGenerator::generate(const graph::operation::Permute::Node & /* node */) +Stage StageGenerator::generate(const graph::operation::PermuteNode & /* node */) { throw "Unsupported"; } diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.h b/runtimes/neurun/src/backend/acl_cl/StageGenerator.h index 1cbf72b..4a48086 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.h +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.h @@ -37,15 +37,15 @@ public: virtual std::shared_ptr tensor_builder() override { return _tensor_builder; } - virtual Stage generate(const graph::operation::Conv2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::MaxPool2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::AvgPool2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::Concat::Node &node) override; - virtual Stage generate(const graph::operation::FullyConnected::Node &node) override; - virtual Stage generate(const graph::operation::Reshape::Node &node) override; - virtual Stage generate(const graph::operation::Softmax::Node &node) override; - virtual Stage generate(const graph::operation::NOP::Node &node) override; - virtual Stage generate(const graph::operation::Permute::Node &node) override; + virtual Stage generate(const graph::operation::Conv2DNode &node) override; + virtual Stage generate(const graph::operation::MaxPool2DNode &node) override; + virtual Stage generate(const graph::operation::AvgPool2DNode &node) override; + virtual Stage generate(const graph::operation::ConcatNode &node) override; + virtual Stage generate(const graph::operation::FullyConnectedNode &node) override; + virtual Stage generate(const graph::operation::ReshapeNode &node) override; + virtual Stage generate(const graph::operation::SoftmaxNode &node) override; + virtual Stage generate(const graph::operation::NOPNode &node) override; + virtual Stage generate(const graph::operation::PermuteNode &node) override; virtual Stage generate(const graph::operation::AddNode &node) override; private: diff --git a/runtimes/neurun/src/backend/cpu/InitializerGenerator.cc b/runtimes/neurun/src/backend/cpu/InitializerGenerator.cc index 468cb37..f415c71 100644 --- a/runtimes/neurun/src/backend/cpu/InitializerGenerator.cc +++ b/runtimes/neurun/src/backend/cpu/InitializerGenerator.cc @@ -34,28 +34,27 @@ InitializerGenerator::InitializerGenerator(const neurun::graph::operand::Set &ct // DO NOTHING } -Initializer InitializerGenerator::generate(const graph::operation::Conv2D::Implicit::Node &node) +Initializer InitializerGenerator::generate(const graph::operation::Conv2DNode &node) { - using graph::operation::Conv2D::Implicit::Input; + using graph::operation::Conv2DNode; Initializer ret; - ret.push_back({node.getInputs().at(Input::KERNEL), generateWeight(node)}); - ret.push_back({node.getInputs().at(Input::BIAS), generateBias(node)}); + ret.push_back({node.getInputs().at(Conv2DNode::Input::KERNEL), generateWeight(node)}); + ret.push_back({node.getInputs().at(Conv2DNode::Input::BIAS), generateBias(node)}); return ret; } -Initializer InitializerGenerator::generate(const graph::operation::FullyConnected::Node &node) +Initializer InitializerGenerator::generate(const graph::operation::FullyConnectedNode &node) { - using graph::operation::FullyConnected::Input; + using graph::operation::FullyConnectedNode; Initializer ret; - ret.push_back({node.getInputs().at(Input::WEIGHT), generateWeight(node)}); - ret.push_back({node.getInputs().at(Input::BIAS), generateBias(node)}); + ret.push_back({node.getInputs().at(FullyConnectedNode::Input::WEIGHT), generateWeight(node)}); + ret.push_back({node.getInputs().at(FullyConnectedNode::Input::BIAS), generateBias(node)}); return ret; } -InitializerFn -InitializerGenerator::generateWeight(const graph::operation::Conv2D::Implicit::Node &node) +InitializerFn InitializerGenerator::generateWeight(const graph::operation::Conv2DNode &node) { const auto ker_index{node.getInputs().at(1)}; @@ -75,8 +74,7 @@ InitializerGenerator::generateWeight(const graph::operation::Conv2D::Implicit::N }; } -InitializerFn -InitializerGenerator::generateWeight(const graph::operation::FullyConnected::Node &node) +InitializerFn InitializerGenerator::generateWeight(const graph::operation::FullyConnectedNode &node) { const auto weight_index{node.getInputs().at(1)}; const auto input_index{node.getInputs().at(0)}; @@ -151,8 +149,7 @@ InitializerGenerator::generateWeight(const graph::operation::FullyConnected::Nod } } -InitializerFn -InitializerGenerator::generateBias(const graph::operation::Conv2D::Implicit::Node &node) +InitializerFn InitializerGenerator::generateBias(const graph::operation::Conv2DNode &node) { // TODO Refactor so we can reuse the common code @@ -176,7 +173,7 @@ InitializerGenerator::generateBias(const graph::operation::Conv2D::Implicit::Nod }; } -InitializerFn InitializerGenerator::generateBias(const graph::operation::FullyConnected::Node &node) +InitializerFn InitializerGenerator::generateBias(const graph::operation::FullyConnectedNode &node) { const auto bias_index{node.getInputs().at(2)}; diff --git a/runtimes/neurun/src/backend/cpu/InitializerGenerator.h b/runtimes/neurun/src/backend/cpu/InitializerGenerator.h index b7e7302..859504a 100644 --- a/runtimes/neurun/src/backend/cpu/InitializerGenerator.h +++ b/runtimes/neurun/src/backend/cpu/InitializerGenerator.h @@ -34,15 +34,15 @@ public: InitializerGenerator(const neurun::graph::operand::Set &ctx); public: - Initializer generate(const graph::operation::Conv2D::Implicit::Node &node) override; - Initializer generate(const graph::operation::FullyConnected::Node &node) override; + Initializer generate(const graph::operation::Conv2DNode &node) override; + Initializer generate(const graph::operation::FullyConnectedNode &node) override; private: - InitializerFn generateWeight(const graph::operation::Conv2D::Implicit::Node &node); - InitializerFn generateWeight(const graph::operation::FullyConnected::Node &node); + InitializerFn generateWeight(const graph::operation::Conv2DNode &node); + InitializerFn generateWeight(const graph::operation::FullyConnectedNode &node); - InitializerFn generateBias(const graph::operation::Conv2D::Implicit::Node &node); - InitializerFn generateBias(const graph::operation::FullyConnected::Node &node); + InitializerFn generateBias(const graph::operation::Conv2DNode &node); + InitializerFn generateBias(const graph::operation::FullyConnectedNode &node); private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/backend/cpu/StageGenerator.cc b/runtimes/neurun/src/backend/cpu/StageGenerator.cc index 8382aa2..105324d 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.cc +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.cc @@ -50,14 +50,14 @@ StageGenerator::StageGenerator(const neurun::graph::operand::Set &operand_ctx, // DO NOTHING } -Stage StageGenerator::generate(const graph::operation::Conv2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::Conv2DNode &node) { - using namespace graph::operation::Conv2D::Implicit; + using graph::operation::Conv2DNode; const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(Input::INPUT)}; - const auto ker_index{node.getInputs().at(Input::KERNEL)}; - const auto bias_index{node.getInputs().at(Input::BIAS)}; + const auto ifm_index{node.getInputs().at(Conv2DNode::Input::INPUT)}; + const auto ker_index{node.getInputs().at(Conv2DNode::Input::KERNEL)}; + const auto bias_index{node.getInputs().at(Conv2DNode::Input::BIAS)}; const auto vstride_index{node.param().vstride_index}; const auto hstride_index{node.param().hstride_index}; @@ -137,12 +137,12 @@ Stage StageGenerator::generate(const graph::operation::Conv2D::Implicit::Node &n }; } -Stage StageGenerator::generate(const graph::operation::MaxPool2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::MaxPool2DNode &node) { VERBOSE(MaxPool2D) << "generate CPU MaxPool2D" << std::endl; const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(graph::operation::MaxPool2D::Implicit::Input::INPUT)}; + const auto ifm_index{node.getInputs().at(graph::operation::MaxPool2DNode::Input::INPUT)}; const auto kh_index{node.param().kh_index}; const auto kw_index{node.param().kw_index}; @@ -233,12 +233,12 @@ Stage StageGenerator::generate(const graph::operation::MaxPool2D::Implicit::Node }; } -Stage StageGenerator::generate(const graph::operation::AvgPool2D::Implicit::Node &node) +Stage StageGenerator::generate(const graph::operation::AvgPool2DNode &node) { VERBOSE(AvgPool2D) << "generate CPU AvgPool2D" << std::endl; const auto ofm_index{node.getOutputs().at(0)}; - const auto ifm_index{node.getInputs().at(graph::operation::AvgPool2D::Implicit::Input::INPUT)}; + const auto ifm_index{node.getInputs().at(graph::operation::AvgPool2DNode::Input::INPUT)}; const auto kh_index{node.param().kh_index}; const auto kw_index{node.param().kw_index}; @@ -333,7 +333,7 @@ Stage StageGenerator::generate(const graph::operation::AvgPool2D::Implicit::Node }; } -Stage StageGenerator::generate(const graph::operation::Concat::Node &node) +Stage StageGenerator::generate(const graph::operation::ConcatNode &node) { VERBOSE(Concat) << "generate CPU Concat" << std::endl; @@ -387,16 +387,16 @@ Stage StageGenerator::generate(const graph::operation::Concat::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::FullyConnected::Node &node) +Stage StageGenerator::generate(const graph::operation::FullyConnectedNode &node) { VERBOSE(FullyConnected) << "generate CPU FullyConnected" << std::endl; - using namespace graph::operation::FullyConnected; + using graph::operation::FullyConnectedNode; const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(Input::INPUT)}; - const auto weight_index{node.getInputs().at(Input::WEIGHT)}; - const auto bias_index{node.getInputs().at(Input::BIAS)}; + const auto input_index{node.getInputs().at(FullyConnectedNode::Input::INPUT)}; + const auto weight_index{node.getInputs().at(FullyConnectedNode::Input::WEIGHT)}; + const auto bias_index{node.getInputs().at(FullyConnectedNode::Input::BIAS)}; const auto activation_index{node.param().activation_index}; // Construct operation parameters @@ -448,10 +448,10 @@ Stage StageGenerator::generate(const graph::operation::FullyConnected::Node &nod }; } -Stage StageGenerator::generate(const graph::operation::Reshape::Node &node) +Stage StageGenerator::generate(const graph::operation::ReshapeNode &node) { const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(graph::operation::Reshape::Input::INPUT)}; + const auto input_index{node.getInputs().at(graph::operation::ReshapeNode::Input::INPUT)}; struct Param { @@ -485,12 +485,12 @@ Stage StageGenerator::generate(const graph::operation::Reshape::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::Softmax::Node &node) +Stage StageGenerator::generate(const graph::operation::SoftmaxNode &node) { VERBOSE(Softmax) << "generate CPU Softmax" << std::endl; const auto output_index{node.getOutputs().at(0)}; - const auto input_index{node.getInputs().at(graph::operation::Softmax::Input::INPUT)}; + const auto input_index{node.getInputs().at(graph::operation::SoftmaxNode::Input::INPUT)}; const auto scale_index{node.param().scale_index}; struct Param @@ -530,13 +530,13 @@ Stage StageGenerator::generate(const graph::operation::Softmax::Node &node) }; } -Stage StageGenerator::generate(const graph::operation::NOP::Node & /* node */) +Stage StageGenerator::generate(const graph::operation::NOPNode & /* node */) { // DO NOTHING return nullptr; } -Stage StageGenerator::generate(const graph::operation::Permute::Node &node) +Stage StageGenerator::generate(const graph::operation::PermuteNode &node) { VERBOSE(Permute) << "generate CPU Permute" << std::endl; diff --git a/runtimes/neurun/src/backend/cpu/StageGenerator.h b/runtimes/neurun/src/backend/cpu/StageGenerator.h index ede9243..cb99b1a 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.h +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.h @@ -38,15 +38,15 @@ public: virtual std::shared_ptr tensor_builder() override { return _tensor_builder; } - virtual Stage generate(const graph::operation::Conv2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::MaxPool2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::AvgPool2D::Implicit::Node &node) override; - virtual Stage generate(const graph::operation::Concat::Node &node) override; - virtual Stage generate(const graph::operation::FullyConnected::Node &node) override; - virtual Stage generate(const graph::operation::Reshape::Node &node) override; - virtual Stage generate(const graph::operation::Softmax::Node &node) override; - virtual Stage generate(const graph::operation::NOP::Node &node) override; - virtual Stage generate(const graph::operation::Permute::Node &node) override; + virtual Stage generate(const graph::operation::Conv2DNode &node) override; + virtual Stage generate(const graph::operation::MaxPool2DNode &node) override; + virtual Stage generate(const graph::operation::AvgPool2DNode &node) override; + virtual Stage generate(const graph::operation::ConcatNode &node) override; + virtual Stage generate(const graph::operation::FullyConnectedNode &node) override; + virtual Stage generate(const graph::operation::ReshapeNode &node) override; + virtual Stage generate(const graph::operation::SoftmaxNode &node) override; + virtual Stage generate(const graph::operation::NOPNode &node) override; + virtual Stage generate(const graph::operation::PermuteNode &node) override; virtual Stage generate(const graph::operation::AddNode &node) override; private: diff --git a/runtimes/neurun/src/backend/interface/IInitializerGenerator.h b/runtimes/neurun/src/backend/interface/IInitializerGenerator.h index 89a17a7..6aca1e4 100644 --- a/runtimes/neurun/src/backend/interface/IInitializerGenerator.h +++ b/runtimes/neurun/src/backend/interface/IInitializerGenerator.h @@ -52,27 +52,18 @@ struct IInitializerGenerator { virtual ~IInitializerGenerator() = default; - virtual Initializer generate(const graph::operation::Conv2D::Implicit::Node &) + virtual Initializer generate(const graph::operation::Conv2DNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::MaxPool2DNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::AvgPool2DNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::ConcatNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::FullyConnectedNode &) { return Initializer{}; } - virtual Initializer generate(const graph::operation::MaxPool2D::Implicit::Node &) - { - return Initializer{}; - } - virtual Initializer generate(const graph::operation::AvgPool2D::Implicit::Node &) - { - return Initializer{}; - } - virtual Initializer generate(const graph::operation::Concat::Node &) { return Initializer{}; } - virtual Initializer generate(const graph::operation::FullyConnected::Node &) - { - return Initializer{}; - } - virtual Initializer generate(const graph::operation::Reshape::Node &) { return Initializer{}; } - virtual Initializer generate(const graph::operation::Softmax::Node &) { return Initializer{}; } - virtual Initializer generate(const graph::operation::NOP::Node &) { return Initializer{}; } - virtual Initializer generate(const graph::operation::Permute::Node &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::ReshapeNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::SoftmaxNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::NOPNode &) { return Initializer{}; } + virtual Initializer generate(const graph::operation::PermuteNode &) { return Initializer{}; } virtual Initializer generate(const graph::operation::AddNode &) { return Initializer{}; } }; diff --git a/runtimes/neurun/src/backend/interface/IStageGenerator.h b/runtimes/neurun/src/backend/interface/IStageGenerator.h index 8ecb3f1..58e0272 100644 --- a/runtimes/neurun/src/backend/interface/IStageGenerator.h +++ b/runtimes/neurun/src/backend/interface/IStageGenerator.h @@ -54,15 +54,15 @@ struct IStageGenerator virtual std::shared_ptr tensor_builder() = 0; - virtual Stage generate(const graph::operation::Conv2D::Implicit::Node &node) = 0; - virtual Stage generate(const graph::operation::MaxPool2D::Implicit::Node &node) = 0; - virtual Stage generate(const graph::operation::AvgPool2D::Implicit::Node &node) = 0; - virtual Stage generate(const graph::operation::Concat::Node &node) = 0; - virtual Stage generate(const graph::operation::FullyConnected::Node &node) = 0; - virtual Stage generate(const graph::operation::Reshape::Node &node) = 0; - virtual Stage generate(const graph::operation::Softmax::Node &node) = 0; - virtual Stage generate(const graph::operation::NOP::Node &node) = 0; - virtual Stage generate(const graph::operation::Permute::Node &node) = 0; + virtual Stage generate(const graph::operation::Conv2DNode &node) = 0; + virtual Stage generate(const graph::operation::MaxPool2DNode &node) = 0; + virtual Stage generate(const graph::operation::AvgPool2DNode &node) = 0; + virtual Stage generate(const graph::operation::ConcatNode &node) = 0; + virtual Stage generate(const graph::operation::FullyConnectedNode &node) = 0; + virtual Stage generate(const graph::operation::ReshapeNode &node) = 0; + virtual Stage generate(const graph::operation::SoftmaxNode &node) = 0; + virtual Stage generate(const graph::operation::NOPNode &node) = 0; + virtual Stage generate(const graph::operation::PermuteNode &node) = 0; virtual Stage generate(const graph::operation::AddNode &node) = 0; }; diff --git a/runtimes/neurun/src/codegen/BackendResolver.h b/runtimes/neurun/src/codegen/BackendResolver.h index d410690..e788836 100644 --- a/runtimes/neurun/src/codegen/BackendResolver.h +++ b/runtimes/neurun/src/codegen/BackendResolver.h @@ -44,10 +44,10 @@ public: if (backend_all_str.compare("none") != 0) { VERBOSE(BackendResolver) << "Use backend for all ops: " << backend_all_str << std::endl; -#define OP(InternalName, NnApiName) \ - { \ - auto backend = _backend_manager->get(backend_all_str); \ - _gen_map[typeid(graph::operation::InternalName::Node)] = backend; \ +#define OP(InternalName, NnApiName) \ + { \ + auto backend = _backend_manager->get(backend_all_str); \ + _gen_map[typeid(graph::operation::InternalName)] = backend; \ } #include "graph/operation/Op.lst" #undef OP @@ -60,7 +60,7 @@ public: ::nnfw::util::EnvVar{std::string("OP_BACKEND_") + #NnApiName}.asString("acl_cl"); \ auto backend = _backend_manager->get(backend_str); \ VERBOSE(BackendResolver) << "backend for " << #NnApiName << ": " << backend_str << std::endl; \ - _gen_map[typeid(graph::operation::InternalName::Node)] = backend; \ + _gen_map[typeid(graph::operation::InternalName)] = backend; \ } #include "graph/operation/Op.lst" diff --git a/runtimes/neurun/src/codegen/Planner.cc b/runtimes/neurun/src/codegen/Planner.cc index 4d6c44c..9393156 100644 --- a/runtimes/neurun/src/codegen/Planner.cc +++ b/runtimes/neurun/src/codegen/Planner.cc @@ -30,7 +30,7 @@ namespace neurun namespace codegen { -void Planner::visit(const graph::operation::Conv2D::Implicit::Node &node) +void Planner::visit(const graph::operation::Conv2DNode &node) { // backend auto backend = node.lower_info()->backend(); @@ -44,7 +44,7 @@ void Planner::visit(const graph::operation::Conv2D::Implicit::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::MaxPool2D::Implicit::Node &node) +void Planner::visit(const graph::operation::MaxPool2DNode &node) { // backend auto backend = node.lower_info()->backend(); @@ -58,7 +58,7 @@ void Planner::visit(const graph::operation::MaxPool2D::Implicit::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::AvgPool2D::Implicit::Node &node) +void Planner::visit(const graph::operation::AvgPool2DNode &node) { // backend auto backend = node.lower_info()->backend(); @@ -72,7 +72,7 @@ void Planner::visit(const graph::operation::AvgPool2D::Implicit::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::Concat::Node &node) +void Planner::visit(const graph::operation::ConcatNode &node) { // NOTE This implementation assumes concat over feature depth // TODO Remove this assumption @@ -91,7 +91,7 @@ void Planner::visit(const graph::operation::Concat::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::FullyConnected::Node &node) +void Planner::visit(const graph::operation::FullyConnectedNode &node) { VERBOSE(FullyConnected) << "Configure FULLY_CONNECTED operation" << std::endl; @@ -107,7 +107,7 @@ void Planner::visit(const graph::operation::FullyConnected::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::Reshape::Node &node) +void Planner::visit(const graph::operation::ReshapeNode &node) { const auto output_index{node.getOutputs().at(0)}; const auto input_index{node.getInputs().at(0)}; @@ -140,7 +140,7 @@ void Planner::visit(const graph::operation::Reshape::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::Softmax::Node &node) +void Planner::visit(const graph::operation::SoftmaxNode &node) { VERBOSE(Softmax) << "Configure SOFTMAX operation" << std::endl; @@ -167,7 +167,7 @@ void Planner::visit(const graph::operation::Softmax::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::NOP::Node &node) +void Planner::visit(const graph::operation::NOPNode &node) { // backend auto backend = node.lower_info()->backend(); @@ -181,7 +181,7 @@ void Planner::visit(const graph::operation::NOP::Node &node) _builder.addStage(stage_gen->generate(node)); } -void Planner::visit(const graph::operation::Permute::Node &node) +void Planner::visit(const graph::operation::PermuteNode &node) { VERBOSE(Permute) << "Configure Permute operation" << std::endl; diff --git a/runtimes/neurun/src/codegen/Planner.h b/runtimes/neurun/src/codegen/Planner.h index e1cdb76..1b96c17 100644 --- a/runtimes/neurun/src/codegen/Planner.h +++ b/runtimes/neurun/src/codegen/Planner.h @@ -46,15 +46,15 @@ public: } public: - virtual void visit(const graph::operation::Conv2D::Implicit::Node &) override; - virtual void visit(const graph::operation::MaxPool2D::Implicit::Node &) override; - virtual void visit(const graph::operation::AvgPool2D::Implicit::Node &) override; - virtual void visit(const graph::operation::Concat::Node &) override; - virtual void visit(const graph::operation::Reshape::Node &) override; - virtual void visit(const graph::operation::FullyConnected::Node &) override; - virtual void visit(const graph::operation::Softmax::Node &) override; - virtual void visit(const graph::operation::NOP::Node &) override; - virtual void visit(const graph::operation::Permute::Node &) override; + virtual void visit(const graph::operation::Conv2DNode &) override; + virtual void visit(const graph::operation::MaxPool2DNode &) override; + virtual void visit(const graph::operation::AvgPool2DNode &) override; + virtual void visit(const graph::operation::ConcatNode &) override; + virtual void visit(const graph::operation::ReshapeNode &) override; + virtual void visit(const graph::operation::FullyConnectedNode &) override; + virtual void visit(const graph::operation::SoftmaxNode &) override; + virtual void visit(const graph::operation::NOPNode &) override; + virtual void visit(const graph::operation::PermuteNode &) override; virtual void visit(const graph::operation::AddNode &) override; private: diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index 28a9b25..52cae4a 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -243,7 +243,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using GraphNode = neurun::graph::operation::Conv2D::Implicit::Node; + using GraphNode = neurun::graph::operation::Conv2DNode; graph.addOperation(nnfw::make_unique(node_param)); } @@ -264,7 +264,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using GraphNode = neurun::graph::operation::MaxPool2D::Implicit::Node; + using GraphNode = neurun::graph::operation::MaxPool2DNode; graph.addOperation(nnfw::make_unique(node_param)); } @@ -285,7 +285,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using GraphNode = neurun::graph::operation::AvgPool2D::Implicit::Node; + using GraphNode = neurun::graph::operation::AvgPool2DNode; graph.addOperation(nnfw::make_unique(node_param)); } @@ -298,7 +298,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_CONCATENATION: { - using GraphNode = neurun::graph::operation::Concat::Node; + using GraphNode = neurun::graph::operation::ConcatNode; graph.addOperation(nnfw::make_unique(node_param)); @@ -306,7 +306,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RESHAPE: { - using GraphNode = neurun::graph::operation::Reshape::Node; + using GraphNode = neurun::graph::operation::ReshapeNode; graph.addOperation(nnfw::make_unique(node_param)); @@ -314,7 +314,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_FULLY_CONNECTED: { - using GraphNode = neurun::graph::operation::FullyConnected::Node; + using GraphNode = neurun::graph::operation::FullyConnectedNode; graph.addOperation(nnfw::make_unique(node_param)); @@ -322,7 +322,7 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SOFTMAX: { - using GraphNode = neurun::graph::operation::Softmax::Node; + using GraphNode = neurun::graph::operation::SoftmaxNode; graph.addOperation(nnfw::make_unique(node_param)); diff --git a/runtimes/neurun/src/graph/dumper/Dumper.cc b/runtimes/neurun/src/graph/dumper/Dumper.cc index 6e10409..f21cde0 100644 --- a/runtimes/neurun/src/graph/dumper/Dumper.cc +++ b/runtimes/neurun/src/graph/dumper/Dumper.cc @@ -29,7 +29,7 @@ namespace dumper using namespace neurun::graph::operation; -void Dumper::visit(const Conv2D::Implicit::Node &node) +void Dumper::visit(const Conv2DNode &node) { VERBOSE(LIR) << "* Conv2D(Implicit)" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ") Kernel(" @@ -38,21 +38,21 @@ void Dumper::visit(const Conv2D::Implicit::Node &node) VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const MaxPool2D::Implicit::Node &node) +void Dumper::visit(const MaxPool2DNode &node) { VERBOSE(LIR) << "* MaxPool2D(Implicit)" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ")" << std::endl; VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const AvgPool2D::Implicit::Node &node) +void Dumper::visit(const AvgPool2DNode &node) { VERBOSE(LIR) << "* AvgPool2D(Implicit)" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ")" << std::endl; VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const Concat::Node &node) +void Dumper::visit(const ConcatNode &node) { VERBOSE(LIR) << "* Concat" << std::endl; std::string inputs; @@ -64,7 +64,7 @@ void Dumper::visit(const Concat::Node &node) VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const FullyConnected::Node &node) +void Dumper::visit(const FullyConnectedNode &node) { VERBOSE(LIR) << "* FullyConnected" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ") Weight(" @@ -73,7 +73,7 @@ void Dumper::visit(const FullyConnected::Node &node) VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const Reshape::Node &node) +void Dumper::visit(const ReshapeNode &node) { VERBOSE(LIR) << "* Reshape" << std::endl; // TODO The shape index should be "node.getInputs().at(1).value()" but not valid for now @@ -83,14 +83,14 @@ void Dumper::visit(const Reshape::Node &node) VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const Softmax::Node &node) +void Dumper::visit(const SoftmaxNode &node) { VERBOSE(LIR) << "* Softmax" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ")" << std::endl; VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } -void Dumper::visit(const NOP::Node &node) +void Dumper::visit(const NOPNode &node) { VERBOSE(LIR) << "* NOP" << std::endl; std::string inputs, outputs; @@ -106,7 +106,7 @@ void Dumper::visit(const NOP::Node &node) VERBOSE(LIR) << " - Outputs : OFM(" << outputs << ")" << std::endl; } -void Dumper::visit(const Permute::Node &node) +void Dumper::visit(const PermuteNode &node) { VERBOSE(LIR) << "* Permute" << std::endl; VERBOSE(LIR) << " - Inputs : IFM(" << node.getInputs().at(0).value() << ")" << std::endl; diff --git a/runtimes/neurun/src/graph/dumper/Dumper.h b/runtimes/neurun/src/graph/dumper/Dumper.h index 00fe9cd..d8ed270 100644 --- a/runtimes/neurun/src/graph/dumper/Dumper.h +++ b/runtimes/neurun/src/graph/dumper/Dumper.h @@ -32,15 +32,15 @@ public: Dumper() = default; public: - void visit(const graph::operation::Conv2D::Implicit::Node &node) override; - void visit(const graph::operation::MaxPool2D::Implicit::Node &node) override; - void visit(const graph::operation::AvgPool2D::Implicit::Node &node) override; - void visit(const graph::operation::Concat::Node &node) override; - void visit(const graph::operation::FullyConnected::Node &node) override; - void visit(const graph::operation::Reshape::Node &node) override; - void visit(const graph::operation::Softmax::Node &node) override; - void visit(const graph::operation::NOP::Node &node) override; - void visit(const graph::operation::Permute::Node &node) override; + void visit(const graph::operation::Conv2DNode &node) override; + void visit(const graph::operation::MaxPool2DNode &node) override; + void visit(const graph::operation::AvgPool2DNode &node) override; + void visit(const graph::operation::ConcatNode &node) override; + void visit(const graph::operation::FullyConnectedNode &node) override; + void visit(const graph::operation::ReshapeNode &node) override; + void visit(const graph::operation::SoftmaxNode &node) override; + void visit(const graph::operation::NOPNode &node) override; + void visit(const graph::operation::PermuteNode &node) override; void visit(const graph::operation::AddNode &node) override; }; diff --git a/runtimes/neurun/src/graph/operation/Add.h b/runtimes/neurun/src/graph/operation/Add.h index 252a262..de732a5 100644 --- a/runtimes/neurun/src/graph/operation/Add.h +++ b/runtimes/neurun/src/graph/operation/Add.h @@ -26,22 +26,22 @@ namespace graph namespace operation { -enum Input -{ - LHS = 0, - RHS -}; - -struct Param -{ - operand::Index activation_index; -}; - class AddNode : public graph::operation::Node { public: AddNode(const graph::operation::Node::InitParam &init_param); + enum Input + { + LHS = 0, + RHS + }; + + struct Param + { + operand::Index activation_index; + }; + public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "Add"; } diff --git a/runtimes/neurun/src/graph/operation/AvgPool2D.cc b/runtimes/neurun/src/graph/operation/AvgPool2D.cc index 8150d32..2ae767e 100644 --- a/runtimes/neurun/src/graph/operation/AvgPool2D.cc +++ b/runtimes/neurun/src/graph/operation/AvgPool2D.cc @@ -27,14 +27,10 @@ namespace graph { namespace operation { -namespace AvgPool2D -{ -namespace Implicit -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void AvgPool2DNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +AvgPool2DNode::AvgPool2DNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(1u)} { assert(init_param.input_count == 7); @@ -62,8 +58,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.activation_index = operand::Index{init_param.inputs[6]}; } -} // namespace Implicit -} // namespace AvgPool2D } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/AvgPool2D.h b/runtimes/neurun/src/graph/operation/AvgPool2D.h index 8f4c455..2a4f4cb 100644 --- a/runtimes/neurun/src/graph/operation/AvgPool2D.h +++ b/runtimes/neurun/src/graph/operation/AvgPool2D.h @@ -27,32 +27,28 @@ namespace graph { namespace operation { -namespace AvgPool2D -{ -namespace Implicit -{ -enum Input +class AvgPool2DNode : public graph::operation::Node { - INPUT = 0 -}; +public: + AvgPool2DNode(const graph::operation::Node::InitParam &init_param); -struct Param -{ - operand::Index kw_index; - operand::Index kh_index; + enum Input + { + INPUT = 0 + }; - operand::Index hstride_index; - operand::Index vstride_index; + struct Param + { + operand::Index kw_index; + operand::Index kh_index; - operand::Index padding_index; - operand::Index activation_index; -}; + operand::Index hstride_index; + operand::Index vstride_index; -class Node : public graph::operation::Node -{ -public: - Node(const graph::operation::Node::InitParam &init_param); + operand::Index padding_index; + operand::Index activation_index; + }; public: virtual void accept(NodeVisitor &&) const override; @@ -65,8 +61,6 @@ private: Param _param; }; -} // namespace Implicit -} // namespace AvgPool2D } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Concat.cc b/runtimes/neurun/src/graph/operation/Concat.cc index 255b710..e9c6efb 100644 --- a/runtimes/neurun/src/graph/operation/Concat.cc +++ b/runtimes/neurun/src/graph/operation/Concat.cc @@ -27,12 +27,10 @@ namespace graph { namespace operation { -namespace Concat -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void ConcatNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +ConcatNode::ConcatNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createAtLeast(2u)} { assert(init_param.input_count >= 2); // At least one one input tensor and axis @@ -57,7 +55,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.axis_index = operand::Index{init_param.inputs[init_param.input_count - 1]}; } -} // namespace Concat } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Concat.h b/runtimes/neurun/src/graph/operation/Concat.h index 7710d46..f9ac208 100644 --- a/runtimes/neurun/src/graph/operation/Concat.h +++ b/runtimes/neurun/src/graph/operation/Concat.h @@ -27,18 +27,16 @@ namespace graph { namespace operation { -namespace Concat -{ -struct Param -{ - operand::Index axis_index; -}; - -class Node : public graph::operation::Node +class ConcatNode : public graph::operation::Node { public: - Node(const graph::operation::Node::InitParam &init_param); + ConcatNode(const graph::operation::Node::InitParam &init_param); + + struct Param + { + operand::Index axis_index; + }; public: virtual void accept(NodeVisitor &&) const override; @@ -51,7 +49,6 @@ private: Param _param; }; -} // namespace Concat } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Conv2D.cc b/runtimes/neurun/src/graph/operation/Conv2D.cc index 4a248c7..0c35e81 100644 --- a/runtimes/neurun/src/graph/operation/Conv2D.cc +++ b/runtimes/neurun/src/graph/operation/Conv2D.cc @@ -27,14 +27,10 @@ namespace graph { namespace operation { -namespace Conv2D -{ -namespace Implicit -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void Conv2DNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +Conv2DNode::Conv2DNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(3u)} { assert(init_param.input_count == 7 && init_param.output_count == 1); @@ -59,8 +55,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.activation_index = operand::Index{init_param.inputs[6]}; } -} // namespace Implicit -} // namespace Conv2D } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Conv2D.h b/runtimes/neurun/src/graph/operation/Conv2D.h index b0eec01..3bb4cc4 100644 --- a/runtimes/neurun/src/graph/operation/Conv2D.h +++ b/runtimes/neurun/src/graph/operation/Conv2D.h @@ -27,31 +27,27 @@ namespace graph { namespace operation { -namespace Conv2D -{ -namespace Implicit -{ -enum Input +class Conv2DNode : public graph::operation::Node { - INPUT = 0, - KERNEL, - BIAS -}; +public: + Conv2DNode(const graph::operation::Node::InitParam &); -struct Param -{ - operand::Index hstride_index; - operand::Index vstride_index; + enum Input + { + INPUT = 0, + KERNEL, + BIAS + }; - operand::Index padding_index; - operand::Index activation_index; -}; + struct Param + { + operand::Index hstride_index; + operand::Index vstride_index; -class Node : public graph::operation::Node -{ -public: - Node(const graph::operation::Node::InitParam &); + operand::Index padding_index; + operand::Index activation_index; + }; public: virtual void accept(NodeVisitor &&) const override; @@ -64,9 +60,7 @@ private: Param _param; }; -} // namespace Implicit -} // namespace Conv2D -} // namespace coperation +} // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/FullyConnected.cc b/runtimes/neurun/src/graph/operation/FullyConnected.cc index 601436c..6b081ac 100644 --- a/runtimes/neurun/src/graph/operation/FullyConnected.cc +++ b/runtimes/neurun/src/graph/operation/FullyConnected.cc @@ -27,12 +27,10 @@ namespace graph { namespace operation { -namespace FullyConnected -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void FullyConnectedNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +FullyConnectedNode::FullyConnectedNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(3u)} { assert(init_param.input_count == 4 && init_param.output_count == 1); @@ -50,7 +48,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.activation_index = operand::Index{init_param.inputs[3]}; } -} // namespace FullyConnected } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/FullyConnected.h b/runtimes/neurun/src/graph/operation/FullyConnected.h index 2c28452..73dc991 100644 --- a/runtimes/neurun/src/graph/operation/FullyConnected.h +++ b/runtimes/neurun/src/graph/operation/FullyConnected.h @@ -27,25 +27,23 @@ namespace graph { namespace operation { -namespace FullyConnected -{ -enum Input +class FullyConnectedNode : public graph::operation::Node { - INPUT = 0, - WEIGHT, - BIAS -}; +public: + FullyConnectedNode(const graph::operation::Node::InitParam &init_param); -struct Param -{ - operand::Index activation_index; -}; + enum Input + { + INPUT = 0, + WEIGHT, + BIAS + }; -class Node : public graph::operation::Node -{ -public: - Node(const graph::operation::Node::InitParam &init_param); + struct Param + { + operand::Index activation_index; + }; public: virtual void accept(NodeVisitor &&) const override; @@ -58,7 +56,6 @@ private: Param _param; }; -} // namespace FullyConnected } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/MaxPool2D.cc b/runtimes/neurun/src/graph/operation/MaxPool2D.cc index fe5507b..5b1485c 100644 --- a/runtimes/neurun/src/graph/operation/MaxPool2D.cc +++ b/runtimes/neurun/src/graph/operation/MaxPool2D.cc @@ -27,14 +27,10 @@ namespace graph { namespace operation { -namespace MaxPool2D -{ -namespace Implicit -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void MaxPool2DNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +MaxPool2DNode::MaxPool2DNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(1u)} { assert(init_param.input_count == 7); @@ -62,8 +58,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.activation_index = operand::Index{init_param.inputs[6]}; } -} // namespace Implicit -} // namespace MaxPool2D } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/MaxPool2D.h b/runtimes/neurun/src/graph/operation/MaxPool2D.h index d626ec5..5e8e9f2 100644 --- a/runtimes/neurun/src/graph/operation/MaxPool2D.h +++ b/runtimes/neurun/src/graph/operation/MaxPool2D.h @@ -27,46 +27,40 @@ namespace graph { namespace operation { -namespace MaxPool2D -{ -namespace Implicit -{ -enum Input +class MaxPool2DNode : public graph::operation::Node { - INPUT = 0 -}; +public: + MaxPool2DNode(const graph::operation::Node::InitParam &init_param); -struct Param -{ - operand::Index kw_index; - operand::Index kh_index; + enum Input + { + INPUT = 0 + }; - operand::Index hstride_index; - operand::Index vstride_index; + struct Param + { + operand::Index kw_index; + operand::Index kh_index; - operand::Index padding_index; - operand::Index activation_index; -}; + operand::Index hstride_index; + operand::Index vstride_index; + + operand::Index padding_index; + operand::Index activation_index; + }; -class Node : public graph::operation::Node -{ public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "MaxPool2D"; } public: - Node(const graph::operation::Node::InitParam &init_param); - -public: const Param ¶m() const { return _param; } private: Param _param; }; -} // namespace Implicit -} // namespace MaxPool2D } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/NOP.cc b/runtimes/neurun/src/graph/operation/NOP.cc index 008320d..41a43b7 100644 --- a/runtimes/neurun/src/graph/operation/NOP.cc +++ b/runtimes/neurun/src/graph/operation/NOP.cc @@ -25,17 +25,14 @@ namespace graph { namespace operation { -namespace NOP -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void NOPNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &) +NOPNode::NOPNode(const graph::operation::Node::InitParam &) : operation::Node{OperandConstraint::createExact(1u)} { } -} // namespace NOP } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/NOP.h b/runtimes/neurun/src/graph/operation/NOP.h index 193c5d4..3f22829 100644 --- a/runtimes/neurun/src/graph/operation/NOP.h +++ b/runtimes/neurun/src/graph/operation/NOP.h @@ -27,20 +27,17 @@ namespace graph { namespace operation { -namespace NOP -{ -class Node : public graph::operation::Node +class NOPNode : public graph::operation::Node { public: - Node(const graph::operation::Node::InitParam &); + NOPNode(const graph::operation::Node::InitParam &); public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "NOP"; } }; -} // namespace NOP } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/NodeVisitor.h b/runtimes/neurun/src/graph/operation/NodeVisitor.h index 9738948..0f2e7ec 100644 --- a/runtimes/neurun/src/graph/operation/NodeVisitor.h +++ b/runtimes/neurun/src/graph/operation/NodeVisitor.h @@ -39,15 +39,15 @@ struct NodeVisitor { virtual ~NodeVisitor() = default; - virtual void visit(const Conv2D::Implicit::Node &) = 0; - virtual void visit(const MaxPool2D::Implicit::Node &) = 0; - virtual void visit(const AvgPool2D::Implicit::Node &) = 0; - virtual void visit(const Concat::Node &) = 0; - virtual void visit(const Reshape::Node &) = 0; - virtual void visit(const FullyConnected::Node &) = 0; - virtual void visit(const Softmax::Node &) = 0; - virtual void visit(const NOP::Node &) = 0; - virtual void visit(const Permute::Node &) = 0; + virtual void visit(const Conv2DNode &) = 0; + virtual void visit(const MaxPool2DNode &) = 0; + virtual void visit(const AvgPool2DNode &) = 0; + virtual void visit(const ConcatNode &) = 0; + virtual void visit(const ReshapeNode &) = 0; + virtual void visit(const FullyConnectedNode &) = 0; + virtual void visit(const SoftmaxNode &) = 0; + virtual void visit(const NOPNode &) = 0; + virtual void visit(const PermuteNode &) = 0; virtual void visit(const AddNode &) = 0; }; diff --git a/runtimes/neurun/src/graph/operation/Op.lst b/runtimes/neurun/src/graph/operation/Op.lst index 23b4123..763815f 100644 --- a/runtimes/neurun/src/graph/operation/Op.lst +++ b/runtimes/neurun/src/graph/operation/Op.lst @@ -20,11 +20,11 @@ // NOTE The relation between "Internal Name" and "NN API Name" is "1 : N". -// Internal Name | NN API Name -OP(Conv2D::Implicit , CONV_2D) -OP(AvgPool2D::Implicit , AVERAGE_POOL_2D) -OP(MaxPool2D::Implicit , MAX_POOL_2D) -OP(Concat , CONCATENATION) -OP(FullyConnected , FULLY_CONNECTED) -OP(Reshape , RESHAPE) -OP(Softmax , SOFTMAX) +// Internal Name | NN API Name +OP(Conv2DNode , CONV_2D) +OP(AvgPool2DNode , AVERAGE_POOL_2D) +OP(MaxPool2DNode , MAX_POOL_2D) +OP(ConcatNode , CONCATENATION) +OP(FullyConnectedNode , FULLY_CONNECTED) +OP(ReshapeNode , RESHAPE) +OP(SoftmaxNode , SOFTMAX) diff --git a/runtimes/neurun/src/graph/operation/Permute.cc b/runtimes/neurun/src/graph/operation/Permute.cc index 30a2a1a..ae475cb 100644 --- a/runtimes/neurun/src/graph/operation/Permute.cc +++ b/runtimes/neurun/src/graph/operation/Permute.cc @@ -26,19 +26,16 @@ namespace graph { namespace operation { -namespace Permute -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void PermuteNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const operand::Index &input, const operand::Index &output) +PermuteNode::PermuteNode(const operand::Index &input, const operand::Index &output) : operation::Node{OperandConstraint::createExact(1u)} { setInputs({input}); setOutputs({output}); } -} // namespace Permute } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Permute.h b/runtimes/neurun/src/graph/operation/Permute.h index 1ebbbee..c496722 100644 --- a/runtimes/neurun/src/graph/operation/Permute.h +++ b/runtimes/neurun/src/graph/operation/Permute.h @@ -25,20 +25,17 @@ namespace graph { namespace operation { -namespace Permute -{ -class Node : public graph::operation::Node +class PermuteNode : public graph::operation::Node { public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "Permute"; } public: - Node(const operand::Index &input, const operand::Index &output); + PermuteNode(const operand::Index &input, const operand::Index &output); }; -} // namespace Permute } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Reshape.cc b/runtimes/neurun/src/graph/operation/Reshape.cc index 5367b0a..6656abb 100644 --- a/runtimes/neurun/src/graph/operation/Reshape.cc +++ b/runtimes/neurun/src/graph/operation/Reshape.cc @@ -27,12 +27,10 @@ namespace graph { namespace operation { -namespace Reshape -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void ReshapeNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +ReshapeNode::ReshapeNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(1u)} { assert(init_param.input_count == 2 && init_param.output_count == 1); @@ -48,7 +46,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) setOutputs({init_param.outputs[0]}); } -} // namespace Reshape } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Reshape.h b/runtimes/neurun/src/graph/operation/Reshape.h index 3959007..eb90a5a 100644 --- a/runtimes/neurun/src/graph/operation/Reshape.h +++ b/runtimes/neurun/src/graph/operation/Reshape.h @@ -27,25 +27,22 @@ namespace graph { namespace operation { -namespace Reshape -{ -enum Input +class ReshapeNode : public graph::operation::Node { - INPUT = 0 -}; +public: + ReshapeNode(const graph::operation::Node::InitParam &init_param); + + enum Input + { + INPUT = 0 + }; -class Node : public graph::operation::Node -{ public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "Reshape"; } - -public: - Node(const graph::operation::Node::InitParam &init_param); }; -} // namespace Reshape } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Softmax.cc b/runtimes/neurun/src/graph/operation/Softmax.cc index 82b4bfe..3368da3 100644 --- a/runtimes/neurun/src/graph/operation/Softmax.cc +++ b/runtimes/neurun/src/graph/operation/Softmax.cc @@ -27,12 +27,10 @@ namespace graph { namespace operation { -namespace Softmax -{ -void Node::accept(NodeVisitor &&v) const { v.visit(*this); } +void SoftmaxNode::accept(NodeVisitor &&v) const { v.visit(*this); } -Node::Node(const graph::operation::Node::InitParam &init_param) +SoftmaxNode::SoftmaxNode(const graph::operation::Node::InitParam &init_param) : operation::Node{OperandConstraint::createExact(1u)} { assert(init_param.input_count == 2 && init_param.output_count == 1); @@ -48,7 +46,6 @@ Node::Node(const graph::operation::Node::InitParam &init_param) _param.scale_index = operand::Index{init_param.inputs[1]}; } -} // namespace Softmax } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Softmax.h b/runtimes/neurun/src/graph/operation/Softmax.h index 8fc8ae8..0037648 100644 --- a/runtimes/neurun/src/graph/operation/Softmax.h +++ b/runtimes/neurun/src/graph/operation/Softmax.h @@ -27,36 +27,32 @@ namespace graph { namespace operation { -namespace Softmax -{ -enum Input +class SoftmaxNode : public graph::operation::Node { - INPUT = 0 -}; +public: + SoftmaxNode(const graph::operation::Node::InitParam &init_param); + enum Input + { + INPUT = 0 + }; -struct Param -{ - operand::Index scale_index; -}; + struct Param + { + operand::Index scale_index; + }; -class Node : public graph::operation::Node -{ public: virtual void accept(NodeVisitor &&) const override; virtual std::string getName() const override { return "SoftMax"; } public: - Node(const graph::operation::Node::InitParam &init_param); - -public: const Param ¶m() const { return _param; } private: Param _param; }; -} // namespace Softmax } // namespace operation } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc b/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc index 329f53d..e64f5e5 100644 --- a/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc +++ b/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc @@ -140,7 +140,7 @@ operation::Index PermutationInsertionPass::insertPermute(const operand::Index &o operand.lower_info()->addUseBackend(operand.lower_info()->def_backends().getOnlyElement()); // Insert permute operation to the graph - auto insert_node = nnfw::make_unique(operand_index, out_operand_index); + auto insert_node = nnfw::make_unique(operand_index, out_operand_index); insert_node->lower_info( nnfw::make_unique(_graph.backend_resolver()->getDefaultBackend())); diff --git a/runtimes/neurun/test/graph/operation/SetIO.cc b/runtimes/neurun/test/graph/operation/SetIO.cc index c0a0c90..2f2289f 100644 --- a/runtimes/neurun/test/graph/operation/SetIO.cc +++ b/runtimes/neurun/test/graph/operation/SetIO.cc @@ -45,7 +45,7 @@ TEST(graph_operation_setIO, operation_setIO_conv) } uint32_t outoperand = graph.addOperand(shape, type).asInt(); - using GraphNode = neurun::graph::operation::Conv2D::Implicit::Node; + using GraphNode = neurun::graph::operation::Conv2DNode; auto conv = nnfw::make_unique(GraphNodeInitParam{7, params.data(), 1, &outoperand}); ASSERT_EQ(conv->getInputs().at(Index{0}).asInt(), params[0]); @@ -70,7 +70,7 @@ TEST(graph_operation_setIO, operation_setIO_concat) } uint32_t outoperand = graph.addOperand(shape, type).asInt(); - using GraphNode = neurun::graph::operation::Concat::Node; + using GraphNode = neurun::graph::operation::ConcatNode; auto concat = nnfw::make_unique(GraphNodeInitParam{7, params.data(), 1, &outoperand}); -- 2.7.4