From: Андрей Шедько/AI Tools Lab /SRR/Assistant Engineer/삼성전자 Date: Wed, 5 Sep 2018 18:06:05 +0000 (+0300) Subject: [nnc]Visitor improvement Pure Virtual Methods to Virtual (#1303) X-Git-Tag: nncc_backup~1928 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e68413f4e6b79be46bfa1513f5d9ccd78ce68a23;p=platform%2Fcore%2Fml%2Fnnfw.git [nnc]Visitor improvement Pure Virtual Methods to Virtual (#1303) changed visitor's methods from pure virtual to virtual Signed-off-by: Andrei Shedko --- diff --git a/contrib/nnc/core/modelIR/graph.cpp b/contrib/nnc/core/modelIR/graph.cpp index 319895e..cde3665 100644 --- a/contrib/nnc/core/modelIR/graph.cpp +++ b/contrib/nnc/core/modelIR/graph.cpp @@ -31,7 +31,7 @@ INode::Ref Graph::getOutput(const std::string &name) { return it->second; } -void Graph::accept(Visitor *visitor) { +void Graph::accept(IVisitor *visitor) { std::deque q; std::set known_nodes; diff --git a/contrib/nnc/core/modelIR/visitor.cpp b/contrib/nnc/core/modelIR/visitor.cpp new file mode 100644 index 0000000..090c96a --- /dev/null +++ b/contrib/nnc/core/modelIR/visitor.cpp @@ -0,0 +1,25 @@ +#include "core/modelIR/visitor.h" + +namespace nncc { +namespace contrib { +namespace core { +namespace IR { +namespace model { + +void Visitor::visit(ADT::INode *node, ops::ConcatOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::Conv2DOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::DepthwiseConv2DOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::SoftmaxOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::PoolOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::FullyConnectedOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::CappedReluOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::BiasAddOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::VariableOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::ReluOp &op) {(void)node; (void)op;}; +void Visitor::visit(ADT::INode *node, ops::ReshapeOp &op) {(void)node; (void)op;}; + +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc diff --git a/contrib/nnc/include/core/modelIR/ShapeInference.h b/contrib/nnc/include/core/modelIR/ShapeInference.h index d9dbce9..18ade01 100644 --- a/contrib/nnc/include/core/modelIR/ShapeInference.h +++ b/contrib/nnc/include/core/modelIR/ShapeInference.h @@ -18,7 +18,7 @@ namespace model using namespace nncc::contrib::core::IR::model; -class ShapeInference : public Visitor { +class ShapeInference : public IVisitor { public: static const auto AUTO_DIM = std::numeric_limits::max(); diff --git a/contrib/nnc/include/core/modelIR/graph.h b/contrib/nnc/include/core/modelIR/graph.h index b36aac5..de31bc2 100644 --- a/contrib/nnc/include/core/modelIR/graph.h +++ b/contrib/nnc/include/core/modelIR/graph.h @@ -21,7 +21,7 @@ namespace IR namespace model { using ADT::INode; -class Visitor; +class IVisitor; class Graph { public: @@ -38,7 +38,7 @@ class Graph { return node; } - void accept(Visitor *visitor); + void accept(IVisitor *visitor); void markOutput(INode::Ref node); INode::Ref getInput(const std::string &name); diff --git a/contrib/nnc/include/core/modelIR/ir_dot_dumper.h b/contrib/nnc/include/core/modelIR/ir_dot_dumper.h index 17829cb..2de6102 100644 --- a/contrib/nnc/include/core/modelIR/ir_dot_dumper.h +++ b/contrib/nnc/include/core/modelIR/ir_dot_dumper.h @@ -33,7 +33,7 @@ using namespace nncc::contrib::core::IR::model; * @breif Model IR visitor that can be used to output Model IR as a .dot graph. * @usage Run on a Model IR graph as a visitor, and then call writeDot passing it a stream */ -class IrDotDumper : public Visitor +class IrDotDumper : public IVisitor { public: void visit(INode *node, ops::ConcatOp &op) override; diff --git a/contrib/nnc/include/core/modelIR/ir_node.h b/contrib/nnc/include/core/modelIR/ir_node.h index a8d7948..bea7a7a 100644 --- a/contrib/nnc/include/core/modelIR/ir_node.h +++ b/contrib/nnc/include/core/modelIR/ir_node.h @@ -43,7 +43,7 @@ public: virtual const std::string &getName() const = 0; virtual void setName(const std::string &name) = 0; - virtual void accept(Visitor *v) = 0; + virtual void accept(IVisitor *v) = 0; virtual const IODescriptor getOutput(const size_t index) = 0; virtual void connectInputTo(const int inputIndex, const IODescriptor &descriptor) = 0; @@ -110,7 +110,7 @@ public: void setName(const std::string &name) override { _props.name = name; } - void accept(Visitor *v) override + void accept(IVisitor *v) override { v->visit(this, *static_cast(_props.op)); } diff --git a/contrib/nnc/include/core/modelIR/visitor.h b/contrib/nnc/include/core/modelIR/visitor.h index 189cd3c..cf6f9ae 100644 --- a/contrib/nnc/include/core/modelIR/visitor.h +++ b/contrib/nnc/include/core/modelIR/visitor.h @@ -28,7 +28,10 @@ namespace ops class ReshapeOp; } -class Visitor { +/** + * @brief Visitor Interface declaration + */ +class IVisitor { public: virtual void visit(ADT::INode *node, ops::ConcatOp &op) = 0; virtual void visit(ADT::INode *node, ops::Conv2DOp &op) = 0; @@ -40,9 +43,31 @@ class Visitor { virtual void visit(ADT::INode *node, ops::BiasAddOp &op) = 0; virtual void visit(ADT::INode *node, ops::VariableOp &op) = 0; virtual void visit(ADT::INode *node, ops::ReluOp &op) = 0; - virtual void visit(ADT::INode* node, ops::ReshapeOp &op) = 0; + virtual void visit(ADT::INode *node, ops::ReshapeOp &op) = 0; - virtual ~Visitor() = default; + virtual ~IVisitor() = default; +}; + +/** + * @brief Non Pure Virtual implementation of IVisitor + * It is used to facilitate adding new operations, + * so that we don't have to add more declarations and + * only need to define an implementation of `visit` for a subset of operations in the graph, + * while not doing anything for all others. + */ +class Visitor: public IVisitor{ +public: + void visit(ADT::INode *node, ops::ConcatOp &op) override; + void visit(ADT::INode *node, ops::Conv2DOp &op) override; + void visit(ADT::INode *node, ops::DepthwiseConv2DOp &op) override; + void visit(ADT::INode *node, ops::SoftmaxOp &op) override; + void visit(ADT::INode *node, ops::PoolOp &op) override; + void visit(ADT::INode *node, ops::FullyConnectedOp &op) override; + void visit(ADT::INode *node, ops::CappedReluOp &op) override; + void visit(ADT::INode *node, ops::BiasAddOp &op) override; + void visit(ADT::INode *node, ops::VariableOp &op) override; + void visit(ADT::INode *node, ops::ReluOp &op) override; + void visit(ADT::INode *node, ops::ReshapeOp &op) override; }; } // namespace model diff --git a/contrib/nnc/include/plugin/interpreter/Interpreter.h b/contrib/nnc/include/plugin/interpreter/Interpreter.h index e2f6c45..cd2a255 100644 --- a/contrib/nnc/include/plugin/interpreter/Interpreter.h +++ b/contrib/nnc/include/plugin/interpreter/Interpreter.h @@ -26,7 +26,7 @@ using namespace nncc::contrib::core::IR::model; using nncc::contrib::core::data::Index; using nncc::contrib::core::data::Tensor; -class NNInterpreter : public Visitor +class NNInterpreter : public IVisitor { public: explicit NNInterpreter() = default; diff --git a/contrib/nnc/plugin/soft_backend/model_analyzer.h b/contrib/nnc/plugin/soft_backend/model_analyzer.h index 2a9ba14..458ae73 100644 --- a/contrib/nnc/plugin/soft_backend/model_analyzer.h +++ b/contrib/nnc/plugin/soft_backend/model_analyzer.h @@ -27,7 +27,7 @@ namespace ops = model::ops; const size_t INVALID_TENSOR_ID = std::numeric_limits::max(); -class ModelAnalyzer: public model::Visitor +class ModelAnalyzer: public model::IVisitor { public: void visit(ADT::INode *node, ops::ConcatOp &op) override; diff --git a/contrib/nnc/plugin/soft_backend/serializer.h b/contrib/nnc/plugin/soft_backend/serializer.h index 3b498d0..0c15098 100644 --- a/contrib/nnc/plugin/soft_backend/serializer.h +++ b/contrib/nnc/plugin/soft_backend/serializer.h @@ -22,7 +22,7 @@ namespace model = nncc::contrib::core::IR::model; namespace ADT = model::ADT; namespace ops = model::ops; -class Serializer: public model::Visitor +class Serializer: public model::IVisitor { public: