From 6d9d6f49aa05ad033676a219c1a98150fb8401f4 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 24 Dec 2018 16:10:47 +0000 Subject: COMPMID-1769: Add support for NEON StridedSlice,Split,Slice,Unstack Change-Id: I7d3c5e6858fed090410720f76947327e39bc72f8 Reviewed-on: https://review.mlplatform.org/450 Reviewed-by: Giuseppe Rossini Tested-by: Arm Jenkins Reviewed-by: Michalis Spyrou Reviewed-by: VidhyaSudhan Loganathan --- arm_compute/core/NEON/NEKernels.h | 3 +- .../core/NEON/kernels/NEStridedSliceKernel.h | 104 ++++++++++++ arm_compute/runtime/NEON/NEFunctions.h | 6 +- arm_compute/runtime/NEON/functions/NESlice.h | 69 ++++++++ arm_compute/runtime/NEON/functions/NESplit.h | 76 +++++++++ .../runtime/NEON/functions/NEStridedSlice.h | 75 +++++++++ arm_compute/runtime/NEON/functions/NEUnstack.h | 75 +++++++++ src/core/NEON/kernels/NEStridedSliceKernel.cpp | 187 +++++++++++++++++++++ src/runtime/NEON/functions/NESlice.cpp | 63 +++++++ src/runtime/NEON/functions/NESplit.cpp | 138 +++++++++++++++ src/runtime/NEON/functions/NEStridedSlice.cpp | 47 ++++++ src/runtime/NEON/functions/NEUnstack.cpp | 119 +++++++++++++ tests/validation/NEON/Slice.cpp | 135 +++++++++++++++ tests/validation/NEON/Split.cpp | 159 ++++++++++++++++++ tests/validation/NEON/StridedSlice.cpp | 138 +++++++++++++++ tests/validation/NEON/Unstack.cpp | 128 ++++++++++++++ 16 files changed, 1520 insertions(+), 2 deletions(-) create mode 100644 arm_compute/core/NEON/kernels/NEStridedSliceKernel.h create mode 100644 arm_compute/runtime/NEON/functions/NESlice.h create mode 100644 arm_compute/runtime/NEON/functions/NESplit.h create mode 100644 arm_compute/runtime/NEON/functions/NEStridedSlice.h create mode 100644 arm_compute/runtime/NEON/functions/NEUnstack.h create mode 100644 src/core/NEON/kernels/NEStridedSliceKernel.cpp create mode 100644 src/runtime/NEON/functions/NESlice.cpp create mode 100644 src/runtime/NEON/functions/NESplit.cpp create mode 100644 src/runtime/NEON/functions/NEStridedSlice.cpp create mode 100644 src/runtime/NEON/functions/NEUnstack.cpp create mode 100644 tests/validation/NEON/Slice.cpp create mode 100644 tests/validation/NEON/Split.cpp create mode 100644 tests/validation/NEON/StridedSlice.cpp create mode 100644 tests/validation/NEON/Unstack.cpp diff --git a/arm_compute/core/NEON/NEKernels.h b/arm_compute/core/NEON/NEKernels.h index e859519d94..95a3e0555b 100644 --- a/arm_compute/core/NEON/NEKernels.h +++ b/arm_compute/core/NEON/NEKernels.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018 ARM Limited. + * Copyright (c) 2016-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -115,6 +115,7 @@ #include "arm_compute/core/NEON/kernels/NESobel5x5Kernel.h" #include "arm_compute/core/NEON/kernels/NESobel7x7Kernel.h" #include "arm_compute/core/NEON/kernels/NESoftmaxLayerKernel.h" +#include "arm_compute/core/NEON/kernels/NEStridedSliceKernel.h" #include "arm_compute/core/NEON/kernels/NETableLookupKernel.h" #include "arm_compute/core/NEON/kernels/NEThresholdKernel.h" #include "arm_compute/core/NEON/kernels/NETileKernel.h" diff --git a/arm_compute/core/NEON/kernels/NEStridedSliceKernel.h b/arm_compute/core/NEON/kernels/NEStridedSliceKernel.h new file mode 100644 index 0000000000..a272a8118b --- /dev/null +++ b/arm_compute/core/NEON/kernels/NEStridedSliceKernel.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018-2019 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_NE_STRIDED_SLICE_KERNEL_H__ +#define __ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H__ + +#include "arm_compute/core/NEON/INEKernel.h" +#include "arm_compute/core/Types.h" + +#include + +namespace arm_compute +{ +// Forward declarations +class ITensor; + +/** Interface for the kernel to perform tensor strided slicing */ +class NEStridedSliceKernel : public INEKernel +{ +public: + const char *name() const override + { + return "NEStridedSliceKernel"; + } + /** Default constructor */ + NEStridedSliceKernel(); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + NEStridedSliceKernel(const NEStridedSliceKernel &) = delete; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + NEStridedSliceKernel &operator=(const NEStridedSliceKernel &) = delete; + /** Allow instances of this class to be moved */ + NEStridedSliceKernel(NEStridedSliceKernel &&) = default; + /** Allow instances of this class to be moved */ + NEStridedSliceKernel &operator=(NEStridedSliceKernel &&) = default; + /** Default destructor */ + ~NEStridedSliceKernel() = default; + /** Configure kernel + * + * @note Supported tensor rank: up to 4 + * + * @param[in] input Source tensor. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[out] output Destination tensor. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] begin_mask If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] end_mask If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] shrink_axis_mask If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. + * A slice of size 1 starting from starts[i] in the dimension must be preserved. + */ + void configure(const ITensor *input, ITensor *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask); + + /** Static function to check if given info will lead to a valid configuration of @ref CLStridedSliceKernel + * + * @note Supported tensor rank: up to 4 + * + * @param[in] input Source tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[in] output Destination tensor info. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] begin_mask If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] end_mask If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] shrink_axis_mask If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. + * A slice of size 1 starting from starts[i] in the dimension must be preserved. + */ + static Status validate(const ITensorInfo *input, const ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask); + + // Inherited methods overridden: + void run(const Window &window, const ThreadInfo &info) override; + +private: + const ITensor *_input; /**< Source tensor */ + ITensor *_output; /**< Destination tensor */ + Coordinates _starts_abs; /**< Absolute start coordinates */ + Coordinates _final_strides; /**< Final strides */ + int32_t _shrink_mask; /**< Shrink axis mask */ +}; +} // namespace arm_compute +#endif /*__ARM_COMPUTE_NE_STRIDED_SLICE_KERNEL_H__ */ diff --git a/arm_compute/runtime/NEON/NEFunctions.h b/arm_compute/runtime/NEON/NEFunctions.h index bfecbcf65e..53afb985f5 100644 --- a/arm_compute/runtime/NEON/NEFunctions.h +++ b/arm_compute/runtime/NEON/NEFunctions.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018 ARM Limited. + * Copyright (c) 2016-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -114,14 +114,18 @@ #include "arm_compute/runtime/NEON/functions/NEScharr3x3.h" #include "arm_compute/runtime/NEON/functions/NESelect.h" #include "arm_compute/runtime/NEON/functions/NESimpleAssemblyFunction.h" +#include "arm_compute/runtime/NEON/functions/NESlice.h" #include "arm_compute/runtime/NEON/functions/NESobel3x3.h" #include "arm_compute/runtime/NEON/functions/NESobel5x5.h" #include "arm_compute/runtime/NEON/functions/NESobel7x7.h" #include "arm_compute/runtime/NEON/functions/NESoftmaxLayer.h" +#include "arm_compute/runtime/NEON/functions/NESplit.h" +#include "arm_compute/runtime/NEON/functions/NEStridedSlice.h" #include "arm_compute/runtime/NEON/functions/NETableLookup.h" #include "arm_compute/runtime/NEON/functions/NEThreshold.h" #include "arm_compute/runtime/NEON/functions/NETile.h" #include "arm_compute/runtime/NEON/functions/NETranspose.h" +#include "arm_compute/runtime/NEON/functions/NEUnstack.h" #include "arm_compute/runtime/NEON/functions/NEUpsampleLayer.h" #include "arm_compute/runtime/NEON/functions/NEWarpAffine.h" #include "arm_compute/runtime/NEON/functions/NEWarpPerspective.h" diff --git a/arm_compute/runtime/NEON/functions/NESlice.h b/arm_compute/runtime/NEON/functions/NESlice.h new file mode 100644 index 0000000000..cc95584048 --- /dev/null +++ b/arm_compute/runtime/NEON/functions/NESlice.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2019 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_NE_SLICE_H__ +#define __ARM_COMPUTE_NE_SLICE_H__ + +#include "arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h" + +namespace arm_compute +{ +// Forward Declarations +class ITensor; + +/** Basic function to perform tensor slicing */ +class NESlice : public INESimpleFunctionNoBorder +{ +public: + /** Configure kernel + * + * @note Supported tensor rank: up to 4 + * @note Start indices must be non-negative. 0 <= starts[i] + * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. + * @note End indices are not inclusive unless negative. + * + * @param[in] input Source tensor. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[out] output Destination tensor. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + */ + void configure(const ITensor *input, ITensor *output, const Coordinates &starts, const Coordinates &ends); + + /** Static function to check if given info will lead to a valid configuration of @ref NESlice + * + * @note Supported tensor rank: up to 4 + * @note Start indices must be non-negative. 0 <= starts[i] + * @note End coordinates can be negative, which represents the number of elements before the end of that dimension. + * @note End indices are not inclusive unless negative. + * + * @param[in] input Source tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[in] output Destination tensor info. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * + * @return A status + */ + static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends); +}; +} // namespace arm_compute +#endif /* __ARM_COMPUTE_NE_SLICE_H__ */ diff --git a/arm_compute/runtime/NEON/functions/NESplit.h b/arm_compute/runtime/NEON/functions/NESplit.h new file mode 100644 index 0000000000..9f8aea41eb --- /dev/null +++ b/arm_compute/runtime/NEON/functions/NESplit.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018-2019 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_NESPLIT_H__ +#define __ARM_COMPUTE_NESPLIT_H__ + +#include "arm_compute/core/Types.h" + +#include "arm_compute/runtime/IFunction.h" +#include "arm_compute/runtime/NEON/functions/NESlice.h" + +#include +#include + +namespace arm_compute +{ +// Forward declarations +class ITensor; + +/** Basic function to split a tensor along a given axis */ +class NESplit : public IFunction +{ +public: + /** Default constructor */ + NESplit(); + /** Initialise the kernel's input and outputs. + * + * @param[in] input The input tensor. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32. + * @param[out] outputs A vector containing the output tensors. Data types supported: Same as @p input. + * The output tensors should match the input tensor dimensions for all shape dimensions apart + * from the split dimension. + * @param[in] axis Axis on which to split the input. + */ + void configure(const ITensor *input, const std::vector &outputs, unsigned int axis); + /** Static function to check if given info will lead to a valid configuration of @ref NESplit + * + * @param[in] input The input tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32. + * @param[in] outputs A vector containing the output tensors' info. Data types supported: Same as @p input. + * The output tensors should match the input tensor dimensions for all shape dimensions apart + * from the split dimension + * @param[in] axis Axis on which to split the input. + * + * @return a status + */ + static Status validate(const ITensorInfo *input, const std::vector &outputs, unsigned int axis); + + // Inherited methods overridden: + void run() override; + +private: + std::vector _outputs_vector; + std::unique_ptr _slice_functions; + unsigned int _num_outputs; +}; +} // namespace arm_compute +#endif /* __ARM_COMPUTE_NESPLIT_H__ */ diff --git a/arm_compute/runtime/NEON/functions/NEStridedSlice.h b/arm_compute/runtime/NEON/functions/NEStridedSlice.h new file mode 100644 index 0000000000..209c1ab812 --- /dev/null +++ b/arm_compute/runtime/NEON/functions/NEStridedSlice.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018-2019 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_NE_STRIDED_SLICE_H__ +#define __ARM_COMPUTE_NE_STRIDED_SLICE_H__ + +#include "arm_compute/runtime/NEON/INESimpleFunction.h" + +namespace arm_compute +{ +// Forward Declarations +class ITensor; + +/** Basic function to run @ref NEStridedSliceKernel */ +class NEStridedSlice : public INESimpleFunction +{ +public: + /** Configure kernel + * + * @note Supported tensor rank: up to 4 + * + * @param[in] input Source tensor. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[out] output Destination tensor. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. + * A slice of size 1 starting from starts[i] in the dimension must be preserved. + */ + void configure(const ITensor *input, ITensor *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0); + + /** Static function to check if given info will lead to a valid configuration of @ref NEStridedSlice + * + * @note Supported tensor rank: up to 4 + * + * @param[in] input Source tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[in] output Destination tensor info. Data type supported: Same as @p input + * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). + * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead. + * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. + * A slice of size 1 starting from starts[i] in the dimension must be preserved. + */ + static Status validate(const ITensorInfo *input, const ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0); +}; +} // namespace arm_compute +#endif /* __ARM_COMPUTE_NE_STRIDED_SLICE_H__ */ diff --git a/arm_compute/runtime/NEON/functions/NEUnstack.h b/arm_compute/runtime/NEON/functions/NEUnstack.h new file mode 100644 index 0000000000..7210afa914 --- /dev/null +++ b/arm_compute/runtime/NEON/functions/NEUnstack.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018-2019 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_NEUNSTACK_H__ +#define __ARM_COMPUTE_NEUNSTACK_H__ + +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/IFunction.h" + +#include "arm_compute/runtime/NEON/functions/NEStridedSlice.h" + +#include + +namespace arm_compute +{ +// Forward declarations +class ITensor; + +/** Basic function to unpack a rank-R tensor into rank-(R-1) tensors. This function calls the following functions: + * + * -# @ref NEStridedSlice + */ +class NEUnstack : public IFunction +{ +public: + /** Default constructor */ + NEUnstack(); + /** Set the input, output and unstacking axis. + * + * @param[in] input A tensor to be unstacked. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32. + * @param[in,out] output_vector A vector of tensors. Data types supported: Same as @p input. + * Note: The number of elements of the vector will be used as the number of slices to be taken from the axis. + * @param[in] axis The axis to unstack along. Valid values are [-R,R) where R is the input's rank. Negative values wrap around. + * + */ + void configure(const ITensor *input, const std::vector &output_vector, int axis); + /** Static function to check if given info will lead to a valid configuration of @ref NEUnstack + * + * @param[in] input Input tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32 + * @param[in] output_vector Vector of output tensors' info. Data types supported: Same as @p input. + * @param[in] axis The axis to unstack along. Valid values are [-R,R) where R is the input's rank. Negative values wrap around. + * + * @return a status + */ + static Status validate(const ITensorInfo *input, const std::vector &output_vector, int axis); + + // Inherited methods overridden: + void run() override; + +private: + unsigned int _num_slices; + std::unique_ptr _strided_slice_vector; +}; +} // namespace arm_compute +#endif /* __ARM_COMPUTE_NEUNSTACK_H__ */ diff --git a/src/core/NEON/kernels/NEStridedSliceKernel.cpp b/src/core/NEON/kernels/NEStridedSliceKernel.cpp new file mode 100644 index 0000000000..bb5756de93 --- /dev/null +++ b/src/core/NEON/kernels/NEStridedSliceKernel.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2018-2019 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/NEON/kernels/NEStridedSliceKernel.h" + +#include "arm_compute/core/CPP/Validate.h" +#include "arm_compute/core/IAccessWindow.h" +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/core/Window.h" + +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/helpers/bit_ops.h" +#include "arm_compute/core/utils/helpers/tensor_transform.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" + +namespace arm_compute +{ +namespace +{ +Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, + DataType::U8, DataType::S8, DataType::QASYMM8, + DataType::U16, DataType::S16, + DataType::U32, DataType::S32, + DataType::F16, DataType::F32); + + ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().num_dimensions() > 4); + ARM_COMPUTE_RETURN_ERROR_ON(starts.num_dimensions() > input->num_dimensions()); + ARM_COMPUTE_RETURN_ERROR_ON(ends.num_dimensions() > input->num_dimensions()); + ARM_COMPUTE_RETURN_ERROR_ON(strides.num_dimensions() > input->num_dimensions()); + ARM_COMPUTE_RETURN_ERROR_ON(std::any_of(strides.cbegin(), strides.cbegin() + strides.num_dimensions(), [](int i) + { + return i == 0; + })); + + // Get expected output shape + const TensorShape exp_output_shape = arm_compute::misc::shape_calculator::compute_strided_slice_shape(*input, + starts, ends, strides, + begin_mask, end_mask, shrink_axis_mask); + ARM_COMPUTE_RETURN_ERROR_ON(exp_output_shape.total_size() == 0); + + // Checks output if configured + if(output->total_size() != 0) + { + const TensorInfo exp_output_info = output->clone()->set_tensor_shape(exp_output_shape); + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &exp_output_info); + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); + } + + return Status{}; +} + +std::pair validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + // Output tensor auto initialization if not yet initialized + const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_strided_slice_shape(*input, + starts, ends, strides, + begin_mask, end_mask, shrink_axis_mask); + auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape)); + + // Create window + const unsigned int num_elems_processed_per_iteration = 1; + + Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); + output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); + + return std::make_pair(Status{}, win); +} + +void strided_slice_generic(const ITensor *input, ITensor *output, + const Coordinates &starts, const BiStrides &strides, int32_t shrink_axis_mask, + const Window &window) +{ + Iterator output_it(output, window); + const size_t width_size = input->info()->element_size(); + + const bool is_shrink_w = arm_compute::helpers::bit_ops::is_bit_set(shrink_axis_mask, 0); + const bool is_shrink_h = arm_compute::helpers::bit_ops::is_bit_set(shrink_axis_mask, 1); + const bool is_shrink_c = arm_compute::helpers::bit_ops::is_bit_set(shrink_axis_mask, 2); + const bool is_shrink_n = arm_compute::helpers::bit_ops::is_bit_set(shrink_axis_mask, 3); + + unsigned int index = 0; + const int idx_w = is_shrink_w ? 0 : index++; + const int idx_h = is_shrink_h ? 0 : index++; + const int idx_c = is_shrink_c ? 0 : index++; + const int idx_n = is_shrink_n ? 0 : index; + + BiStrides shrinked_strides; + shrinked_strides.set(0, is_shrink_w ? 0 : strides[0]); + shrinked_strides.set(1, is_shrink_h ? 0 : strides[1]); + shrinked_strides.set(2, is_shrink_c ? 0 : strides[2]); + shrinked_strides.set(3, is_shrink_n ? 0 : strides[3]); + + execute_window_loop(window, [&](const Coordinates & id) + { + const int w_coord = starts[0] + (id[idx_w] * shrinked_strides[0]); + const int h_coord = starts[1] + (id[idx_h] * shrinked_strides[1]); + const int c_coord = starts[2] + (id[idx_c] * shrinked_strides[2]); + const int n_coord = starts[3] + (id[idx_n] * shrinked_strides[3]); + + Coordinates in_coords(w_coord, h_coord, c_coord, n_coord); + std::copy_n(input->ptr_to_element(in_coords), width_size, output_it.ptr()); + }, + output_it); +} +} // namespace + +NEStridedSliceKernel::NEStridedSliceKernel() + : _input(nullptr), _output(nullptr), _starts_abs(), _final_strides(), _shrink_mask() +{ +} + +void NEStridedSliceKernel::configure(const ITensor *input, ITensor *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask)); + + _input = input; + _output = output; + _shrink_mask = shrink_axis_mask; + + const TensorShape &input_shape = input->info()->tensor_shape(); + + Coordinates ends_abs; + std::tie(_starts_abs, ends_abs, _final_strides) = arm_compute::helpers::tensor_transform::calculate_strided_slice_coords( + input_shape, + starts, ends, strides, + begin_mask, end_mask, shrink_axis_mask); + + // Configure kernel window + auto win_config = validate_and_configure_window(input->info(), output->info(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); + ARM_COMPUTE_ERROR_THROW_ON(win_config.first); + INEKernel::configure(win_config.second); +} + +Status NEStridedSliceKernel::validate(const ITensorInfo *input, const ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask)); + ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), + starts, ends, strides, begin_mask, end_mask, shrink_axis_mask) + .first); + + return Status{}; +} + +void NEStridedSliceKernel::run(const Window &window, const ThreadInfo &info) +{ + ARM_COMPUTE_UNUSED(info); + ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); + ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); + + // Dispatch kernel + strided_slice_generic(_input, _output, _starts_abs, _final_strides, _shrink_mask, window); +} +} // namespace arm_compute diff --git a/src/runtime/NEON/functions/NESlice.cpp b/src/runtime/NEON/functions/NESlice.cpp new file mode 100644 index 0000000000..03c2053b9b --- /dev/null +++ b/src/runtime/NEON/functions/NESlice.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NESlice.h" + +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/NEON/kernels/NEStridedSliceKernel.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/Validate.h" +#include "arm_compute/core/utils/helpers/tensor_transform.h" + +#include "support/ToolchainSupport.h" + +namespace arm_compute +{ +void NESlice::configure(const ITensor *input, ITensor *output, const Coordinates &starts, const Coordinates &ends) +{ + ARM_COMPUTE_ERROR_ON_NULLPTR(input); + + // Get absolute end coordinates + const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends); + + auto k = arm_compute::support::cpp14::make_unique(); + k->configure(input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0); + _kernel = std::move(k); +} + +Status NESlice::validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); + + // Check start dimensions for being non-negative + ARM_COMPUTE_RETURN_ERROR_ON(std::any_of(starts.cbegin(), starts.cbegin() + starts.num_dimensions(), [](int i) + { + return i < 0; + })); + + // Get absolute end coordinates + const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends); + + return NEStridedSliceKernel::validate(input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0); +} +} // namespace arm_compute diff --git a/src/runtime/NEON/functions/NESplit.cpp b/src/runtime/NEON/functions/NESplit.cpp new file mode 100644 index 0000000000..e947657934 --- /dev/null +++ b/src/runtime/NEON/functions/NESplit.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NESplit.h" + +#include "arm_compute/core/Error.h" +#include "arm_compute/core/Helpers.h" +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" + +#include "support/ToolchainSupport.h" + +namespace arm_compute +{ +NESplit::NESplit() + : _outputs_vector(), _slice_functions(), _num_outputs(0) +{ +} + +void NESplit::configure(const ITensor *input, const std::vector &outputs, unsigned int axis) +{ + // Create Slice functions + _num_outputs = outputs.size(); + _slice_functions = arm_compute::support::cpp14::make_unique(_num_outputs); + + // Get output shape + const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_split_shape(input->info(), axis, _num_outputs); + + // Extract output tensor info + std::vector outputs_info; + for(auto &output : outputs) + { + ARM_COMPUTE_ERROR_ON_NULLPTR(output); + outputs_info.emplace_back(output->info()); + } + + // Validate + ARM_COMPUTE_ERROR_THROW_ON(NESplit::validate(input->info(), outputs_info, axis)); + + const size_t axis_split_step = output_shape[axis]; + unsigned int axis_offset = 0; + + // Start/End coordinates + Coordinates start_coords; + Coordinates end_coords; + for(unsigned int d = 0; d < output_shape.num_dimensions(); ++d) + { + end_coords.set(d, -1); + } + + for(unsigned int i = 0; i < _num_outputs; i++) + { + // Update coordinate on axis + start_coords.set(axis, axis_offset); + end_coords.set(axis, axis_offset + axis_split_step); + + // Configure slice function + _slice_functions[i].configure(input, outputs[i], start_coords, end_coords); + + // Set valid region from shape + outputs[i]->info()->set_valid_region(ValidRegion(Coordinates(), output_shape)); + + // Update axis offset + axis_offset += axis_split_step; + } +} + +Status NESplit::validate(const ITensorInfo *input, const std::vector &outputs, unsigned int axis) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); + ARM_COMPUTE_RETURN_ERROR_ON(axis >= input->num_dimensions()); + ARM_COMPUTE_RETURN_ERROR_ON(outputs.size() < 2); + + // Get output shape + const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_split_shape(input, axis, outputs.size()); + ARM_COMPUTE_RETURN_ERROR_ON(output_shape.total_size() == 0); + + const size_t axis_split_step = output_shape[axis]; + unsigned int axis_offset = 0; + + // Start/End coordinates + Coordinates start_coords; + Coordinates end_coords; + for(unsigned int d = 0; d < output_shape.num_dimensions(); ++d) + { + end_coords.set(d, -1); + } + + // Validate output tensors + for(const auto &output : outputs) + { + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); + + // Output auto inizialitation if not yet initialized + TensorInfo tmp_output_info = *output->clone(); + auto_init_if_empty(tmp_output_info, input->clone()->set_is_resizable(true).set_tensor_shape(output_shape)); + + // Update coordinate on axis + start_coords.set(axis, axis_offset); + end_coords.set(axis, axis_offset + axis_split_step); + + ARM_COMPUTE_RETURN_ON_ERROR(NESlice::validate(input, output, start_coords, end_coords)); + axis_offset += axis_split_step; + } + + return Status{}; +} + +void NESplit::run() +{ + for(unsigned i = 0; i < _num_outputs; ++i) + { + _slice_functions[i].run(); + } +} +} // namespace arm_compute diff --git a/src/runtime/NEON/functions/NEStridedSlice.cpp b/src/runtime/NEON/functions/NEStridedSlice.cpp new file mode 100644 index 0000000000..53eb2b03b0 --- /dev/null +++ b/src/runtime/NEON/functions/NEStridedSlice.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NEStridedSlice.h" + +#include "arm_compute/core/NEON/kernels/NEStridedSliceKernel.h" +#include "arm_compute/core/Types.h" +#include "support/ToolchainSupport.h" + +namespace arm_compute +{ +void NEStridedSlice::configure(const ITensor *input, ITensor *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + auto k = arm_compute::support::cpp14::make_unique(); + k->configure(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); + _kernel = std::move(k); +} + +Status NEStridedSlice::validate(const ITensorInfo *input, const ITensorInfo *output, + const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) +{ + return NEStridedSliceKernel::validate(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); +} +} // namespace arm_compute diff --git a/src/runtime/NEON/functions/NEUnstack.cpp b/src/runtime/NEON/functions/NEUnstack.cpp new file mode 100644 index 0000000000..7532020973 --- /dev/null +++ b/src/runtime/NEON/functions/NEUnstack.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NEUnstack.h" + +#include "arm_compute/core/Error.h" +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/TensorInfo.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" + +namespace arm_compute +{ +namespace +{ +inline unsigned int wrap_axis(int axis, const ITensorInfo *const tensor) +{ + return wrap_around(axis, static_cast(tensor->num_dimensions())); +} + +inline void setup_slice_coordinates_and_mask(Coordinates &slice_start, int32_t &slice_end_mask, const unsigned int input_num_dimensions) +{ + // Setups up coordinates to slice the input tensor: start coordinates to all 0s and the unstacking axis of both Start/End to slice just one 2d tensor at a time. + Coordinates slice_end; + slice_start.set_num_dimensions(input_num_dimensions); + slice_end.set_num_dimensions(input_num_dimensions); + for(size_t k = 0; k < input_num_dimensions; ++k) + { + slice_start.set(k, 0); + slice_end.set(k, -1); + } + slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(slice_end); +} +} // namespace + +NEUnstack::NEUnstack() // NOLINT + : _num_slices(0), + _strided_slice_vector() +{ +} + +void NEUnstack::configure(const ITensor *input, const std::vector &output_vector, int axis) +{ + std::vector outputs_vector_info(output_vector.size()); + std::transform(output_vector.begin(), output_vector.end(), outputs_vector_info.begin(), [](ITensor * t) + { + ARM_COMPUTE_ERROR_ON_NULLPTR(t); + return t->info(); + }); + + ARM_COMPUTE_ERROR_ON_NULLPTR(input); + ARM_COMPUTE_ERROR_THROW_ON(NEUnstack::validate(input->info(), outputs_vector_info, axis)); + + // Wrap around negative values + const unsigned int axis_u = wrap_axis(axis, input->info()); + _num_slices = std::min(outputs_vector_info.size(), input->info()->dimension(axis_u)); + _strided_slice_vector = arm_compute::support::cpp14::make_unique(_num_slices); + + Coordinates slice_start; + int32_t slice_end_mask; + setup_slice_coordinates_and_mask(slice_start, slice_end_mask, input->info()->tensor_shape().num_dimensions()); + for(unsigned int slice = 0; slice < _num_slices; ++slice) + { + // Adjusts start and end coordinates to take a 2D slice at a time + slice_start.set(axis_u, slice); + _strided_slice_vector[slice].configure(input, output_vector[slice], slice_start, Coordinates(), BiStrides(), 0, slice_end_mask, (1 << axis_u)); + } +} + +Status NEUnstack::validate(const ITensorInfo *input, const std::vector &output_vector, int axis) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); + ARM_COMPUTE_RETURN_ERROR_ON(output_vector.empty()); + ARM_COMPUTE_RETURN_ERROR_ON(axis < (-static_cast(input->tensor_shape().num_dimensions()))); + ARM_COMPUTE_RETURN_ERROR_ON(axis >= static_cast(input->tensor_shape().num_dimensions())); + + const unsigned int num_slices = std::min(output_vector.size(), input->dimension(wrap_axis(axis, input))); + ARM_COMPUTE_RETURN_ERROR_ON(num_slices > input->dimension(wrap_axis(axis, input))); + ARM_COMPUTE_RETURN_ERROR_ON(num_slices > output_vector.size()); + + Coordinates slice_start; + int32_t slice_end_mask; + for(size_t k = 0; k < num_slices; ++k) + { + slice_start.set(wrap_axis(axis, input), k); + setup_slice_coordinates_and_mask(slice_start, slice_end_mask, input->tensor_shape().num_dimensions()); + ARM_COMPUTE_RETURN_ON_ERROR(NEStridedSlice::validate(input, output_vector[k], slice_start, Coordinates(), BiStrides(), 0, slice_end_mask, (1 << wrap_axis(axis, input)))); + } + return Status{}; +} + +void NEUnstack::run() +{ + for(unsigned i = 0; i < _num_slices; ++i) + { + _strided_slice_vector[i].run(); + } +} +} // namespace arm_compute diff --git a/tests/validation/NEON/Slice.cpp b/tests/validation/NEON/Slice.cpp new file mode 100644 index 0000000000..69506a5fac --- /dev/null +++ b/tests/validation/NEON/Slice.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NESlice.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" + +#include "tests/NEON/Accessor.h" +#include "tests/datasets/SliceOperationsDataset.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/SliceOperationsFixtures.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(Slice) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( + framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 2U, 5U, 3U), 1, DataType::F32), // Invalid input shape + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), // Negative begin + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), // Big number of coordinates + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32) + }), + framework::dataset::make("Starts", { Coordinates(3, 1, 0), Coordinates(-3, 1, 0), Coordinates(3, 1, 0), Coordinates(3, 1, 0) })), + framework::dataset::make("Ends", { Coordinates(13, 3, 0), Coordinates(13, 3, 1), Coordinates(13, 3, 1, 1), Coordinates(13, 3, 1) })), + framework::dataset::make("Expected", { false, false, false, true })), + input_info, starts, ends, expected) +{ + TensorInfo output_info; + const Status status = NESlice::validate(&input_info.clone()->set_is_resizable(false), &output_info, starts, ends); + ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +DATA_TEST_CASE(Configuration, + framework::DatasetMode::ALL, + combine(arm_compute::test::datasets::SmallSliceDataset(), framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F32 })), + shape, starts, ends, data_type) +{ + // Create tensors + Tensor src = create_tensor(shape, data_type); + Tensor dst; + + // Create and Configure function + NESlice slice; + slice.configure(&src, &dst, starts, ends); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape()); + validate(dst.info()->valid_region(), valid_region); +} + +template +using NESliceFixture = SliceFixture; + +TEST_SUITE(Float) +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, + NESliceFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallSliceDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NESliceFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeSliceDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() // FP16 +#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, + NESliceFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallSliceDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NESliceFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeSliceDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() // FP32 +TEST_SUITE_END() // Float + +TEST_SUITE_END() // Slice +TEST_SUITE_END() // NEON +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/Split.cpp b/tests/validation/NEON/Split.cpp new file mode 100644 index 0000000000..17360960e0 --- /dev/null +++ b/tests/validation/NEON/Split.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NESplit.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" + +#include "tests/NEON/Accessor.h" +#include "tests/datasets/SplitDataset.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/SplitFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(Split) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( + framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis + TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid number of splits + TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32) + }), + framework::dataset::make("Axis", { 4, 2, 2 })), + framework::dataset::make("Splits", { 4, 5, 4 })), + framework::dataset::make("Expected", { false, false, true })), + input_info, axis, splits, expected) +{ + std::vector outputs_info(splits); + std::vector outputs_info_ptr; + for(auto &output_info : outputs_info) + { + outputs_info_ptr.emplace_back(&output_info); + } + const Status status = NESplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis); + ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +DATA_TEST_CASE(Configuration, + framework::DatasetMode::ALL, + combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F32 })), + shape, axis, splits, data_type) +{ + // Create tensors + Tensor src = create_tensor(shape, data_type); + std::vector dsts(splits); + std::vector dsts_ptrs; + for(auto &dst : dsts) + { + dsts_ptrs.emplace_back(&dst); + } + + // Create and Configure function + NESplit split; + split.configure(&src, dsts_ptrs, axis); + + // Validate valid regions + for(auto &dst : dsts) + { + const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape()); + validate(dst.info()->valid_region(), valid_region); + } +} + +template +using NESplitFixture = SplitFixture; + +TEST_SUITE(Float) +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, + NESplitFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate outputs + for(unsigned int i = 0; i < _target.size(); ++i) + { + validate(Accessor(_target[i]), _reference[i]); + } +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NESplitFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate outputs + for(unsigned int i = 0; i < _target.size(); ++i) + { + validate(Accessor(_target[i]), _reference[i]); + } +} +TEST_SUITE_END() // FP16 +#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, + NESplitFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate outputs + for(unsigned int i = 0; i < _target.size(); ++i) + { + validate(Accessor(_target[i]), _reference[i]); + } +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NESplitFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate outputs + for(unsigned int i = 0; i < _target.size(); ++i) + { + validate(Accessor(_target[i]), _reference[i]); + } +} +TEST_SUITE_END() // FP32 +TEST_SUITE_END() // Float + +TEST_SUITE_END() // Split +TEST_SUITE_END() // NEON +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/StridedSlice.cpp b/tests/validation/NEON/StridedSlice.cpp new file mode 100644 index 0000000000..f94aed0d51 --- /dev/null +++ b/tests/validation/NEON/StridedSlice.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NEStridedSlice.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" + +#include "tests/NEON/Accessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/SliceOperationsDataset.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/SliceOperationsFixtures.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(StridedSlice) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( + framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 2U, 5U, 3U), 1, DataType::F32), // Invalid input shape + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), // Zero stride + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), // Big number of coordinates + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), // Invalid Coords/Strides + TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32) + }), + framework::dataset::make("Starts", { Coordinates(3, 1, 0), Coordinates(3, 1, 0), Coordinates(3, 1, 0), Coordinates(3, 1, 0), Coordinates(3, 1, 0) })), + framework::dataset::make("Ends", { Coordinates(13, 3, 0), Coordinates(13, 3, 1), Coordinates(13, 3, 1, 1), Coordinates(13, -1, 1), Coordinates(13, 3, 1) })), + framework::dataset::make("Strides", { BiStrides(2, 1, 1), BiStrides(2, 0, 1), BiStrides(2, 1, 1), BiStrides(2, -1, 1), BiStrides(2, 1, 1) })), + framework::dataset::make("Expected", { false, false, false, false, true })), + input_info, starts, ends, strides, expected) +{ + TensorInfo output_info; + ARM_COMPUTE_EXPECT(bool(NEStridedSlice::validate(&input_info.clone()->set_is_resizable(false), &output_info, starts, ends, strides)) == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +DATA_TEST_CASE(Configuration, + framework::DatasetMode::ALL, + combine(arm_compute::test::datasets::SmallStridedSliceDataset(), framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F32 })), + shape, starts, ends, strides, begin_mask, end_mask, shrink_mask, data_type) +{ + // Create tensors + Tensor src = create_tensor(shape, data_type); + Tensor dst; + + // Create and Configure function + NEStridedSlice strided_slice; + strided_slice.configure(&src, &dst, starts, ends, strides, begin_mask, end_mask, shrink_mask); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape()); + validate(dst.info()->valid_region(), valid_region); +} + +template +using NEStridedSliceFixture = StridedSliceFixture; + +TEST_SUITE(Float) +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, + NEStridedSliceFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallStridedSliceDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NEStridedSliceFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeStridedSliceDataset(), framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() // FP16 +#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, + NEStridedSliceFixture, + framework::DatasetMode::PRECOMMIT, + combine(datasets::SmallStridedSliceDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + NEStridedSliceFixture, + framework::DatasetMode::NIGHTLY, + combine(datasets::LargeStridedSliceDataset(), framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() // FP32 +TEST_SUITE_END() // Float + +TEST_SUITE_END() // StridedSlice +TEST_SUITE_END() // NEON + +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/Unstack.cpp b/tests/validation/NEON/Unstack.cpp new file mode 100644 index 0000000000..6be80df3c6 --- /dev/null +++ b/tests/validation/NEON/Unstack.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2018-2019 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/NEON/functions/NEUnstack.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" + +#include "tests/NEON/Accessor.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/UnstackFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const auto unstack_axis_dataset = framework::dataset::make("Axis", -3, 3); +const auto unstack_num_dataset = framework::dataset::make("Num", 1, 3); // The length of the dimension axis +const auto unstack_dataset_small = datasets::Small3DShapes() * unstack_axis_dataset * unstack_num_dataset; +} //namespace + +TEST_SUITE(NEON) +TEST_SUITE(Unstack) + +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( + framework::dataset::make("InputInfo", +{ + TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, 1 slice on x axis + TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails because axis > input's rank + TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank) + TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // passes, 3 slices along X + TensorInfo(TensorShape(13U, 7U, 5U), 1, DataType::S16), // fails, too few output slices + TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types +}), +framework::dataset::make("OutputInfo", +{ + std::vector{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) }, std::vector{ TensorInfo(TensorShape(2U, 3U), 1, DataType::U8) }, std::vector{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) }, + + std::vector{ TensorInfo(TensorShape(7U, 5U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U), 1, DataType::S32) }, std::vector{ TensorInfo(TensorShape(7U, 5U), 1, DataType::S16) }, std::vector{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) }, +})), +framework::dataset::make("Axis", { -3, 3, -4, -3, 1, 1 })), +framework::dataset::make("Num", { 1, 1, 1, 1, 0, 1 })), +framework::dataset::make("Expected", { true, false, false, true, false, false })), +input_info, output_info, axis, num, expected) +{ + std::vector ti(output_info); + std::vector vec(num); + for(size_t j = 0; j < vec.size(); ++j) + { + vec[j] = &ti[j]; + } + ARM_COMPUTE_EXPECT(bool(NEUnstack::validate(&input_info.clone()->set_is_resizable(false), vec, axis)) == expected, framework::LogLevel::ERRORS); +} + +template +using NEUnstackFixture = UnstackValidationFixture; + +TEST_SUITE(F32) +FIXTURE_DATA_TEST_CASE(RunSmall, NEUnstackFixture, framework::DatasetMode::PRECOMMIT, unstack_dataset_small * framework::dataset::make("DataType", { DataType::F32 })) +{ + ARM_COMPUTE_ERROR_ON(_target.size() != _reference.size()); + // Validate output + for(size_t k = 0; k < _target.size(); ++k) + { + validate(Accessor(_target[k]), _reference[k]); + } +} +TEST_SUITE_END() // F32 + +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +TEST_SUITE(F16) +FIXTURE_DATA_TEST_CASE(RunSmall, NEUnstackFixture, framework::DatasetMode::PRECOMMIT, unstack_dataset_small * framework::dataset::make("DataType", { DataType::F16 })) +{ + ARM_COMPUTE_ERROR_ON(_target.size() != _reference.size()); + // Validate output + for(size_t k = 0; k < _target.size(); ++k) + { + validate(Accessor(_target[k]), _reference[k]); + } +} +TEST_SUITE_END() // F16 +#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ + +TEST_SUITE(Quantized) +FIXTURE_DATA_TEST_CASE(RunSmall, NEUnstackFixture, framework::DatasetMode::PRECOMMIT, unstack_dataset_small * framework::dataset::make("DataType", { DataType::QASYMM8 })) +{ + ARM_COMPUTE_ERROR_ON(_target.size() != _reference.size()); + // Validate output + for(size_t k = 0; k < _target.size(); ++k) + { + validate(Accessor(_target[k]), _reference[k]); + } +} +TEST_SUITE_END() // QASYMM8 + +TEST_SUITE_END() // Unstack +TEST_SUITE_END() // NEON +} // namespace validation +} // namespace test +} // namespace arm_compute -- cgit v1.2.1