[PACL] Support ABS_EX op (#4334)
author장지섭/On-Device Lab(SR)/Engineer/삼성전자 <jiseob.jang@samsung.com>
Mon, 28 Jan 2019 10:01:06 +0000 (19:01 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 28 Jan 2019 10:01:06 +0000 (19:01 +0900)
This commit supports ABS_EX operation for PACL.

Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
runtimes/pure_arm_compute/src/compilation.cc

index 73a08da..36d9c5e 100644 (file)
@@ -5704,8 +5704,58 @@ void Planner::visit(const ::internal::tflite::op::ReduceSum::Node &node)
 
 void Planner::visit(const ::internal::tflite::op::Abs::Node &node)
 {
-  // TODO Implement Abs op
-  throw std::runtime_error("Not supported yet");
+  VERBOSE(Tanh) << "Configure Abs operation" << std::endl;
+
+  const ::internal::tflite::operand::Index output_index{node.param().output_index};
+  const ::internal::tflite::operand::Index input_index{node.param().input_index};
+
+  // Set shape constraints
+  _builder.addShapeConstr(output_index,
+                          asTensorInfo(asTensorShape(_ctx.at(output_index).shape()),
+                                       _ctx.at(output_index).type(), _ctx.at(output_index).scale(),
+                                       _ctx.at(output_index).zeroPoint()));
+  _builder.addShapeConstr(input_index,
+                          asTensorInfo(asTensorShape(_ctx.at(input_index).shape()),
+                                       _ctx.at(input_index).type(), _ctx.at(output_index).scale(),
+                                       _ctx.at(output_index).zeroPoint()));
+
+  struct Param
+  {
+    int output_index;
+    int input_index;
+  };
+
+  Param param;
+
+  param.output_index = output_index.asInt();
+  param.input_index = input_index.asInt();
+
+  auto stage = [param](const IAllocationContext &ctx, IExecutionBuilder &builder) {
+    auto output_alloc = ctx.at(::internal::tflite::operand::Index{param.output_index});
+    auto input_alloc = ctx.at(::internal::tflite::operand::Index{param.input_index});
+
+    const ::arm_compute::ActivationLayerInfo act_info{
+        ::arm_compute::ActivationLayerInfo::ActivationFunction::ABS};
+
+    if (::internal::arm_compute::isGpuMode())
+    {
+      auto fn = nnfw::cpp14::make_unique<::arm_compute::CLActivationLayer>();
+
+      fn->configure(CAST_CL(input_alloc), CAST_CL(output_alloc), act_info);
+
+      builder.append("Abs", std::move(fn));
+    }
+    else
+    {
+      auto fn = nnfw::cpp14::make_unique<::arm_compute::NEActivationLayer>();
+
+      fn->configure(input_alloc, output_alloc, act_info);
+
+      builder.append("Abs", std::move(fn));
+    }
+  };
+
+  _builder.addStage(stage);
 }
 
 void Planner::visit(const ::internal::tflite::op::NotEqual::Node &node)