aboutsummaryrefslogtreecommitdiff
path: root/arm_compute
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-01-17 09:40:27 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:42 +0000
commit5237e01c342b9301951a799842e9c48813b66fd4 (patch)
tree257e9f92e0599c0de68668ce568a3a4f37c1f0b6 /arm_compute
parent652bde553f506caac4c563988dc9baf746f9584d (diff)
downloadComputeLibrary-5237e01c342b9301951a799842e9c48813b66fd4.tar.gz
COMPMID-838 Implement CLPermute
Change-Id: I6d97b649f1ebc289c9e6f8949e67740a6b3cbcb2 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/116636 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r--arm_compute/core/CL/CLKernels.h3
-rw-r--r--arm_compute/core/CL/kernels/CLPermuteKernel.h67
-rw-r--r--arm_compute/core/Window.h21
-rw-r--r--arm_compute/core/Window.inl16
-rw-r--r--arm_compute/runtime/CL/CLFunctions.h3
-rw-r--r--arm_compute/runtime/CL/functions/CLPermute.h49
6 files changed, 156 insertions, 3 deletions
diff --git a/arm_compute/core/CL/CLKernels.h b/arm_compute/core/CL/CLKernels.h
index 64687fb26a..e9a1fde71a 100644
--- a/arm_compute/core/CL/CLKernels.h
+++ b/arm_compute/core/CL/CLKernels.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -88,6 +88,7 @@
#include "arm_compute/core/CL/kernels/CLNonLinearFilterKernel.h"
#include "arm_compute/core/CL/kernels/CLNonMaximaSuppression3x3Kernel.h"
#include "arm_compute/core/CL/kernels/CLNormalizationLayerKernel.h"
+#include "arm_compute/core/CL/kernels/CLPermuteKernel.h"
#include "arm_compute/core/CL/kernels/CLPixelWiseMultiplicationKernel.h"
#include "arm_compute/core/CL/kernels/CLPoolingLayerKernel.h"
#include "arm_compute/core/CL/kernels/CLQuantizationLayerKernel.h"
diff --git a/arm_compute/core/CL/kernels/CLPermuteKernel.h b/arm_compute/core/CL/kernels/CLPermuteKernel.h
new file mode 100644
index 0000000000..8f96529d32
--- /dev/null
+++ b/arm_compute/core/CL/kernels/CLPermuteKernel.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_CLPERMUTEKERNEL_H__
+#define __ARM_COMPUTE_CLPERMUTEKERNEL_H__
+
+#include "arm_compute/core/CL/ICLKernel.h"
+
+namespace arm_compute
+{
+class ICLTensor;
+
+/** OpenCL kernel to perform tensor permutation.
+ *
+ * Permutes given a permutation vector
+ */
+class CLPermuteKernel : public ICLKernel
+{
+public:
+ /** Default constructor */
+ CLPermuteKernel();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLPermuteKernel(const CLPermuteKernel &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLPermuteKernel &operator=(const CLPermuteKernel &) = delete;
+ /** Allow instances of this class to be moved */
+ CLPermuteKernel(CLPermuteKernel &&) = default;
+ /** Allow instances of this class to be moved */
+ CLPermuteKernel &operator=(CLPermuteKernel &&) = default;
+ /** Set the input and output of the kernel.
+ *
+ * @param[in] input The input tensor to permute. Data types supported: U8/S8/QS8/QASYMM8/U16/S16/QS16/F16/U32/S32/F32
+ * @param[in] output The output tensor. Data types supported: Same as @p input
+ * @param[in] perm Permutation vector
+ */
+ void configure(const ICLTensor *input, ICLTensor *output, const PermutationVector &perm);
+
+ // Inherited methods overridden:
+ void run(const Window &window, cl::CommandQueue &queue) override;
+
+private:
+ const ICLTensor *_input;
+ ICLTensor *_output;
+ PermutationVector _perm;
+};
+} // arm_compute
+#endif /*__ARM_COMPUTE_CLPERMUTEKERNEL_H__ */
diff --git a/arm_compute/core/Window.h b/arm_compute/core/Window.h
index 654f5ed4f8..c890bf8f9e 100644
--- a/arm_compute/core/Window.h
+++ b/arm_compute/core/Window.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -245,6 +245,14 @@ public:
{
return first_slice_window<3>();
};
+ /** First 4D slice of the window
+ *
+ * @return The first slice of the window.
+ */
+ Window first_slice_window_4D() const
+ {
+ return first_slice_window<4>();
+ };
/** Slide the passed 1D window slice.
*
* If slice contains the last slice then it will remain unchanged and false will be returned.
@@ -305,6 +313,17 @@ public:
*/
Window collapse_if_possible(const Window &full_window, size_t first) const;
+ /* Collapse the dimensions higher than @p first.
+ *
+ * A dimension is collapsable if it starts from 0 and matches the corresponding dimension in the full_window
+ *
+ * @param[in] full_window Full window @p window has been created from.
+ * @param[in] first Dimensions into which the following are collapsed.
+ *
+ * @return Collapsed window if successful.
+ */
+ Window collapse(const Window &full_window, size_t first) const;
+
private:
/** First slice of the window
*
diff --git a/arm_compute/core/Window.inl b/arm_compute/core/Window.inl
index e46a0ec8f7..1b21820f90 100644
--- a/arm_compute/core/Window.inl
+++ b/arm_compute/core/Window.inl
@@ -72,6 +72,22 @@ inline Window Window::collapse_if_possible(const Window &full_window, size_t fir
return collapsed;
}
+inline Window Window::collapse(const Window &full_window, size_t first) const
+{
+ Window collapsed = collapse_if_possible(full_window, first);
+ // Make sure that the window has collapsed
+ int end = _dims[first].end();
+ int start = 0;
+ ARM_COMPUTE_UNUSED(start);
+ for(size_t d = first + 1; d < Coordinates::num_max_dimensions; ++d)
+ {
+ start = end * _dims[d].start();
+ end *= _dims[d].end();
+ }
+ ARM_COMPUTE_ERROR_ON((collapsed[first].end() != end) || (collapsed[first].start() != start));
+ return collapsed;
+}
+
inline void Window::shift(size_t dimension, int shift_value)
{
ARM_COMPUTE_ERROR_ON(dimension >= Coordinates::num_max_dimensions);
diff --git a/arm_compute/runtime/CL/CLFunctions.h b/arm_compute/runtime/CL/CLFunctions.h
index 1154ab79aa..630b9535d9 100644
--- a/arm_compute/runtime/CL/CLFunctions.h
+++ b/arm_compute/runtime/CL/CLFunctions.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -86,6 +86,7 @@
#include "arm_compute/runtime/CL/functions/CLNonMaximaSuppression3x3.h"
#include "arm_compute/runtime/CL/functions/CLNormalizationLayer.h"
#include "arm_compute/runtime/CL/functions/CLOpticalFlow.h"
+#include "arm_compute/runtime/CL/functions/CLPermute.h"
#include "arm_compute/runtime/CL/functions/CLPhase.h"
#include "arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h"
#include "arm_compute/runtime/CL/functions/CLPoolingLayer.h"
diff --git a/arm_compute/runtime/CL/functions/CLPermute.h b/arm_compute/runtime/CL/functions/CLPermute.h
new file mode 100644
index 0000000000..ef8ba31019
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLPermute.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_CLPERMUTE_H__
+#define __ARM_COMPUTE_CLPERMUTE_H__
+
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
+
+#include <cstdint>
+
+namespace arm_compute
+{
+class ICLTensor;
+
+/** Basic function to execute an @ref CLPermuteKernel. */
+class CLPermute : public ICLSimpleFunction
+{
+public:
+ /** Set the input and output tensors.
+ *
+ * @param[in] input The input tensor to permute. Data types supported: U8/S8/QS8/QASYMM8/U16/S16/QS16/F16/U32/S32/F32
+ * @param[in] output The output tensor. Data types supported: Same as @p input
+ * @param[in] perm Permutation vector
+ */
+ void configure(const ICLTensor *input, ICLTensor *output, const PermutationVector &perm);
+};
+}
+#endif /*__ARM_COMPUTE_CLPERMUTE_H__ */