Add CL Kernel calls for Equal op from runtime. (#3107)
authorPrasanna R/System SW /SRI-Bangalore/Engineer/삼성전자 <prasanna.r@samsung.com>
Fri, 19 Oct 2018 00:26:05 +0000 (05:56 +0530)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 19 Oct 2018 00:26:05 +0000 (09:26 +0900)
This patch adds CL Kernel calls for Equal op from runtime.

Signed-off-by: prasannar <prasanna.r@samsung.com>
runtimes/pure_arm_compute/src/compilation.cc

index 229683f..97fd4e4 100644 (file)
@@ -57,6 +57,7 @@
 #include <arm_compute/runtime/CL/functions/CLNormalizationLayerEx.h>
 #include <arm_compute/runtime/CL/functions/CLExp.h>
 #include <arm_compute/runtime/CL/functions/CLBatchToSpaceND.h>
+#include <arm_compute/runtime/CL/functions/CLEqual.h>
 #include <arm_compute/runtime/CL/functions/CLSquaredDifference.h>
 #include <arm_compute/runtime/CL/functions/CLNeg.h>
 
@@ -3456,9 +3457,58 @@ void Planner::visit(const ::internal::tflite::op::RSQRT::Node &node)
 
 void Planner::visit(const ::internal::tflite::op::Equal::Node &node)
 {
-  VERBOSE(Equal) << "Configure Equal operation" << std::endl;
+  const ::internal::tflite::operand::Index output_index{node.param().output_index};
+  const ::internal::tflite::operand::Index input1_index{node.param().input1_index};
+  const ::internal::tflite::operand::Index input2_index{node.param().input2_index};
 
-  throw std::runtime_error("Not supported, yet");
+  // Set Shape Constraints and TensorInfo
+  _builder.addShapeConstr(output_index,
+                          asTensorInfo(asTensorShape(_ctx.at(output_index).shape(), false),
+                                       _ctx.at(output_index).type(), _ctx.at(output_index).scale(),
+                                       _ctx.at(output_index).zeroPoint()));
+  _builder.addShapeConstr(input1_index,
+                          asTensorInfo(asTensorShape(_ctx.at(input1_index).shape(), false),
+                                       _ctx.at(input1_index).type(), _ctx.at(input1_index).scale(),
+                                       _ctx.at(input1_index).zeroPoint()));
+  _builder.addShapeConstr(input2_index,
+                          asTensorInfo(asTensorShape(_ctx.at(input2_index).shape(), false),
+                                       _ctx.at(input2_index).type(), _ctx.at(input2_index).scale(),
+                                       _ctx.at(input2_index).zeroPoint()));
+
+  // Construct operation parameters
+  struct Param
+  {
+    int output_index;
+    int input1_index;
+    int input2_index;
+  };
+
+  Param param;
+
+  param.output_index = output_index.asInt();
+  param.input1_index = input1_index.asInt();
+  param.input2_index = input2_index.asInt();
+  auto stage = [param](const IAllocationContext &ctx, IExecutionBuilder &builder) {
+    auto output_alloc = ctx.at(::internal::tflite::operand::Index{param.output_index});
+    auto input1_alloc = ctx.at(::internal::tflite::operand::Index{param.input1_index});
+    auto input2_alloc = ctx.at(::internal::tflite::operand::Index{param.input2_index});
+
+    if (::internal::arm_compute::isGpuMode())
+    {
+      auto fn = nnfw::make_unique<::arm_compute::CLEqual>();
+
+      fn->configure(CAST_CL(input1_alloc), CAST_CL(input2_alloc), CAST_CL(output_alloc));
+
+      builder.append("Equal", std::move(fn));
+    }
+    else
+    {
+      // TODO Add NEON support
+
+      throw std::runtime_error("Not supported, yet");
+    }
+  };
+  _builder.addStage(stage);
 }
 
 void Planner::visit(const ::internal::tflite::op::TransposeConv::Node &node)