From 2c4ec1a3c65fc14bc940d5c686eaf39586e755d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=88=98=EC=A7=84/=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: Tue, 21 Aug 2018 15:06:40 +0900 Subject: [PATCH] [neurun] Introduce NOP operation (#2382) This commit introduces NOP operation to do nothing. (Actually it needs the tensor copy into other indexes. but not now.) In this PR, the NOP operation doesn't anything, it's just the operation for graph manipulation test. Signed-off-by: sjsujinkim --- runtimes/neurun/src/backend/IStageGenerator.h | 2 + .../neurun/src/backend/acl_cl/StageGenerator.cc | 5 ++ .../neurun/src/backend/acl_cl/StageGenerator.h | 1 + runtimes/neurun/src/backend/cpu/StageGenerator.cc | 5 ++ runtimes/neurun/src/backend/cpu/StageGenerator.h | 1 + runtimes/neurun/src/codegen/Dumper.cc | 16 +++++++ runtimes/neurun/src/codegen/Dumper.h | 1 + runtimes/neurun/src/codegen/Planner.cc | 6 +++ runtimes/neurun/src/codegen/Planner.h | 1 + runtimes/neurun/src/codegen/TensorMarker.cc | 5 ++ runtimes/neurun/src/codegen/TensorMarker.h | 1 + runtimes/neurun/src/graph/operation/NOP.cc | 37 +++++++++++++++ runtimes/neurun/src/graph/operation/NOP.h | 37 +++++++++++++++ runtimes/neurun/src/internal/op/NOP.cc | 37 +++++++++++++++ runtimes/neurun/src/internal/op/NOP.h | 54 ++++++++++++++++++++++ runtimes/neurun/src/internal/op/NodeVisitor.h | 2 + 16 files changed, 211 insertions(+) create mode 100644 runtimes/neurun/src/graph/operation/NOP.cc create mode 100644 runtimes/neurun/src/graph/operation/NOP.h create mode 100644 runtimes/neurun/src/internal/op/NOP.cc create mode 100644 runtimes/neurun/src/internal/op/NOP.h diff --git a/runtimes/neurun/src/backend/IStageGenerator.h b/runtimes/neurun/src/backend/IStageGenerator.h index 80bc03a..b1e9de1 100644 --- a/runtimes/neurun/src/backend/IStageGenerator.h +++ b/runtimes/neurun/src/backend/IStageGenerator.h @@ -14,6 +14,7 @@ #include "internal/op/FullyConnected.h" #include "internal/op/Reshape.h" #include "internal/op/Softmax.h" +#include "internal/op/NOP.h" struct IExecutionBuilder { @@ -48,6 +49,7 @@ struct IStageGenerator virtual Stage generate(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) = 0; virtual Stage generate(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) = 0; + virtual Stage generate(const ::internal::tflite::op::NOP::Node &node) = 0; }; } // namespace backend diff --git a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc index 60d71b5..b588c24 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.cc @@ -599,6 +599,11 @@ Stage StageGenerator::generate(const ::internal::tflite::op::TensorConvert::AclT }; } +Stage StageGenerator::generate(const ::internal::tflite::op::NOP::Node &node) +{ + // DO NOTHING +} + } // 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 94ad8a3..358a0b4 100644 --- a/runtimes/neurun/src/backend/acl_cl/StageGenerator.h +++ b/runtimes/neurun/src/backend/acl_cl/StageGenerator.h @@ -38,6 +38,7 @@ public: generate(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override; virtual Stage generate(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override; + virtual Stage generate(const ::internal::tflite::op::NOP::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 e71dec1..9695604 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.cc +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.cc @@ -596,6 +596,11 @@ Stage StageGenerator::generate(const ::internal::tflite::op::TensorConvert::AclT throw std::runtime_error("Wrong Approach"); } +Stage StageGenerator::generate(const ::internal::tflite::op::NOP::Node &node) +{ + // DO NOTHING +} + } // 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 2022b1d..ef47539 100644 --- a/runtimes/neurun/src/backend/cpu/StageGenerator.h +++ b/runtimes/neurun/src/backend/cpu/StageGenerator.h @@ -40,6 +40,7 @@ public: generate(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override; virtual Stage generate(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override; + virtual Stage generate(const ::internal::tflite::op::NOP::Node &node) override; private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/codegen/Dumper.cc b/runtimes/neurun/src/codegen/Dumper.cc index 0c04202..61e105e 100644 --- a/runtimes/neurun/src/codegen/Dumper.cc +++ b/runtimes/neurun/src/codegen/Dumper.cc @@ -94,5 +94,21 @@ void Dumper::visit(const TensorConvert::AclToCommon::Node &node) // NOTE No details for this node. Soon will be removed. } +void Dumper::visit(const NOP::Node &node) +{ + VERBOSE(LIR) << "* NOP" << std::endl; + std::string inputs, outputs; + for (auto i : node.param().ifm_indexes) + { + inputs += std::to_string(i) + ","; + } + VERBOSE(LIR) << " - Inputs : IFM(" << inputs << ")" << std::endl; + for (auto i : node.param().ofm_indexes) + { + outputs += std::to_string(i) + ","; + } + VERBOSE(LIR) << " - Outputs : OFM(" << outputs << ")" << std::endl; +} + } // namespace codegen } // namespace neurun diff --git a/runtimes/neurun/src/codegen/Dumper.h b/runtimes/neurun/src/codegen/Dumper.h index 5aa3f61..ab95702 100644 --- a/runtimes/neurun/src/codegen/Dumper.h +++ b/runtimes/neurun/src/codegen/Dumper.h @@ -25,6 +25,7 @@ public: void visit(const ::internal::tflite::op::TensorConvert::CpuToCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override; + void visit(const ::internal::tflite::op::NOP::Node &node) override; }; } // namespace codegen diff --git a/runtimes/neurun/src/codegen/Planner.cc b/runtimes/neurun/src/codegen/Planner.cc index 2d1a3f6..9e08939 100644 --- a/runtimes/neurun/src/codegen/Planner.cc +++ b/runtimes/neurun/src/codegen/Planner.cc @@ -229,5 +229,11 @@ void Planner::visit(const ::internal::tflite::op::TensorConvert::AclToCommon::No _builder.addStage(stage_gen->generate(node)); } +void Planner::visit(const ::internal::tflite::op::NOP::Node &node) +{ + // DO NOTHING + // TODO : It's just for graph manipulation test now, it should be added tensor copy stage later. +} + } // namespace codegen } // namespace neurun diff --git a/runtimes/neurun/src/codegen/Planner.h b/runtimes/neurun/src/codegen/Planner.h index b2d1ebf..1db33a8 100644 --- a/runtimes/neurun/src/codegen/Planner.h +++ b/runtimes/neurun/src/codegen/Planner.h @@ -43,6 +43,7 @@ public: void visit(const ::internal::tflite::op::TensorConvert::CpuToCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override; + void visit(const ::internal::tflite::op::NOP::Node &node) override; private: const neurun::graph::operand::Set &_ctx; diff --git a/runtimes/neurun/src/codegen/TensorMarker.cc b/runtimes/neurun/src/codegen/TensorMarker.cc index 87d0e68..f064034 100644 --- a/runtimes/neurun/src/codegen/TensorMarker.cc +++ b/runtimes/neurun/src/codegen/TensorMarker.cc @@ -101,5 +101,10 @@ void TensorMarker::visit(const ::internal::tflite::op::TensorConvert::AclToCommo // DO NOTHING } +void TensorMarker::visit(const ::internal::tflite::op::NOP::Node &node) +{ + // DO NOTHING +} + } // namespace codegen } // namespace neurun diff --git a/runtimes/neurun/src/codegen/TensorMarker.h b/runtimes/neurun/src/codegen/TensorMarker.h index cb596fd..d11c7fb 100644 --- a/runtimes/neurun/src/codegen/TensorMarker.h +++ b/runtimes/neurun/src/codegen/TensorMarker.h @@ -29,6 +29,7 @@ public: void visit(const ::internal::tflite::op::TensorConvert::CpuToCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override; void visit(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override; + void visit(const ::internal::tflite::op::NOP::Node &node) override; private: void mark(int32_t ind) { _tensor_builder.mark(::neurun::graph::operand::Index{ind}); } diff --git a/runtimes/neurun/src/graph/operation/NOP.cc b/runtimes/neurun/src/graph/operation/NOP.cc new file mode 100644 index 0000000..66afdaf --- /dev/null +++ b/runtimes/neurun/src/graph/operation/NOP.cc @@ -0,0 +1,37 @@ +#include "NOP.h" + +namespace neurun +{ +namespace graph +{ +namespace operation +{ +namespace NOP +{ + +operand::IndexSet Node::inputs() const +{ + operand::IndexSet set; + for (auto index : _op->param().ifm_indexes) + { + operand::Index ind{index}; + set.append({ind}); + } + return set; +} + +operand::IndexSet Node::outputs() const +{ + operand::IndexSet set; + for (auto index : _op->param().ofm_indexes) + { + operand::Index ind{index}; + set.append({ind}); + } + return set; +} + +} // 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 new file mode 100644 index 0000000..8d038e6 --- /dev/null +++ b/runtimes/neurun/src/graph/operation/NOP.h @@ -0,0 +1,37 @@ +#ifndef __NEURUN_GRAPH_OPERATION_NOP_H__ +#define __NEURUN_GRAPH_OPERATION_NOP_H__ + +#include + +#include "graph/operation/Node.h" +#include "internal/op/NOP.h" + +namespace neurun +{ +namespace graph +{ +namespace operation +{ +namespace NOP +{ + +class Node : public graph::operation::Node +{ +public: + Node(std::unique_ptr<::internal::tflite::op::NOP::Node> &&op) : _op{std::move(op)} {} + +public: + virtual operand::IndexSet inputs() const override; + virtual operand::IndexSet outputs() const override; + virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); } + +private: + std::unique_ptr<::internal::tflite::op::NOP::Node> _op; +}; + +} // namespace NOP +} // namespace operation +} // namespace graph +} // namespace neurun + +#endif // __NEURUN_GRAPH_OPERATION_NOP_H__ diff --git a/runtimes/neurun/src/internal/op/NOP.cc b/runtimes/neurun/src/internal/op/NOP.cc new file mode 100644 index 0000000..5ee59b5 --- /dev/null +++ b/runtimes/neurun/src/internal/op/NOP.cc @@ -0,0 +1,37 @@ +#include "internal/op/NOP.h" +#include "internal/op/NodeVisitor.h" + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace NOP +{ + +void Node::accept(NodeVisitor &&v) const { v.visit(*this); } + +} // namespace NOP +} // namespace op +} // namespace tflite +} // namespace internal + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace NOP +{ + +Param::Param(std::initializer_list ifm_indexes, std::initializer_list ofm_indexes) + : ifm_indexes(ifm_indexes), ofm_indexes(ofm_indexes) +{ +} + +} // namespace NOP +} // namespace op +} // namespace tflite +} // namespace internal diff --git a/runtimes/neurun/src/internal/op/NOP.h b/runtimes/neurun/src/internal/op/NOP.h new file mode 100644 index 0000000..95043ad --- /dev/null +++ b/runtimes/neurun/src/internal/op/NOP.h @@ -0,0 +1,54 @@ +#ifndef __INTERNAL_OP_NOP_H__ +#define __INTERNAL_OP_NOP_H__ + +#include "internal/op/Node.h" + +#include +#include +#include + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace NOP +{ + +struct Param +{ + std::vector ifm_indexes; + std::vector ofm_indexes; + + Param() = default; + Param(std::initializer_list ifm_indexes, std::initializer_list ofm_indexes); +}; + +class Node final : public op::Node +{ +public: + Node(const Param ¶m) : _param(param) + { + // DO NOTHING + } + +public: + virtual ~Node() = default; + +public: + const Param ¶m(void) const { return _param; } + +public: + void accept(NodeVisitor &&) const override; + +private: + const Param _param; +}; + +} // namespace NOP +} // namespace op +} // namespace tflite +} // namespace internal + +#endif // __INTERNAL_OP_NOP_H__ diff --git a/runtimes/neurun/src/internal/op/NodeVisitor.h b/runtimes/neurun/src/internal/op/NodeVisitor.h index c837f58..3a9a63c 100644 --- a/runtimes/neurun/src/internal/op/NodeVisitor.h +++ b/runtimes/neurun/src/internal/op/NodeVisitor.h @@ -10,6 +10,7 @@ #include "internal/op/Softmax.h" #include "internal/op/TensorConvert_Cpu.h" #include "internal/op/TensorConvert_Acl.h" +#include "internal/op/NOP.h" namespace internal { @@ -33,6 +34,7 @@ struct NodeVisitor virtual void visit(const TensorConvert::CpuToCommon::Node &) = 0; virtual void visit(const TensorConvert::AclFromCommon::Node &) = 0; virtual void visit(const TensorConvert::AclToCommon::Node &) = 0; + virtual void visit(const NOP::Node &) = 0; }; } // namespace op -- 2.7.4