From 1af5416917268692fcd4b34b1d7ffebd3a2aea8a Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Wed, 6 Oct 2021 15:25:57 +0100 Subject: Add experimental PostOp interface to ClGemmMatrixMultiplyReshapedKernel Part 1 This interface supports the fusion of multiple elementwise operations Partially resolves: COMPMID-4435 Change-Id: If68dd7dd98dcf239fde7cb1f0a4a6d4d1e899a6f Signed-off-by: SiCongLi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6483 Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice Comments-Addressed: Arm Jenkins --- tests/validation/reference/PostOps.cpp | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/validation/reference/PostOps.cpp (limited to 'tests/validation/reference/PostOps.cpp') diff --git a/tests/validation/reference/PostOps.cpp b/tests/validation/reference/PostOps.cpp new file mode 100644 index 0000000000..1a8fb990c8 --- /dev/null +++ b/tests/validation/reference/PostOps.cpp @@ -0,0 +1,76 @@ +/* + * 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. + */ +#include "PostOps.h" + +#include "arm_compute/core/Helpers.h" +#include "arm_compute/core/Types.h" +#include "src/core/experimental/PostOp.h" +#include "tests/validation/reference/ActivationLayer.h" +#include "tests/validation/reference/ElementwiseOperations.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type> +SimpleTensor post_ops(const SimpleTensor &a, experimental::PostOpList> post_ops) +{ + // Create reference + SimpleTensor dst{ a }; + + for(auto &post_op : post_ops.get_list()) + { + switch(post_op->type()) + { + case experimental::PostOpType::Activation: + { + const auto _post_op = utils::cast::polymorphic_downcast> *>(post_op.get()); + dst = reference::activation_layer(dst, _post_op->_act_info); + break; + } + case experimental::PostOpType::Eltwise_Add: + { + const auto _post_op = utils::cast::polymorphic_downcast> *>(post_op.get()); + dst = reference::arithmetic_operation(ArithmeticOperation::ADD, dst, _post_op->_addend, dst, _post_op->_policy); + break; + } + default: + { + ARM_COMPUTE_ERROR("Unsupported PostOpType"); + } + } + } + return dst; +} + +template SimpleTensor post_ops(const SimpleTensor &a, experimental::PostOpList> post_ops); +template SimpleTensor post_ops(const SimpleTensor &a, experimental::PostOpList> post_ops); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute \ No newline at end of file -- cgit v1.2.1