From 0fb6cf5b6f41a3734ab439f970ba94b96be06c5d Mon Sep 17 00:00:00 2001 From: zhenglin Date: Tue, 12 Dec 2017 15:56:09 +0800 Subject: APPBROWSER-340: Implement NormalizePlanarYUV operator Change-Id: I943fe27ed83e6c499d8f9919c7083f39f6f25acc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/113211 Tested-by: Jenkins Reviewed-by: Stephen Li Reviewed-by: Anthony Barbier --- arm_compute/core/GLES_COMPUTE/GCKernels.h | 1 + .../kernels/GCNormalizePlanarYUVLayerKernel.h | 72 +++++++++++ arm_compute/runtime/GLES_COMPUTE/GCFunctions.h | 1 + .../functions/GCNormalizePlanarYUVLayer.h | 63 ++++++++++ src/core/GLES_COMPUTE/GCKernelLibrary.cpp | 5 + .../cs_shaders/normalize_planar_yuv_layer.cs | 99 +++++++++++++++ .../kernels/GCNormalizePlanarYUVLayerKernel.cpp | 114 +++++++++++++++++ .../functions/GCNormalizePlanarYUVLayer.cpp | 48 +++++++ .../GLES_COMPUTE/NormalizePlanarYUVLayer.cpp | 56 +++++++++ .../fixtures/NormalizePlanarYUVLayerFixture.h | 103 +++++++++++++++ tests/datasets/NormalizePlanarYUVLayerDataset.h | 107 ++++++++++++++++ .../RandomNormalizePlanarYUVLayerDataset.h | 54 ++++++++ ...eNetInceptionV4NormalizePlanarYUVLayerDataset.h | 94 ++++++++++++++ .../GLES_COMPUTE/NormalizePlanarYUVLayer.cpp | 88 +++++++++++++ tests/validation/Helpers.h | 14 +++ .../fixtures/NormalizePlanarYUVLayerFixture.h | 140 +++++++++++++++++++++ .../reference/NormalizePlanarYUVLayer.cpp | 69 ++++++++++ .../validation/reference/NormalizePlanarYUVLayer.h | 44 +++++++ 18 files changed, 1172 insertions(+) create mode 100644 arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h create mode 100644 arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h create mode 100644 src/core/GLES_COMPUTE/cs_shaders/normalize_planar_yuv_layer.cs create mode 100644 src/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.cpp create mode 100755 src/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.cpp create mode 100644 tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp create mode 100644 tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h create mode 100644 tests/datasets/NormalizePlanarYUVLayerDataset.h create mode 100644 tests/datasets/RandomNormalizePlanarYUVLayerDataset.h create mode 100644 tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h create mode 100644 tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp mode change 100644 => 100755 tests/validation/Helpers.h create mode 100644 tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h create mode 100644 tests/validation/reference/NormalizePlanarYUVLayer.cpp create mode 100644 tests/validation/reference/NormalizePlanarYUVLayer.h diff --git a/arm_compute/core/GLES_COMPUTE/GCKernels.h b/arm_compute/core/GLES_COMPUTE/GCKernels.h index 417c98af67..28f6763c94 100644 --- a/arm_compute/core/GLES_COMPUTE/GCKernels.h +++ b/arm_compute/core/GLES_COMPUTE/GCKernels.h @@ -40,6 +40,7 @@ #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMTranspose1xWKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCIm2ColKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCNormalizationLayerKernel.h" +#include "arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCPixelWiseMultiplicationKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCPoolingLayerKernel.h" #include "arm_compute/core/GLES_COMPUTE/kernels/GCSoftmaxLayerKernel.h" diff --git a/arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h b/arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h new file mode 100644 index 0000000000..ecf5f44f71 --- /dev/null +++ b/arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017 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__H__ +#define __ARM_COMPUTE_GCNORMALIZEPLANARYUVLAYERKERNEL_H__ + +#include "arm_compute/core/GLES_COMPUTE/IGCKernel.h" + +namespace arm_compute +{ +class IGCTensor; + +/** Interface for the NormalizePlanarYUV layer kernel. + */ +class GCNormalizePlanarYUVLayerKernel : public IGCKernel +{ +public: + /** Constructor */ + GCNormalizePlanarYUVLayerKernel(); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + GCNormalizePlanarYUVLayerKernel(const GCNormalizePlanarYUVLayerKernel &) = delete; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + GCNormalizePlanarYUVLayerKernel &operator=(const GCNormalizePlanarYUVLayerKernel &) = delete; + /** Default Move Constructor. */ + GCNormalizePlanarYUVLayerKernel(GCNormalizePlanarYUVLayerKernel &&) = default; + /** Default move assignment operator. */ + GCNormalizePlanarYUVLayerKernel &operator=(GCNormalizePlanarYUVLayerKernel &&) = default; + /** Default destructor */ + ~GCNormalizePlanarYUVLayerKernel() = default; + + /** Set the input and output tensors. + * + * @param[in] input Source tensor. 3 lower dimensions represent a single input with dimensions [width, height, FM]. + * Data types supported: F16. + * @param[out] output Destination tensor. Output will have the same number of dimensions as input. Data type supported: same as @p input + * @param[in] mean Mean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as @p input + * @param[in] sd Standard deviation values tensor. 1 dimension with size equal to the feature maps [FM]. + * Data types supported: Same as @p input + */ + void configure(const IGCTensor *input, IGCTensor *output, const IGCTensor *mean, const IGCTensor *sd); + + // Inherited methods overridden: + void run(const Window &window) override; + +private: + const IGCTensor *_input; + IGCTensor *_output; + const IGCTensor *_mean; + const IGCTensor *_sd; +}; +} +#endif /*__ARM_COMPUTE_GCNORMALIZEPLANARYUVLAYERKERNEL_H__ */ diff --git a/arm_compute/runtime/GLES_COMPUTE/GCFunctions.h b/arm_compute/runtime/GLES_COMPUTE/GCFunctions.h index e76d4efb27..e05902858d 100644 --- a/arm_compute/runtime/GLES_COMPUTE/GCFunctions.h +++ b/arm_compute/runtime/GLES_COMPUTE/GCFunctions.h @@ -37,6 +37,7 @@ #include "arm_compute/runtime/GLES_COMPUTE/functions/GCGEMMInterleave4x4.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCGEMMTranspose1xW.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizationLayer.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCPixelWiseMultiplication.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCPoolingLayer.h" #include "arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h" diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h new file mode 100644 index 0000000000..2862eeb9cd --- /dev/null +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017 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_GCNORMALIZEPLANARYUVLAYER_H__ +#define __ARM_COMPUTE_GCNORMALIZEPLANARYUVLAYER_H__ + +#include "arm_compute/runtime/IFunction.h" + +#include "arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +class IGCTensor; + +/** Basic function to run @ref GCNormalizePlanarYUVLayerKernel + * + * @note The function simulates a NormalizePlanarYUV layer. + */ +class GCNormalizePlanarYUVLayer : public IFunction +{ +public: + /** Default constructor */ + GCNormalizePlanarYUVLayer(); + /** Set the input and output tensors. + * + * @param[in] input Source tensor. 3 lower dimensions represent a single input with dimensions [width, height, FM]. + * Data types supported: F16. + * @param[out] output Destination tensor. Output will have the same number of dimensions as input. Data type supported: same as @p input + * @param[in] mean Mean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as @p input + * @param[in] sd Standard deviation values tensor. 1 dimension with size equal to the feature maps [FM]. + * Data types supported: Same as @p input + */ + void configure(const IGCTensor *input, IGCTensor *output, const IGCTensor *mean, const IGCTensor *sd); + + // Inherited methods overridden: + void run() override; + +private: + GCNormalizePlanarYUVLayerKernel _norm_kernel; /**< NormalizePlanarYUV layer kernel to run */ +}; +} +#endif /* __ARM_COMPUTE_GCNORMALIZEPLANARYUVLAYER_H__ */ diff --git a/src/core/GLES_COMPUTE/GCKernelLibrary.cpp b/src/core/GLES_COMPUTE/GCKernelLibrary.cpp index e8c6ad2539..484c8aadfb 100644 --- a/src/core/GLES_COMPUTE/GCKernelLibrary.cpp +++ b/src/core/GLES_COMPUTE/GCKernelLibrary.cpp @@ -220,6 +220,7 @@ const std::map GCKernelLibrary::_shader_program_map = { "batchnormalization_layer", "batchnormalization_layer.cs" }, { "concatenate_depth", "concatenate.cs" }, { "dropout", "dropout.cs" }, + { "normalize_planar_yuv_layer", "normalize_planar_yuv_layer.cs" }, }; const std::map GCKernelLibrary::_program_source_map = @@ -289,6 +290,10 @@ const std::map GCKernelLibrary::_program_source_map = "dropout.cs", #include "./cs_shaders/dropout.csembed" }, + { + "normalize_planar_yuv_layer.cs", +#include "./cs_shaders/normalize_planar_yuv_layer.csembed" + }, #endif /* EMBEDDED_KERNELS */ }; diff --git a/src/core/GLES_COMPUTE/cs_shaders/normalize_planar_yuv_layer.cs b/src/core/GLES_COMPUTE/cs_shaders/normalize_planar_yuv_layer.cs new file mode 100644 index 0000000000..18a9af74fc --- /dev/null +++ b/src/core/GLES_COMPUTE/cs_shaders/normalize_planar_yuv_layer.cs @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017 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. + */ + +layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; + +#include "helpers_cs.h" + +precision mediump float; + +/** Apply normalize_planar_yuv layer. + * + * @param[in] src_ptr Pointer to the first source tensor. Supported data types: F16 + * @param[in] src_attrs The attributes of the source tensor + * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr + * @param[in] dst_attrs The attributes of the destination tensor + * @param[in] mean_ptr Pointer to the mean source tensor. Supported data types: same as @p src_ptr + * @param[in] mean_attrs The attributes of the mean tensor + * @param[in] sd_ptr Standard deviation values tensor,pointer to the sd tensor. Supported data types: same as @p src_ptr + * @param[in] sd_attrs The attributes of the sd tensor + */ +SHADER_PARAMS_DECLARATION +{ + Tensor3DAttributes src_attrs; + Tensor3DAttributes dst_attrs; + VectorAttributes mean_attrs; + VectorAttributes sd_attrs; +}; + +TENSOR_DECLARATION(1, srcBuffer, uvec2, src_ptr, src_shift, 3, readonly); +TENSOR_DECLARATION(2, dstBuffer, uvec2, dst_ptr, dst_shift, 3, writeonly); +TENSOR_DECLARATION(3, meanBuffer, uvec2, mean_ptr, mean_shift, 3, readonly); +TENSOR_DECLARATION(4, sdBuffer, uvec2, sd_ptr, sd_shift, 3, readonly); + +void main(void) +{ + Tensor3DIterator src_iter = CONVERT_TO_TENSOR3D_ITERATOR(src_attrs, src_shift); + Tensor3DIterator dst_iter = CONVERT_TO_TENSOR3D_ITERATOR(dst_attrs, dst_shift); + VectorIterator mean_iter = CONVERT_TO_VECTOR_ITERATOR(mean_attrs, mean_shift); + VectorIterator sd_iter = CONVERT_TO_VECTOR_ITERATOR(sd_attrs, sd_shift); + + vec4 unpacked_s[3]; + vec4 tmp; + vec4 result; + + uint current_slice = gl_GlobalInvocationID.z; + unpacked_s[0] = LOAD_UNPACK4_CURRENT_ITEM_HALF(src_ptr, src_iter); + unpacked_s[1] = LOAD_UNPACK4_HALF(mean_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(mean_iter, current_slice * mean_attrs.stride_x)); + unpacked_s[2] = LOAD_UNPACK4_HALF(sd_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(sd_iter, current_slice * sd_attrs.stride_x)); + + if((current_slice % uint(4)) == uint(0)) + { + tmp = unpacked_s[0] - unpacked_s[1].x; + result = tmp / unpacked_s[2].x; + + STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); + } + else if((current_slice % uint(4)) == uint(1)) + { + tmp = unpacked_s[0] - unpacked_s[1].y; + result = tmp / unpacked_s[2].y; + + STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); + } + else if((current_slice % uint(4)) == uint(2)) + { + tmp = unpacked_s[0] - unpacked_s[1].z; + result = tmp / unpacked_s[2].z; + + STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); + } + else + { + tmp = unpacked_s[0] - unpacked_s[1].w; + result = tmp / unpacked_s[2].w; + + STORE_PACK4_CURRENT_ITEM_HALF(dst_ptr, dst_iter, result); + } +} diff --git a/src/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.cpp b/src/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.cpp new file mode 100644 index 0000000000..bc9c7eb55a --- /dev/null +++ b/src/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2017 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 "arm_compute/core/GLES_COMPUTE/kernels/GCNormalizePlanarYUVLayerKernel.h" + +#include "arm_compute/core/AccessWindowStatic.h" +#include "arm_compute/core/GLES_COMPUTE/GCHelpers.h" +#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h" +#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h" +#include "arm_compute/core/Helpers.h" +#include "arm_compute/core/Utils.h" +#include "arm_compute/core/Validate.h" +#include "arm_compute/core/Window.h" + +#include "support/ToolchainSupport.h" + +using namespace arm_compute; + +GCNormalizePlanarYUVLayerKernel::GCNormalizePlanarYUVLayerKernel() + : _input(nullptr), _output(nullptr), _mean(nullptr), _sd(nullptr) +{ +} + +void GCNormalizePlanarYUVLayerKernel::configure(const IGCTensor *input, IGCTensor *output, const IGCTensor *mean, const IGCTensor *sd) +{ + ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16); + ARM_COMPUTE_ERROR_ON_NULLPTR(output); + ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output, mean, sd); + ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input, output); + ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(mean, sd); + ARM_COMPUTE_ERROR_ON(input->info()->dimension(2) != mean->info()->dimension(0)); + + _input = input; + _output = output; + _mean = mean; + _sd = sd; + + const unsigned int num_elems_processed_per_iteration = 4; + + // Set build options + std::set build_opts; + build_opts.emplace(("#define LOCAL_SIZE_X " + support::cpp11::to_string(1))); + build_opts.emplace(("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1))); + build_opts.emplace(("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1))); + + // Create kernel + _kernel = static_cast(GCKernelLibrary::get().create_kernel("normalize_planar_yuv_layer", build_opts)); + + // Configure kernel window + Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + + AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); + AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); + const int mean_padding = ceil_to_multiple(mean->info()->dimension(0), num_elems_processed_per_iteration) - mean->info()->dimension(0); + const int sd_padding = ceil_to_multiple(sd->info()->dimension(0), num_elems_processed_per_iteration) - sd->info()->dimension(0); + AccessWindowStatic mean_access(mean->info(), 0, 0, mean->info()->dimension(0) + mean_padding, mean->info()->dimension(1)); + AccessWindowStatic sd_access(sd->info(), 0, 0, sd->info()->dimension(0) + sd_padding, sd->info()->dimension(1)); + + update_window_and_padding(win, input_access, output_access, mean_access, sd_access); + output_access.set_valid_region(win, input->info()->valid_region()); + + IGCKernel::configure(win); +} + +void GCNormalizePlanarYUVLayerKernel::run(const Window &window) +{ + ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); + ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); + + _kernel.use(); + + Window slice = window.first_slice_window_3D(); + + Window slice_in; + //slice_in.use_tensor_dimensions(_mean->info()->tensor_shape()); + slice_in = window.first_slice_window_1D(); + slice_in.set(Window::DimX, Window::Dimension(0, 0, 0)); + + unsigned int idx = 2 * num_arguments_per_3D_tensor(); + add_1D_tensor_argument(idx, _mean, 3, slice_in); + add_1D_tensor_argument(idx, _sd, 4, slice_in); + + do + { + idx = 0; + add_3D_tensor_argument(idx, _input, 1, slice); + add_3D_tensor_argument(idx, _output, 2, slice); + + _kernel.update_shader_params(); + + enqueue(*this, slice); + } + while(window.slide_window_slice_3D(slice)); +} diff --git a/src/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.cpp b/src/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.cpp new file mode 100755 index 0000000000..de04a28547 --- /dev/null +++ b/src/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 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 "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" + +#include "arm_compute/core/Error.h" +#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/Validate.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" + +using namespace arm_compute; + +GCNormalizePlanarYUVLayer::GCNormalizePlanarYUVLayer() + : _norm_kernel() +{ +} + +void GCNormalizePlanarYUVLayer::configure(const IGCTensor *input, IGCTensor *output, const IGCTensor *mean, const IGCTensor *sd) +{ + _norm_kernel.configure(input, output, mean, sd); +} + +void GCNormalizePlanarYUVLayer::run() +{ + GCScheduler::get().enqueue(_norm_kernel, true); +} diff --git a/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp b/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..332418015d --- /dev/null +++ b/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 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, + * FITCLSS 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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" +#include "tests/GLES_COMPUTE/GCAccessor.h" +#include "tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h" +#include "tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace +{ +const auto data_types = framework::dataset::make("DataType", { DataType::F16 }); +} // namespace + +using GCNormalizePlanarYUVLayerFixture = NormalizePlanarYUVLayerFixture; + +TEST_SUITE(GC) + +REGISTER_FIXTURE_DATA_TEST_CASE(GoogLeNetInceptionV4NormalizePlanarYUVLayer, GCNormalizePlanarYUVLayerFixture, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset(), + data_types), + framework::dataset::make("Batches", 1))); + +TEST_SUITE_END() +} // namespace test +} // namespace arm_compute diff --git a/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h new file mode 100644 index 0000000000..92343534dc --- /dev/null +++ b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017 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_NORMALIZEPLANARYUVLAYERFIXTURE +#define ARM_COMPUTE_TEST_NORMALIZEPLANARYUVLAYERFIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "tests/framework/Fixture.h" +#ifdef ARM_COMPUTE_GC +#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" +#include "tests/GLES_COMPUTE/Helper.h" + +using namespace arm_compute::test::gles_compute; +#endif /* ARM_COMPUTE_GC */ + +namespace arm_compute +{ +namespace test +{ +/** Fixture that can be used for NEON and CL */ +template +class NormalizePlanarYUVLayerFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape tensor_shape, TensorShape param_shape, DataType data_type, int batches) + { + // Set batched in source and destination shapes + tensor_shape.set(tensor_shape.num_dimensions(), batches); + + // Create tensors + src = create_tensor(tensor_shape, data_type, 1); + dst = create_tensor(tensor_shape, data_type, 1); + mean = create_tensor(param_shape, data_type, 1); + sd = create_tensor(param_shape, data_type, 1); + + // Create and configure function + normalize_planar_yuv_layer.configure(&src, &dst, &mean, &sd); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + mean.allocator()->allocate(); + sd.allocator()->allocate(); + + // Fill tensors + library->fill_tensor_uniform(Accessor(src), 0); + library->fill_tensor_uniform(Accessor(mean), 1); + library->fill_tensor_uniform(Accessor(sd), 2); + } + + void run() + { + normalize_planar_yuv_layer.run(); +#ifdef ARM_COMPUTE_GC + if(opengles31_is_available() && std::is_same::type, arm_compute::GCTensor>::value) + { + force_sync_tensor(dst); + } +#endif /* ARM_COMPUTE_GC */ + } + + void teardown() + { + src.allocator()->free(); + dst.allocator()->free(); + mean.allocator()->free(); + sd.allocator()->free(); + } + +private: + TensorType src{}; + TensorType dst{}; + TensorType mean{}; + TensorType sd{}; + Function normalize_planar_yuv_layer{}; +}; +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZEPLANARYUVLAYERFIXTURE */ diff --git a/tests/datasets/NormalizePlanarYUVLayerDataset.h b/tests/datasets/NormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..2d71a56a30 --- /dev/null +++ b/tests/datasets/NormalizePlanarYUVLayerDataset.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017 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_NORMALIZE_PLANAR_YUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_DATASET + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class NormalizePlanarYUVLayerDataset +{ +public: + using type = std::tuple; + + struct iterator + { + iterator(std::vector::const_iterator tensor_it, + std::vector::const_iterator param_it) + : _tensor_it{ std::move(tensor_it) }, + _param_it{ std::move(param_it) } + { + } + + std::string description() const + { + std::stringstream description; + description << "In=" << *_tensor_it << ":"; + description << "Out=" << *_tensor_it << ":"; + description << "Mean=" << *_param_it << ":"; + description << "Sd=" << *_param_it << ":"; + return description.str(); + } + + NormalizePlanarYUVLayerDataset::type operator*() const + { + return std::make_tuple(*_tensor_it, *_param_it); + } + + iterator &operator++() + { + ++_tensor_it; + ++_param_it; + + return *this; + } + + private: + std::vector::const_iterator _tensor_it; + std::vector::const_iterator _param_it; + }; + + iterator begin() const + { + return iterator(_tensor_shapes.begin(), _param_shapes.begin()); + } + + int size() const + { + return std::min(_tensor_shapes.size(), _param_shapes.size()); + } + + void add_config(TensorShape tensor, TensorShape param) + { + _tensor_shapes.emplace_back(std::move(tensor)); + _param_shapes.emplace_back(std::move(param)); + } + +protected: + NormalizePlanarYUVLayerDataset() = default; + NormalizePlanarYUVLayerDataset(NormalizePlanarYUVLayerDataset &&) = default; + +private: + std::vector _tensor_shapes{}; + std::vector _param_shapes{}; +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_DATASET */ diff --git a/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h b/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..5693004070 --- /dev/null +++ b/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 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_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET + +#include "tests/datasets/NormalizePlanarYUVLayerDataset.h" + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class RandomNormalizePlanarYUVLayerDataset final : public NormalizePlanarYUVLayerDataset +{ +public: + RandomNormalizePlanarYUVLayerDataset() + { + add_config(TensorShape(15U, 4U, 4U, 1U), TensorShape(4U)); + add_config(TensorShape(21U, 11U, 12U, 1U), TensorShape(12U)); + add_config(TensorShape(7U, 3U, 6U, 1U), TensorShape(6U)); + add_config(TensorShape(7U, 2U, 3U, 1U), TensorShape(3U)); + } +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET */ diff --git a/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..e0da484b7d --- /dev/null +++ b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017 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_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET + +#include "tests/datasets/NormalizePlanarYUVLayerDataset.h" + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset final : public NormalizePlanarYUVLayerDataset +{ +public: + GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset() + { + // conv1_3x3_s2_bn + add_config(TensorShape(149U, 149U, 32U), TensorShape(32U)); + // conv2_3x3_s1_bn + add_config(TensorShape(147U, 147U, 32U), TensorShape(32U)); + // conv3_3x3_s1_bn + add_config(TensorShape(147U, 147U, 64U), TensorShape(64U)); + // inception_stem1_3x3_s2_bn + add_config(TensorShape(73U, 73U, 96U), TensorShape(96U)); + // inception_stem2_3x3_reduce_bn, inception_stem2_1x7_reduce_bn, inception_stem2_1x7_bn, inception_stem2_7x1_bn + add_config(TensorShape(73U, 73U, 64U), TensorShape(64U)); + // inception_stem2_3x3_bn, inception_stem2_3x3_2_bn + add_config(TensorShape(71U, 71U, 96U), TensorShape(96U)); + // inception_stem3_3x3_s2_bn, reduction_a_3x3_2_reduce_bn + add_config(TensorShape(35U, 35U, 192U), TensorShape(192U)); + // inception_a1_1x1_2_bn, inception_a1_3x3_bn, inception_a1_3x3_2_bn, inception_a1_3x3_3_bn, inception_a1_1x1_bn, inception_a2_1x1_2_bn, inception_a2_3x3_bn, inception_a2_3x3_2_bn, inception_a2_3x3_3_bn, inception_a2_1x1_bn, inception_a3_1x1_2_bn, inception_a3_3x3_bn, inception_a3_3x3_2_bn, inception_a3_3x3_3_bn, inception_a3_1x1_bn, inception_a4_1x1_2_bn, inception_a4_3x3_bn, inception_a4_3x3_2_bn, inception_a4_3x3_3_bn, inception_a4_1x1_bn + add_config(TensorShape(35U, 35U, 96U), TensorShape(96U)); + // inception_a1_3x3_reduce_bn, inception_a1_3x3_2_reduce_bn, inception_a2_3x3_reduce_bn, inception_a2_3x3_2_reduce_bn, inception_a3_3x3_reduce_bn, inception_a3_3x3_2_reduce_bn, inception_a4_3x3_reduce_bn, inception_a4_3x3_2_reduce_bn + add_config(TensorShape(35U, 35U, 64U), TensorShape(64U)); + // reduction_a_3x3_bn, inception_b1_1x1_2_bn, inception_b2_1x1_2_bn, inception_b3_1x1_2_bn, inception_b4_1x1_2_bn, inception_b5_1x1_2_bn, inception_b6_1x1_2_bn, inception_b7_1x1_2_bn + add_config(TensorShape(17U, 17U, 384U), TensorShape(384U)); + // reduction_a_3x3_2_bn + add_config(TensorShape(35U, 35U, 224U), TensorShape(224U)); + // reduction_a_3x3_3_bn, inception_b1_7x1_bn, inception_b1_1x7_3_bn, inception_b2_7x1_bn, inception_b2_1x7_3_bn, inception_b3_7x1_bn, inception_b3_1x7_3_bn, inception_b4_7x1_bn, inception_b4_1x7_3_bn, inception_b5_7x1_bn, inception_b5_1x7_3_bn, inception_b6_7x1_bn, inception_b6_1x7_3_bn, inception_b7_7x1_bn, inception_b7_1x7_3_bn, reduction_b_1x7_reduce_bn, reduction_b_1x7_bn + add_config(TensorShape(17U, 17U, 256U), TensorShape(256U)); + // inception_b1_1x7_reduce_bn, inception_b1_7x1_2_reduce_bn, inception_b1_7x1_2_bn, inception_b2_1x7_reduce_bn, inception_b2_7x1_2_reduce_bn, inception_b2_7x1_2_bn, inception_b3_1x7_reduce_bn, inception_b3_7x1_2_reduce_bn, inception_b3_7x1_2_bn, inception_b4_1x7_reduce_bn, inception_b4_7x1_2_reduce_bn, inception_b4_7x1_2_bn, inception_b5_1x7_reduce_bn, inception_b5_7x1_2_reduce_bn, inception_b5_7x1_2_bn, inception_b6_1x7_reduce_bn, inception_b6_7x1_2_reduce_bn, inception_b6_7x1_2_bn, inception_b7_1x7_reduce_bn, inception_b7_7x1_2_reduce_bn, inception_b7_7x1_2_bn, reduction_b_3x3_reduce_bn + add_config(TensorShape(17U, 17U, 192U), TensorShape(192U)); + // inception_b1_1x7_bn, inception_b1_1x7_2_bn, inception_b1_7x1_3_bn, inception_b2_1x7_bn, inception_b2_1x7_2_bn, inception_b2_7x1_3_bn, inception_b3_1x7_bn, inception_b3_1x7_2_bn, inception_b3_7x1_3_bn, inception_b4_1x7_bn, inception_b4_1x7_2_bn, inception_b4_7x1_3_bn, inception_b5_1x7_bn, inception_b5_1x7_2_bn, inception_b5_7x1_3_bn, inception_b6_1x7_bn, inception_b6_1x7_2_bn, inception_b6_7x1_3_bn, inception_b7_1x7_bn, inception_b7_1x7_2_bn, inception_b7_7x1_3_bn + add_config(TensorShape(17U, 17U, 224U), TensorShape(224U)); + // inception_b1_1x1_bn, inception_b2_1x1_bn, inception_b3_1x1_bn, inception_b4_1x1_bn, inception_b5_1x1_bn, inception_b6_1x1_bn, inception_b7_1x1_bn + add_config(TensorShape(17U, 17U, 128U), TensorShape(128U)); + // reduction_b_3x3_bn + add_config(TensorShape(8U, 8U, 192U), TensorShape(192U)); + // reduction_b_7x1_bn + add_config(TensorShape(17U, 17U, 320U), TensorShape(320U)); + // reduction_b_3x3_2_bn + add_config(TensorShape(8U, 8U, 320U), TensorShape(320U)); + // inception_c1_1x1_2_bn, inception_c1_1x3_bn, inception_c1_3x1_bn, inception_c1_1x3_3_bn, inception_c1_3x1_3_bn, inception_c1_1x1_bn, inception_c2_1x1_2_bn, inception_c2_1x3_bn, inception_c2_3x1_bn, inception_c2_1x3_3_bn, inception_c2_3x1_3_bn, inception_c2_1x1_bn, inception_c3_1x1_2_bn, inception_c3_1x3_bn, inception_c3_3x1_bn, inception_c3_1x3_3_bn, inception_c3_3x1_3_bn, inception_c3_1x1_bn + add_config(TensorShape(8U, 8U, 256U), TensorShape(256U)); + // inception_c1_1x1_3_bn, inception_c1_1x1_4_bn, inception_c2_1x1_3_bn, inception_c2_1x1_4_bn, inception_c3_1x1_3_bn, inception_c3_1x1_4_bn + add_config(TensorShape(8U, 8U, 384U), TensorShape(384U)); + // inception_c1_3x1_2_bn, inception_c2_3x1_2_bn, inception_c3_3x1_2_bn + add_config(TensorShape(8U, 8U, 448U), TensorShape(448U)); + // inception_c1_1x3_2_bn, inception_c2_1x3_2_bn, inception_c3_1x3_2_bn + add_config(TensorShape(8U, 8U, 512U), TensorShape(512U)); + } +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET */ diff --git a/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..e06b19cfea --- /dev/null +++ b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 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 "arm_compute/core/Types.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" +#include "tests/GLES_COMPUTE/GCAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/RandomNormalizePlanarYUVLayerDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance tolerance_f16(0.5f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ +} // namespace + +TEST_SUITE(GC) +TEST_SUITE(NormalizePlanarYUVLayer) + +template +using GCNormalizePlanarYUVLayerFixture = NormalizePlanarYUVLayerValidationFixture; + +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), framework::dataset::make("DataType", { DataType::F16 })), + shape0, shape1, dt) +{ + // Create tensors + GCTensor src = create_tensor(shape0, dt, 1); + GCTensor dst = create_tensor(shape0, dt, 1); + GCTensor mean = create_tensor(shape1, dt, 1); + GCTensor sd = create_tensor(shape1, dt, 1); + + // Create and Configure function + GCNormalizePlanarYUVLayer norm; + norm.configure(&src, &dst, &mean, &sd); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape0); + validate(dst.info()->valid_region(), valid_region); +} + +TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(Random, GCNormalizePlanarYUVLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), + framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(GCAccessor(_target), _reference, tolerance_f16, 0); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h old mode 100644 new mode 100755 index ab7dbd8a41..ba45968392 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -202,6 +202,20 @@ std::pair get_batchnormalization_layer_test_bounds(int fixed_point_positio return bounds; } +/** Helper function to get the testing range for NormalizePlanarYUV layer. + * + * @return A pair containing the lower upper testing bounds. + */ +template +std::pair get_normalize_planar_yuv_layer_test_bounds() +{ + std::pair bounds; + + bounds = std::make_pair(-1.f, 1.f); + + return bounds; +} + /** Convert quantized simple tensor into float using tensor quantization information. * * @param[in] src Quantized tensor. diff --git a/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h new file mode 100644 index 0000000000..ae5c53a053 --- /dev/null +++ b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2017 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_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_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/NormalizePlanarYUVLayer.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class NormalizePlanarYUVLayerValidationFixedPointFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + _data_type = dt; + _target = compute_target(shape0, shape1, dt); + _reference = compute_reference(shape0, shape1, dt); + } + +protected: + template + void fill(U &&src_tensor, U &&mean_tensor, U &&sd_tensor) + { + if(is_data_type_float(_data_type)) + { + float min_bound = 0.f; + float max_bound = 0.f; + std::tie(min_bound, max_bound) = get_normalize_planar_yuv_layer_test_bounds(); + std::uniform_real_distribution<> distribution(min_bound, max_bound); + std::uniform_real_distribution<> distribution_sd(0, max_bound); + library->fill(src_tensor, distribution, 0); + library->fill(mean_tensor, distribution, 1); + library->fill(sd_tensor, distribution_sd, 2); + } + } + + TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create tensors + TensorType src = create_tensor(shape0, dt, 1); + TensorType dst = create_tensor(shape0, dt, 1); + TensorType mean = create_tensor(shape1, dt, 1); + TensorType sd = create_tensor(shape1, dt, 1); + + // Create and configure function + FunctionType norm; + norm.configure(&src, &dst, &mean, &sd); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + mean.allocator()->allocate(); + sd.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src), AccessorType(mean), AccessorType(sd)); + + // Compute function + norm.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create reference + SimpleTensor ref_src{ shape0, dt, 1 }; + SimpleTensor ref_mean{ shape1, dt, 1 }; + SimpleTensor ref_sd{ shape1, dt, 1 }; + + // Fill reference + fill(ref_src, ref_mean, ref_sd); + + return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_sd); + } + + TensorType _target{}; + SimpleTensor _reference{}; + DataType _data_type{}; +}; + +template +class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationFixedPointFixture +{ +public: + template + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + NormalizePlanarYUVLayerValidationFixedPointFixture::setup(shape0, shape1, dt); + } +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */ diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.cpp b/tests/validation/reference/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..2442943bb4 --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 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 "NormalizePlanarYUVLayer.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +// NormalizePlanarYUV Layer for floating point type +template ::value, int>::type *> +SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd) +{ + SimpleTensor result(src.shape(), src.data_type()); + + const auto cols = static_cast(src.shape()[0]); + const auto rows = static_cast(src.shape()[1]); + const auto depth = static_cast(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < depth; ++i) + { + for(int k = 0; k < rows; ++k) + { + for(int l = 0; l < cols; ++l) + { + const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; + result[pos] = (src[pos] - mean[i]) / sd[i]; + } + } + } + } + return result; +} + +template SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.h b/tests/validation/reference/NormalizePlanarYUVLayer.h new file mode 100644 index 0000000000..c8740a383b --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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_NORMALIZE_PLANAR_YUV_LAYER_H__ +#define __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type * = nullptr> +SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ */ -- cgit v1.2.1