From 0ec53a0e54ae0be0ed9c4e4c14a5fd10ed5f48a8 Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Thu, 12 Mar 2020 16:27:19 +0000 Subject: COMPMID-3238 add reference kernel for QSYMM16 Layer Normalization Kernel Change-Id: I7384120ccf7567550dfbecadeb16e09e69b2c7b0 Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2878 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- .../reference/LayerNormalizationLayer.cpp | 60 ++++++++++++++++++++++ .../validation/reference/LayerNormalizationLayer.h | 44 ++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 tests/validation/reference/LayerNormalizationLayer.cpp create mode 100644 tests/validation/reference/LayerNormalizationLayer.h diff --git a/tests/validation/reference/LayerNormalizationLayer.cpp b/tests/validation/reference/LayerNormalizationLayer.cpp new file mode 100644 index 0000000000..e597ccd997 --- /dev/null +++ b/tests/validation/reference/LayerNormalizationLayer.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 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 "LayerNormalizationLayer.h" +#include "ArithmeticOperations.h" +#include "MeanStdDevNormalizationLayer.h" +#include "PixelWiseMultiplication.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +SimpleTensor layer_normalization_layer_float(SimpleTensor src, SimpleTensor weight, SimpleTensor bias) +{ + src = mean_std_normalization_layer(src); + src = pixel_wise_multiplication(src, weight, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO); + return arithmetic_operation(ArithmeticOperation::ADD, src, bias, DataType::F32, ConvertPolicy::SATURATE); +} + +SimpleTensor layer_normalization_layer(const SimpleTensor &src, const SimpleTensor &weight, const SimpleTensor &bias) +{ + ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 2); + + SimpleTensor converted_src = convert_from_symmetric(src); + SimpleTensor converted_weight = convert_from_symmetric(weight); + SimpleTensor converted_bias = convert_from_symmetric(bias); + + SimpleTensor output = layer_normalization_layer_float(converted_src, converted_weight, converted_bias); + + return convert_to_symmetric(output, src.quantization_info()); +} +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/LayerNormalizationLayer.h b/tests/validation/reference/LayerNormalizationLayer.h new file mode 100644 index 0000000000..5b1d08cc9c --- /dev/null +++ b/tests/validation/reference/LayerNormalizationLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 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_LAYER_NORMALIZATION_LAYER_H +#define ARM_COMPUTE_TEST_LAYER_NORMALIZATION_LAYER_H + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +SimpleTensor layer_normalization_layer(const SimpleTensor &src, const SimpleTensor &weight, const SimpleTensor &bias); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute + +#endif /* ARM_COMPUTE_TEST_LAYER_NORMALIZATION_LAYER_H */ -- cgit v1.2.1