From 4f85982a55ae417edde6864304aeb1d69972973e Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 6 Feb 2019 18:08:04 +0000 Subject: COMPMID-1923: Input is ignored if peephole optimization is enabled in LSTM Change-Id: I9e6c4fe279aafaf7f77af453785a8f677868a25a Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/639 Reviewed-by: Michalis Spyrou Tested-by: Arm Jenkins --- tests/validation/CL/LSTMLayer.cpp | 4 +++- tests/validation/NEON/LSTMLayer.cpp | 6 +++-- tests/validation/fixtures/LSTMLayerFixture.h | 35 +++++++++++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/LSTMLayer.cpp b/tests/validation/CL/LSTMLayer.cpp index 4afebdc2ce..ea20bd6c2c 100644 --- a/tests/validation/CL/LSTMLayer.cpp +++ b/tests/validation/CL/LSTMLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -160,6 +160,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLLSTMLayerFixture, framework::DatasetMo { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); + validate(CLAccessor(_target_scratch), _reference_scratch, tolerance_f32); } TEST_SUITE_END() // FP32 @@ -170,6 +171,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLLSTMLayerFixture, framework::DatasetMod { // Validate output validate(CLAccessor(_target), _reference, tolerance_f16); + validate(CLAccessor(_target_scratch), _reference_scratch, tolerance_f16); } TEST_SUITE_END() // FP16 TEST_SUITE_END() // LSTMLayer diff --git a/tests/validation/NEON/LSTMLayer.cpp b/tests/validation/NEON/LSTMLayer.cpp index 3693d4f20d..5dfd32b8e5 100644 --- a/tests/validation/NEON/LSTMLayer.cpp +++ b/tests/validation/NEON/LSTMLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -39,7 +39,7 @@ namespace validation { namespace { -RelativeTolerance tolerance_f32(0.001f); +RelativeTolerance tolerance_f32(0.00001f); RelativeTolerance tolerance_f16(half(0.1)); } // namespace @@ -160,6 +160,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NELSTMLayerFixture, framework::DatasetMo { // Validate output validate(Accessor(_target), _reference, tolerance_f32); + validate(Accessor(_target_scratch), _reference_scratch, tolerance_f32); } TEST_SUITE_END() // FP32 @@ -171,6 +172,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NELSTMLayerFixture, framework::DatasetMod { // Validate output validate(Accessor(_target), _reference, tolerance_f16); + validate(Accessor(_target_scratch), _reference_scratch, tolerance_f16); } TEST_SUITE_END() // FP16 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ diff --git a/tests/validation/fixtures/LSTMLayerFixture.h b/tests/validation/fixtures/LSTMLayerFixture.h index 7f11265932..b0b2a8fae1 100644 --- a/tests/validation/fixtures/LSTMLayerFixture.h +++ b/tests/validation/fixtures/LSTMLayerFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -33,6 +33,7 @@ #include "tests/validation/reference/GEMM.h" #include "tests/validation/reference/PixelWiseMultiplication.h" #include "tests/validation/reference/Transpose.h" +#include "tests/validation/reference/WidthConcatenateLayer.h" namespace arm_compute { @@ -237,7 +238,8 @@ protected: cell_to_output_w.allocator()->allocate(); ARM_COMPUTE_EXPECT(!cell_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS); ARM_COMPUTE_EXPECT(!cell_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS); - fill(AccessorType(cell_to_output_w), 18); + fill(AccessorType(cell_to_forget_w), 18); + fill(AccessorType(cell_to_output_w), 19); } if(projection_opt) @@ -251,13 +253,14 @@ protected: ARM_COMPUTE_EXPECT(!projection_w.info()->is_resizable(), framework::LogLevel::ERRORS); ARM_COMPUTE_EXPECT(!projection_bias.info()->is_resizable(), framework::LogLevel::ERRORS); - fill(AccessorType(projection_w), 19); - fill(AccessorType(projection_bias), 20); + fill(AccessorType(projection_w), 20); + fill(AccessorType(projection_bias), 21); } // Compute function lstm.run(); + _target_scratch = std::move(scratch); return output; } @@ -322,11 +325,12 @@ protected: fill(cell_to_input_w, 15); fill(recurrent_to_input_w, 16); fill(input_gate_bias, 17); - fill(cell_to_output_w, 18); - fill(projection_w, 19); - fill(projection_bias, 20); + fill(cell_to_forget_w, 18); + fill(cell_to_output_w, 19); + fill(projection_w, 20); + fill(projection_bias, 21); - bool cifg_opt = scratch_shape.x() == cell_bias_shape.x() * 4 ? true : false; + bool cifg_opt = scratch_shape.x() == cell_bias_shape.x() * 4 ? false : true; // Compute forget_gate SimpleTensor fully_connected_forget = reference::fully_connected_layer(input, input_to_forget_w, forget_gate_bias, output_cell_shape); @@ -336,7 +340,7 @@ protected: 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); + SimpleTensor pixelwise_mul_forget_gate = reference::pixel_wise_multiplication(cell_state_in, cell_to_forget_w, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO); forget_gate = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, forget_gate, pixelwise_mul_forget_gate, data_type, ConvertPolicy::SATURATE); } @@ -402,11 +406,24 @@ protected: output_state_out = reference::activation_layer(fully_connected_projection, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold)); } } + + std::vector> scratch_inputs; + if(!cifg_opt) + { + scratch_inputs.emplace_back(std::move(input_gate)); + } + scratch_inputs.emplace_back(std::move(cell_state_out)); + scratch_inputs.emplace_back(std::move(forget_gate)); + scratch_inputs.emplace_back(std::move(output)); + scratch = reference::widthconcatenate_layer(scratch_inputs); + _reference_scratch = std::move(scratch); return output_state_out; } TensorType _target{}; + TensorType _target_scratch{}; SimpleTensor _reference{}; + SimpleTensor _reference_scratch{}; }; } // namespace validation } // namespace test -- cgit v1.2.1