From 3177861f8145640761e8184017f4836255a7c293 Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Fri, 12 Nov 2021 17:33:45 +0000 Subject: Fix PostOp dependency In general src headers should not be included in any public header of other modules. Since there are modules (graph, tests) that rely on specific PostOp definitions in the previous src/core/experimental/PostOp.h, export it to the public arm_compute header Resolves COMPMID-4974 Signed-off-by: SiCongLi Change-Id: I0fa4da5108a34fe6bfff1e9d57839da4e51dc314 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6673 Reviewed-by: Gunes Bayir Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- arm_compute/core/experimental/PostOps.h | 162 +++++++++++++++++++++++++++ arm_compute/graph/backends/FunctionHelpers.h | 2 + 2 files changed, 164 insertions(+) create mode 100644 arm_compute/core/experimental/PostOps.h (limited to 'arm_compute') diff --git a/arm_compute/core/experimental/PostOps.h b/arm_compute/core/experimental/PostOps.h new file mode 100644 index 0000000000..4ea90fc348 --- /dev/null +++ b/arm_compute/core/experimental/PostOps.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_EXPERIMENTAL_POSTOPS +#define ARM_COMPUTE_EXPERIMENTAL_POSTOPS + +#include "arm_compute/core/experimental/IPostOp.h" + +#include "arm_compute/core/Types.h" + +#include + +namespace arm_compute +{ +namespace experimental +{ +/** (EXPERIMENTAL_POST_OPS) + * Implementation of specific IPostOps +*/ + +template +struct PostOpAct : public IPostOp +{ +public: + PostOpAct(const ActivationLayerInfo &act_info) + : _act_info{ act_info } + { + } + // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy + ~PostOpAct() override = default; + PostOpAct(const PostOpAct &) = default; + PostOpAct &operator=(const PostOpAct &) = default; + PostOpAct(PostOpAct &&) = default; + PostOpAct &operator=(PostOpAct &&) = default; + + int prev_dst_pos() const override + { + return 0; + } + PostOpType type() const override + { + return PostOpType::Activation; + } + std::vector arguments() override + { + return {}; + } + std::vector arguments() const override + { + return {}; + } + std::unique_ptr> clone() const override + { + return std::make_unique>(*this); + } + ActivationLayerInfo _act_info; +}; + +template +struct PostOpEltwiseAdd : public IPostOp +{ +public: + PostOpEltwiseAdd(TensorRelatedT addend, int prev_dst_pos, ConvertPolicy policy) + : _addend{ addend }, + _prev_dst_pos{ prev_dst_pos }, + _policy{ policy } + { + } + // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy + ~PostOpEltwiseAdd() override = default; + PostOpEltwiseAdd(const PostOpEltwiseAdd &) = default; + PostOpEltwiseAdd &operator=(const PostOpEltwiseAdd &) = default; + PostOpEltwiseAdd(PostOpEltwiseAdd &&) = default; + PostOpEltwiseAdd &operator=(PostOpEltwiseAdd &&) = default; + int prev_dst_pos() const override + { + return _prev_dst_pos; + } + PostOpType type() const override + { + return PostOpType::Eltwise_Add; + } + std::vector arguments() override + { + return { &_addend }; + } + std::vector arguments() const override + { + return { &_addend }; + } + std::unique_ptr> clone() const override + { + return std::make_unique>(*this); + } + TensorRelatedT _addend; + int _prev_dst_pos; + ConvertPolicy _policy; +}; + +template +struct PostOpEltwisePRelu : public IPostOp +{ +public: + PostOpEltwisePRelu(TensorRelatedT alpha_param, int prev_dst_pos, ConvertPolicy policy) + : _alpha_param{ alpha_param }, + _prev_dst_pos{ prev_dst_pos }, + _policy{ policy } + { + } + // NOTE: PostOps do not own any resources pointed to by TensorRelatedT if it's a pointer type, thus allow shallow copy + ~PostOpEltwisePRelu() override = default; + PostOpEltwisePRelu(const PostOpEltwisePRelu &) = default; + PostOpEltwisePRelu &operator=(const PostOpEltwisePRelu &) = default; + PostOpEltwisePRelu(PostOpEltwisePRelu &&) = default; + PostOpEltwisePRelu &operator=(PostOpEltwisePRelu &&) = default; + int prev_dst_pos() const override + { + return _prev_dst_pos; + } + PostOpType type() const override + { + return PostOpType::Eltwise_PRelu; + } + std::vector arguments() override + { + return { &_alpha_param }; + } + std::vector arguments() const override + { + return { &_alpha_param }; + } + std::unique_ptr> clone() const override + { + return std::make_unique>(*this); + } + TensorRelatedT _alpha_param; + int _prev_dst_pos; + ConvertPolicy _policy; +}; +} // namespace experimental +} // namespace arm_compute +#endif //ARM_COMPUTE_EXPERIMENTAL_POSTOPS \ No newline at end of file diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h index 55af056a43..1e420a803f 100644 --- a/arm_compute/graph/backends/FunctionHelpers.h +++ b/arm_compute/graph/backends/FunctionHelpers.h @@ -24,6 +24,8 @@ #ifndef ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H #define ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H +#include "arm_compute/core/experimental/IPostOp.h" +#include "arm_compute/core/experimental/PostOps.h" #include "arm_compute/graph/Logger.h" #include "arm_compute/graph/Tensor.h" #include "arm_compute/graph/TypePrinter.h" -- cgit v1.2.1