From 396201101c5533267e2b0e7fc41c1a5887b3092e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Siva=20Sai=20Vaddipati/System=20SW=20/SRI-Bangalore/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 10 Oct 2018 18:12:18 +0530 Subject: [PATCH] Introduce Custom(Abs) op in runtime (#3035) This commit introduces Custom(Abs) op in PACL runtime. Related issue: #2828 Signed-off-by: Siva Sai --- runtimes/pure_arm_compute/src/compilation.cc | 7 +++ runtimes/pure_arm_compute/src/internal/op/Abs.cc | 59 +++++++++++++++++++ runtimes/pure_arm_compute/src/internal/op/Abs.h | 68 ++++++++++++++++++++++ .../pure_arm_compute/src/internal/op/NodeVisitor.h | 2 + runtimes/pure_arm_compute/src/model.cc | 12 ++++ 5 files changed, 148 insertions(+) create mode 100644 runtimes/pure_arm_compute/src/internal/op/Abs.cc create mode 100644 runtimes/pure_arm_compute/src/internal/op/Abs.h diff --git a/runtimes/pure_arm_compute/src/compilation.cc b/runtimes/pure_arm_compute/src/compilation.cc index 945adda..af062c8 100644 --- a/runtimes/pure_arm_compute/src/compilation.cc +++ b/runtimes/pure_arm_compute/src/compilation.cc @@ -509,6 +509,7 @@ public: void visit(const ::internal::tflite::op::ReduceSum::Node &node) override; void visit(const ::internal::tflite::op::Equal::Node &node) override; void visit(const ::internal::tflite::op::TransposeConv::Node &node) override; + void visit(const ::internal::tflite::op::Abs::Node &node) override; private: const ::internal::tflite::operand::Set &_ctx; @@ -4378,6 +4379,12 @@ void Planner::visit(const ::internal::tflite::op::ReduceSum::Node &node) _builder.addStage(stage); } +void Planner::visit(const ::internal::tflite::op::Abs::Node &node) +{ + // TODO Implement Abs op + throw std::runtime_error("Not supported yet"); +} + class AllocationContext final : public IAllocationContext { public: diff --git a/runtimes/pure_arm_compute/src/internal/op/Abs.cc b/runtimes/pure_arm_compute/src/internal/op/Abs.cc new file mode 100644 index 0000000..943899f --- /dev/null +++ b/runtimes/pure_arm_compute/src/internal/op/Abs.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "internal/op/Abs.h" +#include "internal/op/NodeVisitor.h" + +#include + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace Abs +{ + +void Node::accept(NodeVisitor &&v) const { v.visit(*this); } + +} // namespace Abs +} // namespace op +} // namespace tflite +} // namespace internal + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace Abs +{ + +Param::Param(uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, + const uint32_t *outputs) +{ + assert(inputCount == 1 && outputCount == 1); + + output_index = outputs[0]; + input_index = inputs[0]; +} + +} // namespace Abs +} // namespace op +} // namespace tflite +} // namespace internal diff --git a/runtimes/pure_arm_compute/src/internal/op/Abs.h b/runtimes/pure_arm_compute/src/internal/op/Abs.h new file mode 100644 index 0000000..3a47629 --- /dev/null +++ b/runtimes/pure_arm_compute/src/internal/op/Abs.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __INTERNAL_OP_ABS_H__ +#define __INTERNAL_OP_ABS_H__ + +#include "internal/op/Node.h" + +#include + +namespace internal +{ +namespace tflite +{ +namespace op +{ +namespace Abs +{ + +struct Param +{ + int32_t output_index; + int32_t input_index; + + Param() = default; + Param(uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs); +}; + +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 Abs +} // namespace op +} // namespace tflite +} // namespace internal + +#endif // __INTERNAL_OP_ABS_H__ diff --git a/runtimes/pure_arm_compute/src/internal/op/NodeVisitor.h b/runtimes/pure_arm_compute/src/internal/op/NodeVisitor.h index c7464cd..099c4f9 100644 --- a/runtimes/pure_arm_compute/src/internal/op/NodeVisitor.h +++ b/runtimes/pure_arm_compute/src/internal/op/NodeVisitor.h @@ -64,6 +64,7 @@ #include "internal/op/ReduceSum.h" #include "internal/op/Equal.h" #include "internal/op/TransposeConv.h" +#include "internal/op/Abs.h" namespace internal { @@ -128,6 +129,7 @@ struct NodeVisitor virtual void visit(const ReduceSum::Node &) = 0; virtual void visit(const Equal::Node &) = 0; virtual void visit(const TransposeConv::Node &) = 0; + virtual void visit(const Abs::Node &) = 0; }; } // namespace op diff --git a/runtimes/pure_arm_compute/src/model.cc b/runtimes/pure_arm_compute/src/model.cc index d37fdff..706c8e6 100644 --- a/runtimes/pure_arm_compute/src/model.cc +++ b/runtimes/pure_arm_compute/src/model.cc @@ -871,6 +871,18 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, break; } + case ANEURALNETWORKS_ABS_EX: + { + using internal::tflite::op::Abs::Param; + using internal::tflite::op::Abs::Node; + + // Add 'operations' + auto &operations = model->deref().operations(); + + operations.emplace_back(Param{inputCount, inputs, outputCount, outputs}); + + break; + } default: throw std::runtime_error{"Not supported operation"}; } -- 2.7.4