aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-01-30 12:14:24 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit82833b80b1a28ff32fe3c3b2f4996fa21a08bbbc (patch)
treee279d828640dbc4d03cccb8c4827210a6ce5b64b
parentba8fcb0297ec1e7f8efea6a2f8211a0023942b44 (diff)
downloadComputeLibrary-82833b80b1a28ff32fe3c3b2f4996fa21a08bbbc.tar.gz
COMPMID-765 : NEON Wrapper initial traits and overloads
Change-Id: Iea4c4732d19e8cf9b245ac2a9f75b2aa70a5839e Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/118149 Reviewed-by: Michele DiGiorgio <michele.digiorgio@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
-rw-r--r--arm_compute/core/NEON/wrapper/intrinsics/and.h60
-rw-r--r--arm_compute/core/NEON/wrapper/intrinsics/load.h68
-rw-r--r--arm_compute/core/NEON/wrapper/intrinsics/store.h62
-rw-r--r--arm_compute/core/NEON/wrapper/traits.h65
-rw-r--r--arm_compute/core/NEON/wrapper/wrapper.h33
-rw-r--r--src/core/NEON/kernels/NEBitwiseAndKernel.cpp16
6 files changed, 298 insertions, 6 deletions
diff --git a/arm_compute/core/NEON/wrapper/intrinsics/and.h b/arm_compute/core/NEON/wrapper/intrinsics/and.h
new file mode 100644
index 0000000000..9b5cfd6b89
--- /dev/null
+++ b/arm_compute/core/NEON/wrapper/intrinsics/and.h
@@ -0,0 +1,60 @@
+/*
+ * 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_WRAPPER_AND_H__
+#define __ARM_COMPUTE_WRAPPER_AND_H__
+
+#include "arm_compute/core/NEON/wrapper/traits.h"
+
+#include <arm_neon.h>
+
+namespace arm_compute
+{
+namespace wrapper
+{
+#define VAND_IMPL(stype, vtype, prefix, postfix) \
+ inline vtype vand(const vtype &a, const vtype &b) \
+ { \
+ return prefix##_##postfix(a, b); \
+ }
+
+VAND_IMPL(uint8_t, uint8x8_t, vand, u8)
+VAND_IMPL(int8_t, int8x8_t, vand, s8)
+VAND_IMPL(uint16_t, uint16x4_t, vand, u16)
+VAND_IMPL(int16_t, int16x4_t, vand, s16)
+VAND_IMPL(uint32_t, uint32x2_t, vand, u32)
+VAND_IMPL(int32_t, int32x2_t, vand, s32)
+VAND_IMPL(uint64_t, uint64x1_t, vand, u64)
+VAND_IMPL(int64_t, int64x1_t, vand, s64)
+
+VAND_IMPL(uint8_t, uint8x16_t, vandq, u8)
+VAND_IMPL(int8_t, int8x16_t, vandq, s8)
+VAND_IMPL(uint16_t, uint16x8_t, vandq, u16)
+VAND_IMPL(int16_t, int16x8_t, vandq, s16)
+VAND_IMPL(uint32_t, uint32x4_t, vandq, u32)
+VAND_IMPL(int32_t, int32x4_t, vandq, s32)
+VAND_IMPL(uint64_t, uint64x2_t, vandq, u64)
+VAND_IMPL(int64_t, int64x2_t, vandq, s64)
+}
+}
+#endif /* __ARM_COMPUTE_WRAPPER_AND_H__ */
diff --git a/arm_compute/core/NEON/wrapper/intrinsics/load.h b/arm_compute/core/NEON/wrapper/intrinsics/load.h
new file mode 100644
index 0000000000..9629f2b4e0
--- /dev/null
+++ b/arm_compute/core/NEON/wrapper/intrinsics/load.h
@@ -0,0 +1,68 @@
+/*
+ * 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_WRAPPER_LOAD_H__
+#define __ARM_COMPUTE_WRAPPER_LOAD_H__
+
+#include "arm_compute/core/NEON/wrapper/traits.h"
+
+#include <arm_neon.h>
+
+namespace arm_compute
+{
+namespace wrapper
+{
+#define VLOAD_IMPL(stype, vtype, postfix) \
+ inline vtype vload(const stype *ptr) \
+ { \
+ return vld1_##postfix(ptr); \
+ }
+
+VLOAD_IMPL(uint8_t, uint8x8_t, u8)
+VLOAD_IMPL(int8_t, int8x8_t, s8)
+VLOAD_IMPL(uint16_t, uint16x4_t, u16)
+VLOAD_IMPL(int16_t, int16x4_t, s16)
+VLOAD_IMPL(uint32_t, uint32x2_t, u32)
+VLOAD_IMPL(int32_t, int32x2_t, s32)
+//VLOAD_IMPL(uint64_t, uint64x1_t, u64)
+//VLOAD_IMPL(int64_t, int64x1_t, s64)
+VLOAD_IMPL(float, float32x2_t, f32)
+
+#define VLOADQ_IMPL(stype, vtype, postfix) \
+ inline vtype vloadq(const stype *ptr) \
+ { \
+ return vld1q_##postfix(ptr); \
+ }
+
+VLOADQ_IMPL(uint8_t, uint8x16_t, u8)
+VLOADQ_IMPL(int8_t, int8x16_t, s8)
+VLOADQ_IMPL(uint16_t, uint16x8_t, u16)
+VLOADQ_IMPL(int16_t, int16x8_t, s16)
+VLOADQ_IMPL(uint32_t, uint32x4_t, u32)
+VLOADQ_IMPL(int32_t, int32x4_t, s32)
+//VLOAD_IMPL(uint64_t, uint64x1_t, u64)
+//VLOAD_IMPL(int64_t, int64x1_t, s64)
+VLOADQ_IMPL(float, float32x4_t, f32)
+}
+}
+#endif /* __ARM_COMPUTE_WRAPPER_LOAD_H__ */
diff --git a/arm_compute/core/NEON/wrapper/intrinsics/store.h b/arm_compute/core/NEON/wrapper/intrinsics/store.h
new file mode 100644
index 0000000000..de57b7350f
--- /dev/null
+++ b/arm_compute/core/NEON/wrapper/intrinsics/store.h
@@ -0,0 +1,62 @@
+/*
+ * 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_WRAPPER_STORE_H__
+#define __ARM_COMPUTE_WRAPPER_STORE_H__
+
+#include "arm_compute/core/NEON/wrapper/traits.h"
+
+#include <arm_neon.h>
+
+namespace arm_compute
+{
+namespace wrapper
+{
+#define VSTORE_IMPL(stype, vtype, prefix, postfix) \
+ inline void vstore(stype *ptr, vtype val) \
+ { \
+ prefix##_##postfix(ptr, val); \
+ }
+
+VSTORE_IMPL(uint8_t, uint8x8_t, vst1, u8)
+VSTORE_IMPL(int8_t, int8x8_t, vst1, s8)
+VSTORE_IMPL(uint16_t, uint16x4_t, vst1, u16)
+VSTORE_IMPL(int16_t, int16x4_t, vst1, s16)
+VSTORE_IMPL(uint32_t, uint32x2_t, vst1, u32)
+VSTORE_IMPL(int32_t, int32x2_t, vst1, s32)
+//VSTORE_IMPL(uint64_t, 1, vst1, u64)
+//VSTORE_IMPL(int64_t, 1, vst1, s64)
+VSTORE_IMPL(float, float32x2_t, vst1, f32)
+
+VSTORE_IMPL(uint8_t, uint8x16_t, vst1q, u8)
+VSTORE_IMPL(int8_t, int8x16_t, vst1q, s8)
+VSTORE_IMPL(uint16_t, uint16x8_t, vst1q, u16)
+VSTORE_IMPL(int16_t, int16x8_t, vst1q, s16)
+VSTORE_IMPL(uint32_t, uint32x4_t, vst1q, u32)
+VSTORE_IMPL(int32_t, int32x4_t, vst1q, s32)
+//VSTORE_IMPL(uint64_t, 2, vst1q, u64)
+//VSTORE_IMPL(int64_t, 2, vst1q, s64)
+VSTORE_IMPL(float, float32x4_t, vst1q, f32)
+}
+}
+#endif /* __ARM_COMPUTE_WRAPPER_STORE_H__ */
diff --git a/arm_compute/core/NEON/wrapper/traits.h b/arm_compute/core/NEON/wrapper/traits.h
new file mode 100644
index 0000000000..045839cf48
--- /dev/null
+++ b/arm_compute/core/NEON/wrapper/traits.h
@@ -0,0 +1,65 @@
+/*
+ * 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_WRAPPER_TRAITS_H__
+#define __ARM_COMPUTE_WRAPPER_TRAITS_H__
+
+#include <arm_neon.h>
+
+namespace arm_compute
+{
+namespace wrapper
+{
+namespace traits
+{
+// *INDENT-OFF*
+// clang-format off
+
+/** Create the appropriate NEON vector given its type and size */
+template <typename T, int S> struct neon_vector;
+/** Specializations */
+template <> struct neon_vector<uint8_t, 8>{ using type = uint8x8_t; };
+template <> struct neon_vector<int8_t, 8>{ using type = int8x8_t; };
+template <> struct neon_vector<uint8_t, 16>{ using type = uint8x16_t; };
+template <> struct neon_vector<int8_t, 16>{ using type = int8x16_t; };
+template <> struct neon_vector<uint16_t, 4>{ using type = uint16x4_t; };
+template <> struct neon_vector<int16_t, 4>{ using type = int16x4_t; };
+template <> struct neon_vector<uint16_t, 8>{ using type = uint16x8_t; };
+template <> struct neon_vector<int16_t, 8>{ using type = int16x8_t; };
+template <> struct neon_vector<uint32_t, 2>{ using type = uint32x2_t; };
+template <> struct neon_vector<int32_t, 2>{ using type = int32x2_t; };
+template <> struct neon_vector<uint32_t, 4>{ using type = uint32x4_t; };
+template <> struct neon_vector<int32_t, 4>{ using type = int32x4_t; };
+template <> struct neon_vector<uint64_t, 1>{ using type = uint64x1_t; };
+template <> struct neon_vector<int64_t, 1>{ using type = int64x1_t; };
+template <> struct neon_vector<uint64_t, 2>{ using type = uint64x2_t; };
+template <> struct neon_vector<int64_t, 2>{ using type = int64x2_t; };
+template <> struct neon_vector<float_t, 2>{ using type = float32x2_t; };
+template <> struct neon_vector<float_t, 4>{ using type = float32x4_t; };
+template <typename T, int S> using neon_vector_t = typename neon_vector<T, S>::type;
+// clang-format on
+// *INDENT-ON*
+}
+}
+}
+#endif /* __ARM_COMPUTE_WRAPPER_TRAITS_H__ */
diff --git a/arm_compute/core/NEON/wrapper/wrapper.h b/arm_compute/core/NEON/wrapper/wrapper.h
new file mode 100644
index 0000000000..9676d04d71
--- /dev/null
+++ b/arm_compute/core/NEON/wrapper/wrapper.h
@@ -0,0 +1,33 @@
+/*
+ * 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_WRAPPER_H__
+#define __ARM_COMPUTE_WRAPPER_H__
+
+#include "arm_compute/core/NEON/wrapper/traits.h"
+
+#include "arm_compute/core/NEON/wrapper/intrinsics/and.h"
+#include "arm_compute/core/NEON/wrapper/intrinsics/load.h"
+#include "arm_compute/core/NEON/wrapper/intrinsics/store.h"
+
+#endif /* __ARM_COMPUTE_WRAPPER_H__ */
diff --git a/src/core/NEON/kernels/NEBitwiseAndKernel.cpp b/src/core/NEON/kernels/NEBitwiseAndKernel.cpp
index 3888300899..c1e3e1f0bc 100644
--- a/src/core/NEON/kernels/NEBitwiseAndKernel.cpp
+++ b/src/core/NEON/kernels/NEBitwiseAndKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -25,6 +25,7 @@
#include "arm_compute/core/Helpers.h"
#include "arm_compute/core/ITensor.h"
+#include "arm_compute/core/NEON/wrapper/wrapper.h"
#include "arm_compute/core/Types.h"
#include "arm_compute/core/Validate.h"
@@ -32,6 +33,7 @@
#include <cstdint>
using namespace arm_compute;
+using namespace arm_compute::wrapper;
namespace arm_compute
{
@@ -40,12 +42,14 @@ class Coordinates;
namespace
{
-inline void bitwise_and_U8_U8_U8(const uint8_t *__restrict input1, const uint8_t *__restrict input2, uint8_t *__restrict output)
+template <typename T, int S>
+inline void bitwise_and(const T *__restrict input1, const T *__restrict input2, T *__restrict output)
{
- const uint8x16_t val1 = vld1q_u8(input1);
- const uint8x16_t val2 = vld1q_u8(input2);
+ using type = typename wrapper::traits::neon_vector<T, S>::type;
+ const type val1 = vloadq(static_cast<const T *>(input1));
+ const type val2 = vloadq(static_cast<const T *>(input2));
- vst1q_u8(output, vandq_u8(val1, val2));
+ vstore(static_cast<T *>(output), vand(val1, val2));
}
} // namespace
@@ -104,7 +108,7 @@ void NEBitwiseAndKernel::run(const Window &window, const ThreadInfo &info)
execute_window_loop(window, [&](const Coordinates & id)
{
- bitwise_and_U8_U8_U8(input1.ptr(), input2.ptr(), output.ptr());
+ bitwise_and<uint8_t, 16>(input1.ptr(), input2.ptr(), output.ptr());
},
input1, input2, output);
}