[enco] Extend backend for ReLU6 (#2265)
author남궁석/동작제어Lab(SR)/Engineer/삼성전자 <sk.namkoong@samsung.com>
Wed, 14 Nov 2018 03:53:07 +0000 (12:53 +0900)
committer박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 14 Nov 2018 03:53:07 +0000 (12:53 +0900)
This commit will extend the backend of enco for ReLU6

Signed-off-by: Seok NamKoong <sk.namkoong@samsung.com>
contrib/enco/core/src/ANN/IR/Operation.def
contrib/enco/core/src/Transforms/Split.cpp

index 6a4d1fa..56b2e5c 100644 (file)
@@ -10,4 +10,5 @@ ANN_OPERATION(DEPTHWISE_CONV_2D, ANEURALNETWORKS_DEPTHWISE_CONV_2D)
 ANN_OPERATION(MAX_POOL_2D, ANEURALNETWORKS_MAX_POOL_2D)
 ANN_OPERATION(AVG_POOL_2D, ANEURALNETWORKS_AVERAGE_POOL_2D)
 ANN_OPERATION(RELU, ANEURALNETWORKS_RELU)
+ANN_OPERATION(RELU6, ANEURALNETWORKS_RELU6)
 ANN_OPERATION(PAD, ANEURALNETWORKS_PAD)
index dba8172..178ffab 100644 (file)
@@ -330,6 +330,26 @@ private:
   coco::FeatureObject *_ofm;
 };
 
+class ANNReLU6Appender final : public ANNOpAppender
+{
+public:
+  void ifm(coco::FeatureObject *ifm) { _ifm = ifm; }
+  void ofm(coco::FeatureObject *ofm) { _ofm = ofm; }
+
+public:
+  void append(ANNBinder *binder) const override
+  {
+    auto ifm = binder->addOperand<float>(_ifm);
+    auto ofm = binder->addOperand<float>(_ofm);
+
+    binder->addOperation(ann::Operation::Code::RELU6, {ifm}, {ofm});
+  }
+
+private:
+  coco::FeatureObject *_ifm;
+  coco::FeatureObject *_ofm;
+};
+
 class ANNMaxPool2DAppender final : public ANNOpAppender
 {
 public:
@@ -717,6 +737,28 @@ public:
         return std::move(app);
       }
     }
+    else if (auto relu6 = eval->op()->asReLU6())
+    {
+      if (auto load = relu->arg()->asLoad())
+      {
+        // Let's compile the following code fragment:
+        //
+        //   %ofm = eval(ReLU6(Load(%ifm))
+        //
+        // TODO Support objects of other kinds, such as Tensor
+        auto ifm = load->object()->asFeature();
+        auto ofm = eval->out()->asFeature();
+
+        assert(ifm != nullptr && ofm != nullptr);
+
+        auto app = make_unique<ANNReLUAppender>();
+
+        app->ifm(ifm);
+        app->ofm(ofm);
+
+        return std::move(app);
+      }
+    }
 
     // Return nullptr if a given Eval instruction is incompatible
     return nullptr;