Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / Neg.cpp
index eae787a..3f08df3 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
- * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#include "kernels/Neg.h"
+#include "Builders.h"
 #include "kernels/Utils.h"
 
+#include "kernels/BinaryOpCommon.h"
+
 #include "PALNeg.h"
 
 namespace luci_interpreter
 {
 
-namespace kernels
+void configure_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
 {
+  const auto input_index = cur_op->inputs()->operator[](0);
+  const auto output_index = cur_op->outputs()->operator[](0);
 
-Neg::Neg(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {}
+  assert(input_index != -1);
+  assert(output_index != -1);
+
+  const auto input = runtime_graph->getCircleTensorByIndex(input_index);
+  const auto output = runtime_graph->getCircleTensorByIndex(output_index);
+
+  LUCI_INTERPRETER_CHECK(Tensor::element_type(input) == Tensor::element_type(output));
+
+  assert(Tensor::num_dims(input) == 4);
 
-void Neg::configure()
-{
-  LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
   // TODO: enable it only if kernel with dynamic shapes
-  output()->resize(input()->shape());
+  // output-> resize(input->shape());
 }
 
-void Neg::execute() const
+void execute_kernel_CircleNeg(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
 {
-  switch (input()->element_type())
+  const auto input_index = cur_op->inputs()->operator[](0);
+  const auto output_index = cur_op->outputs()->operator[](0);
+
+  assert(input_index != -1);
+  assert(output_index != -1);
+
+  const auto input = runtime_graph->getCircleTensorByIndex(input_index);
+  const auto output = runtime_graph->getCircleTensorByIndex(output_index);
+
+  const uint8_t *input_data = runtime_graph->getDataByTensor(input);
+  uint8_t *output_data = runtime_graph->getDataByTensor(output);
+
+  assert(input_data != nullptr);
+  assert(output_data != nullptr);
+
+  switch (Tensor::element_type(input))
   {
+#ifndef DIS_FLOAT
     case DataType::FLOAT32:
-      evalFloat();
+
+      luci_interpreter_pal::Negate(
+        kernels::getTensorShape(input), kernels::getTensorData<float>(input_data),
+        kernels::getTensorShape(output), kernels::getTensorData<float>(output_data));
+
       break;
+#endif // DIS_FLOAT
     default:
       assert(false && "Unsupported type.");
   }
 }
 
-void Neg::evalFloat() const
-{
-  luci_interpreter_pal::Negate(getTensorShape(input()), getTensorData<float>(input()),
-                               getTensorShape(output()), getTensorData<float>(output()));
-}
-
-} // namespace kernels
 } // namespace luci_interpreter