From cbf39c63a6eb89a2c80b2338afc374081803d79d Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 10 Sep 2018 15:07:45 +0100 Subject: COMPMID-1566: Add broadcast to CLArithmeticSubtraction Change-Id: I05d21f9a92013ecfd1128d12cf1561cfd6e5c5e9 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/147983 Tested-by: bsgcomp Reviewed-by: Anthony Barbier --- .../fixtures/ArithmeticAdditionFixture.h | 157 ---------------- .../fixtures/ArithmeticOperationsFixture.h | 201 +++++++++++++++++++++ .../fixtures/ArithmeticSubtractionFixture.h | 114 ------------ tests/validation/fixtures/LSTMLayerFixture.h | 21 +-- tests/validation/fixtures/RNNLayerFixture.h | 4 +- 5 files changed, 213 insertions(+), 284 deletions(-) delete mode 100644 tests/validation/fixtures/ArithmeticAdditionFixture.h create mode 100644 tests/validation/fixtures/ArithmeticOperationsFixture.h delete mode 100644 tests/validation/fixtures/ArithmeticSubtractionFixture.h (limited to 'tests/validation/fixtures') diff --git a/tests/validation/fixtures/ArithmeticAdditionFixture.h b/tests/validation/fixtures/ArithmeticAdditionFixture.h deleted file mode 100644 index 66875934de..0000000000 --- a/tests/validation/fixtures/ArithmeticAdditionFixture.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2017-2018 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_TEST_ARITHMETIC_ADDITION_FIXTURE -#define ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_FIXTURE - -#include "arm_compute/core/TensorShape.h" -#include "arm_compute/core/Types.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/IAccessor.h" -#include "tests/framework/Asserts.h" -#include "tests/framework/Fixture.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/ArithmeticAddition.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -template -class ArithmeticAdditionGenericFixture : public framework::Fixture -{ -public: - template - void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, - QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) - { - _target = compute_target(shape0, shape1, data_type0, data_type1, output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); - _reference = compute_reference(shape0, shape1, data_type0, data_type1, output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); - } - -protected: - template - void fill(U &&tensor, int i) - { - library->fill_tensor_uniform(tensor, i); - } - - TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, - QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) - { - // Create tensors - TensorType ref_src1 = create_tensor(shape0, data_type0, 1, qinfo0); - TensorType ref_src2 = create_tensor(shape1, data_type1, 1, qinfo1); - TensorType dst = create_tensor(TensorShape::broadcast_shape(shape0, shape1), output_data_type, 1, qinfo_out); - - // Create and configure function - FunctionType add; - add.configure(&ref_src1, &ref_src2, &dst, convert_policy); - - ARM_COMPUTE_EXPECT(ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Allocate tensors - ref_src1.allocator()->allocate(); - ref_src2.allocator()->allocate(); - dst.allocator()->allocate(); - - ARM_COMPUTE_EXPECT(!ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(!ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Fill tensors - fill(AccessorType(ref_src1), 0); - fill(AccessorType(ref_src2), 1); - - // Compute function - add.run(); - - return dst; - } - - SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, - DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, - QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) - { - // Create reference - SimpleTensor ref_src1{ shape0, data_type0, 1, qinfo0 }; - SimpleTensor ref_src2{ shape1, data_type1, 1, qinfo1 }; - SimpleTensor ref_dst{ TensorShape::broadcast_shape(shape0, shape1), output_data_type, 1, qinfo_out }; - - // Fill reference - fill(ref_src1, 0); - fill(ref_src2, 1); - - return reference::arithmetic_addition(ref_src1, ref_src2, ref_dst, convert_policy); - } - - TensorType _target{}; - SimpleTensor _reference{}; -}; - -template -class ArithmeticAdditionBroadcastValidationFixture : public ArithmeticAdditionGenericFixture -{ -public: - template - void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) - { - ArithmeticAdditionGenericFixture::setup(shape0, shape1, data_type0, data_type1, - output_data_type, convert_policy, QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); - } -}; - -template -class ArithmeticAdditionValidationFixture : public ArithmeticAdditionGenericFixture -{ -public: - template - void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) - { - ArithmeticAdditionGenericFixture::setup(shape, shape, data_type0, data_type1, - output_data_type, convert_policy, QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); - } -}; - -template -class ArithmeticAdditionValidationQuantizedFixture : public ArithmeticAdditionGenericFixture -{ -public: - template - void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, - QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) - - { - ArithmeticAdditionGenericFixture::setup(shape, shape, data_type0, data_type1, - output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); - } -}; -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_ARITHMETIC_ADDITION_FIXTURE */ diff --git a/tests/validation/fixtures/ArithmeticOperationsFixture.h b/tests/validation/fixtures/ArithmeticOperationsFixture.h new file mode 100644 index 0000000000..fb46a5185e --- /dev/null +++ b/tests/validation/fixtures/ArithmeticOperationsFixture.h @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2017-2018 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_TEST_ARITHMETIC_OPERATIONS_FIXTURE +#define ARM_COMPUTE_TEST_ARITHMETIC_OPERATIONS_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/ArithmeticOperations.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class ArithmeticOperationGenericFixture : public framework::Fixture +{ +public: + template + void setup(reference::ArithmeticOperation op, const TensorShape &shape0, const TensorShape &shape1, + DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + { + _op = op; + _target = compute_target(shape0, shape1, data_type0, data_type1, output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); + _reference = compute_reference(shape0, shape1, data_type0, data_type1, output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); + } + +protected: + template + void fill(U &&tensor, int i) + { + library->fill_tensor_uniform(tensor, i); + } + + TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + { + // Create tensors + TensorType ref_src1 = create_tensor(shape0, data_type0, 1, qinfo0); + TensorType ref_src2 = create_tensor(shape1, data_type1, 1, qinfo1); + TensorType dst = create_tensor(TensorShape::broadcast_shape(shape0, shape1), output_data_type, 1, qinfo_out); + + // Create and configure function + FunctionType arith_op; + arith_op.configure(&ref_src1, &ref_src2, &dst, convert_policy); + + ARM_COMPUTE_EXPECT(ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + ref_src1.allocator()->allocate(); + ref_src2.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(ref_src1), 0); + fill(AccessorType(ref_src2), 1); + + // Compute function + arith_op.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, + DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + { + // Create reference + SimpleTensor ref_src1{ shape0, data_type0, 1, qinfo0 }; + SimpleTensor ref_src2{ shape1, data_type1, 1, qinfo1 }; + SimpleTensor ref_dst{ TensorShape::broadcast_shape(shape0, shape1), output_data_type, 1, qinfo_out }; + + // Fill reference + fill(ref_src1, 0); + fill(ref_src2, 1); + + return reference::arithmetic_operation(_op, ref_src1, ref_src2, ref_dst, convert_policy); + } + + TensorType _target{}; + SimpleTensor _reference{}; + reference::ArithmeticOperation _op{ reference::ArithmeticOperation::ADD }; +}; + +template +class ArithmeticAdditionBroadcastValidationFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::ADD, shape0, shape1, data_type0, data_type1, + output_data_type, convert_policy, QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); + } +}; + +template +class ArithmeticAdditionValidationFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::ADD, shape, shape, data_type0, data_type1, + output_data_type, convert_policy, QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); + } +}; + +template +class ArithmeticAdditionValidationQuantizedFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::ADD, shape, shape, data_type0, data_type1, + output_data_type, convert_policy, qinfo0, qinfo1, qinfo_out); + } +}; + +template +class ArithmeticSubtractionBroadcastValidationFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::SUB, shape0, shape1, + data_type0, data_type1, output_data_type, convert_policy, + QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); + } +}; + +template +class ArithmeticSubtractionValidationFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::SUB, shape, shape, + data_type0, data_type1, output_data_type, convert_policy, + QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); + } +}; + +template +class ArithmeticSubtractionValidationQuantizedFixture : public ArithmeticOperationGenericFixture +{ +public: + template + void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + + { + ArithmeticOperationGenericFixture::setup(reference::ArithmeticOperation::SUB, shape, shape, + data_type0, data_type1, output_data_type, + convert_policy, qinfo0, qinfo1, qinfo_out); + } +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_ARITHMETIC_OPERATIONS_FIXTURE */ diff --git a/tests/validation/fixtures/ArithmeticSubtractionFixture.h b/tests/validation/fixtures/ArithmeticSubtractionFixture.h deleted file mode 100644 index 9897677691..0000000000 --- a/tests/validation/fixtures/ArithmeticSubtractionFixture.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2017-2018 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_TEST_ARITHMETIC_SUBTRACTION_FIXTURE -#define ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_FIXTURE - -#include "arm_compute/core/TensorShape.h" -#include "arm_compute/core/Types.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/IAccessor.h" -#include "tests/framework/Asserts.h" -#include "tests/framework/Fixture.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/ArithmeticSubtraction.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -template -class ArithmeticSubtractionValidationFixture : public framework::Fixture -{ -public: - template - void setup(TensorShape shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) - { - _target = compute_target(shape, data_type0, data_type1, output_data_type, convert_policy); - _reference = compute_reference(shape, data_type0, data_type1, output_data_type, convert_policy); - } - -protected: - template - void fill(U &&tensor, int i) - { - library->fill_tensor_uniform(tensor, i); - } - - TensorType compute_target(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) - { - // Create tensors - TensorType ref_src1 = create_tensor(shape, data_type0, 1); - TensorType ref_src2 = create_tensor(shape, data_type1, 1); - TensorType dst = create_tensor(shape, output_data_type, 1); - - // Create and configure function - FunctionType sub; - sub.configure(&ref_src1, &ref_src2, &dst, convert_policy); - - ARM_COMPUTE_EXPECT(ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Allocate tensors - ref_src1.allocator()->allocate(); - ref_src2.allocator()->allocate(); - dst.allocator()->allocate(); - - ARM_COMPUTE_EXPECT(!ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(!ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Fill tensors - fill(AccessorType(ref_src1), 0); - fill(AccessorType(ref_src2), 1); - - // Compute function - sub.run(); - - return dst; - } - - SimpleTensor compute_reference(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ConvertPolicy convert_policy) - { - // Create reference - SimpleTensor ref_src1{ shape, data_type0, 1 }; - SimpleTensor ref_src2{ shape, data_type1, 1 }; - - // Fill reference - fill(ref_src1, 0); - fill(ref_src2, 1); - - return reference::arithmetic_subtraction(ref_src1, ref_src2, output_data_type, convert_policy); - } - - TensorType _target{}; - SimpleTensor _reference{}; -}; -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_ARITHMETIC_SUBTRACTION_FIXTURE */ diff --git a/tests/validation/fixtures/LSTMLayerFixture.h b/tests/validation/fixtures/LSTMLayerFixture.h index 20df855242..bc892bfecf 100644 --- a/tests/validation/fixtures/LSTMLayerFixture.h +++ b/tests/validation/fixtures/LSTMLayerFixture.h @@ -28,8 +28,7 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" #include "tests/validation/reference/ActivationLayer.h" -#include "tests/validation/reference/ArithmeticAddition.h" -#include "tests/validation/reference/ArithmeticSubtraction.h" +#include "tests/validation/reference/ArithmeticOperations.h" #include "tests/validation/reference/FullyConnectedLayer.h" #include "tests/validation/reference/GEMM.h" #include "tests/validation/reference/PixelWiseMultiplication.h" @@ -333,12 +332,12 @@ protected: SimpleTensor fully_connected_forget = reference::fully_connected_layer(input, input_to_forget_w, forget_gate_bias, output_cell_shape); SimpleTensor transposed_weights = reference::transpose(recurrent_to_forget_w); SimpleTensor gemm = reference::gemm(output_state_in, transposed_weights, cell_state_in, 1.f, 0.f); - SimpleTensor forget_gate = reference::arithmetic_addition(fully_connected_forget, gemm, data_type, ConvertPolicy::SATURATE); + SimpleTensor forget_gate = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, fully_connected_forget, gemm, data_type, ConvertPolicy::SATURATE); if(peephole_opt) { SimpleTensor pixelwise_mul_forget_gate = reference::pixel_wise_multiplication(cell_state_in, cell_to_forget_w, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN); - forget_gate = reference::arithmetic_addition(forget_gate, pixelwise_mul_forget_gate, data_type, ConvertPolicy::SATURATE); + forget_gate = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, forget_gate, pixelwise_mul_forget_gate, data_type, ConvertPolicy::SATURATE); } forget_gate = reference::activation_layer(forget_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); @@ -349,18 +348,18 @@ protected: { SimpleTensor ones{ cell_bias_shape, data_type }; fill_custom_val(ones, 1.f, 0); - input_gate = reference::arithmetic_subtraction(ones, forget_gate, data_type, ConvertPolicy::SATURATE); + input_gate = reference::arithmetic_operation(reference::ArithmeticOperation::SUB, ones, forget_gate, data_type, ConvertPolicy::SATURATE); } else { SimpleTensor fully_connected_input = reference::fully_connected_layer(input, input_to_input_w, input_gate_bias, output_cell_shape); transposed_weights = reference::transpose(recurrent_to_input_w); gemm = reference::gemm(output_state_in, transposed_weights, cell_state_in, 1.f, 0.f); - input_gate = reference::arithmetic_addition(fully_connected_input, gemm, data_type, ConvertPolicy::SATURATE); + input_gate = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, fully_connected_input, gemm, data_type, ConvertPolicy::SATURATE); if(peephole_opt) { SimpleTensor pixelwise_mul_input_gate = reference::pixel_wise_multiplication(cell_state_in, cell_to_input_w, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN); - input_gate = reference::arithmetic_addition(input_gate, pixelwise_mul_input_gate, data_type, ConvertPolicy::SATURATE); + input_gate = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, input_gate, pixelwise_mul_input_gate, data_type, ConvertPolicy::SATURATE); } input_gate = reference::activation_layer(input_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); } @@ -370,10 +369,10 @@ protected: transposed_weights = reference::transpose(recurrent_to_cell_w); gemm = reference::gemm(output_state_in, transposed_weights, cell_state_out, 1.f, 0.f); SimpleTensor pixelwise_mul = reference::pixel_wise_multiplication(cell_state_in, forget_gate, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN); - cell_state_out = reference::arithmetic_addition(fully_connected_cell_state, gemm, data_type, ConvertPolicy::SATURATE); + cell_state_out = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, fully_connected_cell_state, gemm, data_type, ConvertPolicy::SATURATE); cell_state_out = reference::activation_layer(cell_state_out, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); cell_state_out = reference::pixel_wise_multiplication(cell_state_out, input_gate, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN); - cell_state_out = reference::arithmetic_addition(cell_state_out, pixelwise_mul, data_type, ConvertPolicy::SATURATE); + cell_state_out = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, cell_state_out, pixelwise_mul, data_type, ConvertPolicy::SATURATE); if(cell_threshold != 0.f) { cell_state_out = reference::activation_layer(cell_state_out, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold, cell_threshold)); @@ -383,11 +382,11 @@ protected: SimpleTensor fully_connected_output = reference::fully_connected_layer(input, input_to_output_w, output_gate_bias, output_cell_shape); transposed_weights = reference::transpose(recurrent_to_output_w); gemm = reference::gemm(output_state_in, transposed_weights, cell_state_out, 1.f, 0.f); - output = reference::arithmetic_addition(fully_connected_output, gemm, data_type, ConvertPolicy::SATURATE); + output = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, fully_connected_output, gemm, data_type, ConvertPolicy::SATURATE); if(peephole_opt) { pixelwise_mul = reference::pixel_wise_multiplication(cell_state_out, cell_to_output_w, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN); - output = reference::arithmetic_addition(output, pixelwise_mul, data_type, ConvertPolicy::SATURATE); + output = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, output, pixelwise_mul, data_type, ConvertPolicy::SATURATE); } output = reference::activation_layer(output, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); diff --git a/tests/validation/fixtures/RNNLayerFixture.h b/tests/validation/fixtures/RNNLayerFixture.h index 42b99cce1c..2645116b44 100644 --- a/tests/validation/fixtures/RNNLayerFixture.h +++ b/tests/validation/fixtures/RNNLayerFixture.h @@ -28,7 +28,7 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" #include "tests/validation/reference/ActivationLayer.h" -#include "tests/validation/reference/ArithmeticAddition.h" +#include "tests/validation/reference/ArithmeticOperations.h" #include "tests/validation/reference/FullyConnectedLayer.h" #include "tests/validation/reference/GEMM.h" @@ -132,7 +132,7 @@ protected: SimpleTensor out_w{ out_shape, data_type }; SimpleTensor fully_connected = reference::fully_connected_layer(input, weights, bias, out_shape); SimpleTensor gemm = reference::gemm(hidden_state, recurrent_weights, out_w, 1.f, 0.f); - SimpleTensor add_res = reference::arithmetic_addition(fully_connected, gemm, data_type, ConvertPolicy::SATURATE); + SimpleTensor add_res = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, fully_connected, gemm, data_type, ConvertPolicy::SATURATE); return reference::activation_layer(add_res, info); } -- cgit v1.2.1