From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Fri, 19 Oct 2018 01:33:41 +0000 (+0900) Subject: [neurun] Introduce Add operation (#3246) X-Git-Tag: 0.3~567 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58afa72fb764446d88e8f56ff5c6dfb43228fc25;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce Add operation (#3246) * [neurun] Introduce Add operation This commit introduces Add operation. For neurun we avoid adding operations before we fix the API for the backends, however this is an exception for testing broadcast Add. Backend implementations are NYI. Signed-off-by: Hanjoung Lee * Throw `std::runtime_error` --- diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc index 569ba6b..4a70e48 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc @@ -542,6 +542,13 @@ Stage StageGenerator::generate(const graph::operation::Permute::Node & /* node * throw "Unsupported"; } +Stage StageGenerator::generate(const graph::operation::Add::Node &) +{ + VERBOSE(Add) << "generate CPU Add" << std::endl; + + throw std::runtime_error("NYI"); +} + } // namespace acl_cl } // namespace backend } // namespace neurun diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.h b/runtimes/neurun/src/backend/acl_cl/StageGenerator.h index 11b900d..a230720 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.h +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.h @@ -46,6 +46,7 @@ public: 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::Add::Node &node) override; 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 ed7fcdb..50761ad 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.cc +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.cc @@ -599,6 +599,13 @@ Stage StageGenerator::generate(const graph::operation::Permute::Node &node) }; } +Stage StageGenerator::generate(const graph::operation::Add::Node &) +{ + VERBOSE(Add) << "generate CPU Add" << std::endl; + + throw std::runtime_error("NYI"); +} + } // namespace neurun } // namespace backend } // namespace cpu diff --git a/runtimes/neurun/src/backend/cpu/StageGenerator.h b/runtimes/neurun/src/backend/cpu/StageGenerator.h index 8aa62b8..0ba088a 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.h +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.h @@ -47,6 +47,7 @@ public: 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::Add::Node &node) override; private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/backend/interface/IStageGenerator.h b/runtimes/neurun/src/backend/interface/IStageGenerator.h index 657ab6f..cf16c71 100644 --- a/runtimes/neurun/src/backend/interface/IStageGenerator.h +++ b/runtimes/neurun/src/backend/interface/IStageGenerator.h @@ -32,6 +32,7 @@ #include "graph/operation/Softmax.h" #include "graph/operation/NOP.h" #include "graph/operation/Permute.h" +#include "graph/operation/Add.h" struct IExecutionBuilder { @@ -62,6 +63,7 @@ struct IStageGenerator 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::Add::Node &node) = 0; }; } // namespace backend diff --git a/runtimes/neurun/src/codegen/Planner.cc b/runtimes/neurun/src/codegen/Planner.cc index 54578a4..3463060 100644 --- a/runtimes/neurun/src/codegen/Planner.cc +++ b/runtimes/neurun/src/codegen/Planner.cc @@ -170,5 +170,17 @@ void Planner::visit(const graph::operation::Permute::Node &node) _builder.addStage(stage_gen->generate(node)); } +void Planner::visit(const graph::operation::Add::Node &node) +{ + VERBOSE(Add) << "Configure Add operation" << std::endl; + + // backend + auto backend = node.lower_info()->backend(); + + // Generate Stage + auto stage_gen = backend->stage_gen(); + _builder.addStage(stage_gen->generate(node)); +} + } // namespace codegen } // namespace neurun diff --git a/runtimes/neurun/src/codegen/Planner.h b/runtimes/neurun/src/codegen/Planner.h index d725567..0156f42 100644 --- a/runtimes/neurun/src/codegen/Planner.h +++ b/runtimes/neurun/src/codegen/Planner.h @@ -55,6 +55,7 @@ public: 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::Add::Node &) override; private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/graph/dumper/Dumper.cc b/runtimes/neurun/src/graph/dumper/Dumper.cc index 3788317..0b2a99f 100644 --- a/runtimes/neurun/src/graph/dumper/Dumper.cc +++ b/runtimes/neurun/src/graph/dumper/Dumper.cc @@ -113,6 +113,14 @@ void Dumper::visit(const Permute::Node &node) VERBOSE(LIR) << " - Output : OFM(" << node.getOutputs().at(0).value() << ")" << std::endl; } +void Dumper::visit(const Add::Node &node) +{ + VERBOSE(LIR) << "* Add" << std::endl; + VERBOSE(LIR) << " - Inputs : Input(" << node.getInputs().at(0).value() << ", " + << node.getInputs().at(1).value() << ")" << std::endl; + VERBOSE(LIR) << " - Output : Output(" << node.getOutputs().at(0).value() << ")" << std::endl; +} + } // namespace dumper } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/dumper/Dumper.h b/runtimes/neurun/src/graph/dumper/Dumper.h index dee490c..393fc93 100644 --- a/runtimes/neurun/src/graph/dumper/Dumper.h +++ b/runtimes/neurun/src/graph/dumper/Dumper.h @@ -41,6 +41,7 @@ public: 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::Add::Node &node) override; }; } // namespace dumper diff --git a/runtimes/neurun/src/graph/operation/Add.cc b/runtimes/neurun/src/graph/operation/Add.cc new file mode 100644 index 0000000..eaf633d --- /dev/null +++ b/runtimes/neurun/src/graph/operation/Add.cc @@ -0,0 +1,36 @@ +#include "Add.h" + +#include + +#include "NodeVisitor.h" + +namespace neurun +{ +namespace graph +{ +namespace operation +{ +namespace Add +{ + +void Node::accept(NodeVisitor &&v) const { v.visit(*this); } + +Node::Node(const graph::operation::Node::InitParam &init_param) + : operation::Node{OperandConstraint::createEQ(2u)} +{ + assert(init_param.input_count == 2); + assert(init_param.output_count == 1); + + // Each input should be interpreted as follows: + // + // 0 -> Lefthand side operand + // 1 -> Righthand side operand + + setInputs({init_param.inputs[0], init_param.inputs[1]}); + setOutputs({init_param.outputs[0]}); +} + +} // namespace Add +} // namespace operation +} // namespace graph +} // namespace neurun diff --git a/runtimes/neurun/src/graph/operation/Add.h b/runtimes/neurun/src/graph/operation/Add.h new file mode 100644 index 0000000..26a4e90 --- /dev/null +++ b/runtimes/neurun/src/graph/operation/Add.h @@ -0,0 +1,41 @@ +#ifndef __NEURUN_GRAPH_OPERATION_ADD_H__ +#define __NEURUN_GRAPH_OPERATION_ADD_H__ + +#include "graph/operation/Node.h" + +namespace neurun +{ +namespace graph +{ +namespace operation +{ +namespace Add +{ + +enum Input +{ + LHS = 0, + RHS +}; + +struct Param +{ + operand::Index activation_index; +}; + +class Node : public graph::operation::Node +{ +public: + Node(const graph::operation::Node::InitParam &init_param); + +public: + virtual void accept(NodeVisitor &&) const override; + virtual std::string getName() const override { return "Add"; } +}; + +} // namespace Add +} // namespace operation +} // namespace graph +} // namespace neurun + +#endif // __NEURUN_GRAPH_OPERATION_ADD_H__ diff --git a/runtimes/neurun/src/graph/operation/NodeVisitor.h b/runtimes/neurun/src/graph/operation/NodeVisitor.h index 28d19b0..a7349a7 100644 --- a/runtimes/neurun/src/graph/operation/NodeVisitor.h +++ b/runtimes/neurun/src/graph/operation/NodeVisitor.h @@ -26,6 +26,7 @@ #include "Softmax.h" #include "NOP.h" #include "Permute.h" +#include "Add.h" namespace neurun { @@ -47,6 +48,7 @@ struct NodeVisitor 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 Add::Node &) = 0; }; } // namespace operation