Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef ARM_COMPUTE_HELPER_H |
| 25 | #define ARM_COMPUTE_HELPER_H |
| 26 | |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 27 | #include "load_store_utility.h" |
| 28 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 29 | #if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 31 | #endif // defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 32 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 33 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 34 | #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 35 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 36 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 37 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 38 | #pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 39 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 40 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 41 | #if defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf) |
steniu01 | f01f9de | 2017-09-27 17:00:11 +0100 | [diff] [blame] | 42 | #pragma OPENCL EXTENSION cl_arm_printf : enable |
Georgios Pinitas | 238c97c | 2018-08-31 17:28:29 +0100 | [diff] [blame] | 43 | #endif // defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | |
Usama Arif | e2428a0 | 2019-05-09 11:03:17 +0100 | [diff] [blame] | 45 | #define GPU_ARCH_MIDGARD 0x100 |
| 46 | #define GPU_ARCH_BIFROST 0x200 |
SiCong Li | a3cf241 | 2022-07-01 15:01:10 +0100 | [diff] [blame] | 47 | #define GPU_ARCH_VALHALL 0x300 |
Usama Arif | e2428a0 | 2019-05-09 11:03:17 +0100 | [diff] [blame] | 48 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 49 | /** Concatenate two inputs. |
| 50 | * |
| 51 | * @param[in] a The first input to be concatenated |
| 52 | * @param[in] b The second input to be concatenated |
| 53 | * |
| 54 | * @return The concatenated output |
| 55 | */ |
Gian Marco Iodice | 43a129e | 2019-05-14 10:14:08 +0100 | [diff] [blame] | 56 | #define CONCAT(a, b) a##b |
| 57 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 58 | /** Expand the given vector |
| 59 | * |
| 60 | * @param[in] x The vector to be expanded |
| 61 | * |
| 62 | * @return The expanded output |
| 63 | */ |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 64 | #define EXPAND(x) x |
| 65 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 66 | /** Clamp the given value between an upper and lower bound. |
| 67 | * |
| 68 | * @param[in] x The value to be clamped |
| 69 | * @param[in] min_val The lower bound |
| 70 | * @param[in] max_val The upper bound |
| 71 | * |
| 72 | * @return The clamped value. |
| 73 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | #define CLAMP(x, min_val, max_val) min(max(x, min_val), max_val) |
| 75 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 76 | /** REVn reverses the given vector whose size is n. |
| 77 | * @name REVn |
| 78 | * |
| 79 | * @param[in] x The vector to be reversed |
| 80 | * |
| 81 | * @return The reversed vector |
| 82 | * @{ |
| 83 | */ |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 84 | #define REV1(x) ((x)) |
| 85 | #define REV2(x) ((x).s10) |
| 86 | #define REV3(x) ((x).s210) |
| 87 | #define REV4(x) ((x).s3210) |
| 88 | #define REV8(x) ((x).s76543210) |
| 89 | #define REV16(x) ((x).sFEDCBA9876543210) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 90 | /** @} */ // end of group REVn |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 91 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 92 | /** Reverse the given vector. |
| 93 | * @name REVERSE |
| 94 | * |
| 95 | * @param[in] x The vector to be reversed |
| 96 | * @param[in] s The size of the vector |
| 97 | * |
| 98 | * @return The reversed vector |
| 99 | * @{ |
| 100 | */ |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 101 | #define REVERSE_STR(x, s) REV##s((x)) |
| 102 | #define REVERSE(x, s) REVERSE_STR(x, s) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 103 | /** @} */ // end of group REVERSE |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 104 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 105 | /** Circular-right-shift (rotate-right) the vector of size s by the amount of n. |
| 106 | * @name ROTs_n |
| 107 | * |
| 108 | * @param[in] x The vector to be shifted |
| 109 | * |
| 110 | * @return The shifted vector |
| 111 | * @{ |
| 112 | */ |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 113 | #define ROT1_0(x) ((x)) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 114 | #define ROT1_1(x) ((x)) |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 115 | |
| 116 | #define ROT2_0(x) ((x)) |
| 117 | #define ROT2_1(x) ((x).s10) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 118 | #define ROT2_2(x) ((x)) |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 119 | |
| 120 | #define ROT3_0(x) ((x)) |
| 121 | #define ROT3_1(x) ((x).s201) |
| 122 | #define ROT3_2(x) ((x).s120) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 123 | #define ROT3_3(x) ((x)) |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 124 | |
| 125 | #define ROT4_0(x) ((x)) |
| 126 | #define ROT4_1(x) ((x).s3012) |
| 127 | #define ROT4_2(x) ((x).s2301) |
| 128 | #define ROT4_3(x) ((x).s1230) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 129 | #define ROT4_4(x) ((x)) |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 130 | |
| 131 | #define ROT8_0(x) ((x)) |
| 132 | #define ROT8_1(x) ((x).s70123456) |
| 133 | #define ROT8_2(x) ((x).s67012345) |
| 134 | #define ROT8_3(x) ((x).s56701234) |
| 135 | #define ROT8_4(x) ((x).s45670123) |
| 136 | #define ROT8_5(x) ((x).s34567012) |
| 137 | #define ROT8_6(x) ((x).s23456701) |
| 138 | #define ROT8_7(x) ((x).s12345670) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 139 | #define ROT8_8(x) ((x)) |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 140 | |
| 141 | #define ROT16_0(x) ((x)) |
| 142 | #define ROT16_1(x) ((x).sF0123456789ABCDE) |
| 143 | #define ROT16_2(x) ((x).sEF0123456789ABCD) |
| 144 | #define ROT16_3(x) ((x).sDEF0123456789ABC) |
| 145 | #define ROT16_4(x) ((x).sCDEF0123456789AB) |
| 146 | #define ROT16_5(x) ((x).sBCDEF0123456789A) |
| 147 | #define ROT16_6(x) ((x).sABCDEF0123456789) |
| 148 | #define ROT16_7(x) ((x).s9ABCDEF012345678) |
| 149 | #define ROT16_8(x) ((x).s89ABCDEF01234567) |
| 150 | #define ROT16_9(x) ((x).s789ABCDEF0123456) |
| 151 | #define ROT16_10(x) ((x).s6789ABCDEF012345) |
| 152 | #define ROT16_11(x) ((x).s56789ABCDEF01234) |
| 153 | #define ROT16_12(x) ((x).s456789ABCDEF0123) |
| 154 | #define ROT16_13(x) ((x).s3456789ABCDEF012) |
| 155 | #define ROT16_14(x) ((x).s23456789ABCDEF01) |
| 156 | #define ROT16_15(x) ((x).s123456789ABCDEF0) |
Giorgio Arena | 9324022 | 2020-12-23 11:55:29 +0000 | [diff] [blame] | 157 | #define ROT16_16(x) ((x)) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 158 | /** @} */ // end of group ROTs_n |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 159 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 160 | /** Circular-right-shift (rotate-right) the given vector by the given amount. |
| 161 | * @name ROTATE |
| 162 | * |
| 163 | * @param[in] x The vector to be shifted |
| 164 | * @param[in] s The size of the vector |
| 165 | * @param[in] n The amount to be shifted |
| 166 | * |
| 167 | * @return The shifted vector |
| 168 | * @{ |
| 169 | */ |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 170 | #define ROTATE_STR(x, s, n) ROT##s##_##n(x) |
| 171 | #define ROTATE(x, s, n) ROTATE_STR(x, s, n) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 172 | /** @} */ // end of group ROTATE |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 173 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 174 | /** Creates a vector of size n filled with offset values corresponding to the location of each element. |
| 175 | * @name V_OFFSn |
| 176 | * |
| 177 | * @param[in] dt The data type of the output vector |
| 178 | * |
| 179 | * @return The vector filled with offset values |
| 180 | * @{ |
| 181 | */ |
Giorgio Arena | 2d1a835 | 2020-10-26 15:04:08 +0000 | [diff] [blame] | 182 | #define V_OFFS1(dt) (dt##1)(0) |
| 183 | #define V_OFFS2(dt) (dt##2)(0, 1) |
| 184 | #define V_OFFS3(dt) (dt##3)(0, 1, 2) |
| 185 | #define V_OFFS4(dt) (dt##4)(0, 1, 2, 3) |
| 186 | #define V_OFFS8(dt) (dt##8)(0, 1, 2, 3, 4, 5, 6, 7) |
| 187 | #define V_OFFS16(dt) (dt##16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 188 | /** @} */ // end of group V_OFFSn |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 189 | |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 190 | /** Create a vector filled with offset values corresponding to the location of each element. |
| 191 | * @name VEC_OFFS |
| 192 | * |
| 193 | * @param[in] dt The data type of the output vector |
| 194 | * @param[in] s The size of the output vector |
| 195 | * |
| 196 | * @return The vector filled with offset values |
| 197 | * @{ |
| 198 | */ |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 199 | #define VEC_OFFS_STR(dt, s) V_OFFS##s(dt) |
| 200 | #define VEC_OFFS(dt, s) VEC_OFFS_STR(dt, s) |
Sang-Hoon Park | bfd75d6 | 2019-10-30 14:56:17 +0000 | [diff] [blame] | 201 | /** @} */ // end of group VEC_OFFS |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 202 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 203 | #define VLOAD_STR(size) vload##size |
| 204 | #define VLOAD(size) VLOAD_STR(size) |
| 205 | |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 206 | /** Extended partial vload that correctly handles scalar values as well. |
| 207 | * Load the **lower** 0 to (n-1)th elements of the given vector while minimising the amount of load ops |
| 208 | * @name VLOAD_PARTIAL |
| 209 | * |
| 210 | * @note With this macro, the passed data can be both a vector and a scalar |
| 211 | * @note @p load_size needs to be <= @p size |
| 212 | * eg 1: Valid |
| 213 | * VLOAD_PARTIAL(16, 15) ...; |
| 214 | * eg 2: Invalid |
| 215 | * VLOAD_PARTIAL(4, 7) ...; |
| 216 | * |
| 217 | * @param[in] size The width of @p DATA. Supported values: 1(scalar), 2, 3, 4, 8, 16 |
| 218 | * @param[in] load_size The number of lower elements to load. Supported values: 1-16, but has to be <= @p size |
| 219 | * @{ |
| 220 | */ |
| 221 | #define VLOAD_PARTIAL_STR(size, load_size) vload_partial_##size##_##load_size |
| 222 | #define VLOAD_PARTIAL(size, load_size) VLOAD_PARTIAL_STR(size, load_size) |
| 223 | |
| 224 | #define NO_LOAD(data, offs, ptr) \ |
| 225 | { \ |
| 226 | } |
| 227 | |
| 228 | // Size == 1 (scalar) |
| 229 | #define vload_partial_1_0 NO_LOAD |
| 230 | #define vload_partial_1_1 vload1 |
| 231 | #define vload_partial_1_2 NO_LOAD |
| 232 | #define vload_partial_1_3 NO_LOAD |
| 233 | #define vload_partial_1_4 NO_LOAD |
| 234 | #define vload_partial_1_5 NO_LOAD |
| 235 | #define vload_partial_1_6 NO_LOAD |
| 236 | #define vload_partial_1_7 NO_LOAD |
| 237 | #define vload_partial_1_8 NO_LOAD |
| 238 | #define vload_partial_1_9 NO_LOAD |
| 239 | #define vload_partial_1_10 NO_LOAD |
| 240 | #define vload_partial_1_11 NO_LOAD |
| 241 | #define vload_partial_1_12 NO_LOAD |
| 242 | #define vload_partial_1_13 NO_LOAD |
| 243 | #define vload_partial_1_14 NO_LOAD |
| 244 | #define vload_partial_1_15 NO_LOAD |
| 245 | #define vload_partial_1_16 NO_LOAD |
| 246 | // Size == 2 |
| 247 | #define vload_partial_2_0 NO_LOAD |
| 248 | #define vload_partial_2_1 vload_partial_1 |
| 249 | #define vload_partial_2_2 vload_partial_2 |
| 250 | #define vload_partial_2_3 NO_LOAD |
| 251 | #define vload_partial_2_4 NO_LOAD |
| 252 | #define vload_partial_2_5 NO_LOAD |
| 253 | #define vload_partial_2_6 NO_LOAD |
| 254 | #define vload_partial_2_7 NO_LOAD |
| 255 | #define vload_partial_2_8 NO_LOAD |
| 256 | #define vload_partial_2_9 NO_LOAD |
| 257 | #define vload_partial_2_10 NO_LOAD |
| 258 | #define vload_partial_2_11 NO_LOAD |
| 259 | #define vload_partial_2_12 NO_LOAD |
| 260 | #define vload_partial_2_13 NO_LOAD |
| 261 | #define vload_partial_2_14 NO_LOAD |
| 262 | #define vload_partial_2_15 NO_LOAD |
| 263 | #define vload_partial_2_16 NO_LOAD |
| 264 | // Size == 3 |
| 265 | #define vload_partial_3_0 NO_LOAD |
| 266 | #define vload_partial_3_1 vload_partial_1 |
| 267 | #define vload_partial_3_2 vload_partial_2 |
| 268 | #define vload_partial_3_3 vload_partial_3 |
| 269 | #define vload_partial_3_4 NO_LOAD |
| 270 | #define vload_partial_3_5 NO_LOAD |
| 271 | #define vload_partial_3_6 NO_LOAD |
| 272 | #define vload_partial_3_7 NO_LOAD |
| 273 | #define vload_partial_3_8 NO_LOAD |
| 274 | #define vload_partial_3_9 NO_LOAD |
| 275 | #define vload_partial_3_10 NO_LOAD |
| 276 | #define vload_partial_3_11 NO_LOAD |
| 277 | #define vload_partial_3_12 NO_LOAD |
| 278 | #define vload_partial_3_13 NO_LOAD |
| 279 | #define vload_partial_3_14 NO_LOAD |
| 280 | #define vload_partial_3_15 NO_LOAD |
| 281 | #define vload_partial_3_16 NO_LOAD |
| 282 | // Size == 4 |
| 283 | #define vload_partial_4_0 NO_LOAD |
| 284 | #define vload_partial_4_1 vload_partial_1 |
| 285 | #define vload_partial_4_2 vload_partial_2 |
| 286 | #define vload_partial_4_3 vload_partial_3 |
| 287 | #define vload_partial_4_4 vload_partial_4 |
| 288 | #define vload_partial_4_5 NO_LOAD |
| 289 | #define vload_partial_4_6 NO_LOAD |
| 290 | #define vload_partial_4_7 NO_LOAD |
| 291 | #define vload_partial_4_8 NO_LOAD |
| 292 | #define vload_partial_4_9 NO_LOAD |
| 293 | #define vload_partial_4_10 NO_LOAD |
| 294 | #define vload_partial_4_11 NO_LOAD |
| 295 | #define vload_partial_4_12 NO_LOAD |
| 296 | #define vload_partial_4_13 NO_LOAD |
| 297 | #define vload_partial_4_14 NO_LOAD |
| 298 | #define vload_partial_4_15 NO_LOAD |
| 299 | #define vload_partial_4_16 NO_LOAD |
| 300 | // Size == 8 |
| 301 | #define vload_partial_8_0 NO_LOAD |
| 302 | #define vload_partial_8_1 vload_partial_1 |
| 303 | #define vload_partial_8_2 vload_partial_2 |
| 304 | #define vload_partial_8_3 vload_partial_3 |
| 305 | #define vload_partial_8_4 vload_partial_4 |
| 306 | #define vload_partial_8_5 vload_partial_5 |
| 307 | #define vload_partial_8_6 vload_partial_6 |
| 308 | #define vload_partial_8_7 vload_partial_7 |
| 309 | #define vload_partial_8_8 vload_partial_8 |
| 310 | #define vload_partial_8_9 NO_LOAD |
| 311 | #define vload_partial_8_10 NO_LOAD |
| 312 | #define vload_partial_8_11 NO_LOAD |
| 313 | #define vload_partial_8_12 NO_LOAD |
| 314 | #define vload_partial_8_13 NO_LOAD |
| 315 | #define vload_partial_8_14 NO_LOAD |
| 316 | #define vload_partial_8_15 NO_LOAD |
| 317 | #define vload_partial_8_16 NO_LOAD |
| 318 | // Size == 16 |
| 319 | #define vload_partial_16_0 NO_LOAD |
| 320 | #define vload_partial_16_1 vload_partial_1 |
| 321 | #define vload_partial_16_2 vload_partial_2 |
| 322 | #define vload_partial_16_3 vload_partial_3 |
| 323 | #define vload_partial_16_4 vload_partial_4 |
| 324 | #define vload_partial_16_5 vload_partial_5 |
| 325 | #define vload_partial_16_6 vload_partial_6 |
| 326 | #define vload_partial_16_7 vload_partial_7 |
| 327 | #define vload_partial_16_8 vload_partial_8 |
| 328 | #define vload_partial_16_9 vload_partial_9 |
| 329 | #define vload_partial_16_10 vload_partial_10 |
| 330 | #define vload_partial_16_11 vload_partial_11 |
| 331 | #define vload_partial_16_12 vload_partial_12 |
| 332 | #define vload_partial_16_13 vload_partial_13 |
| 333 | #define vload_partial_16_14 vload_partial_14 |
| 334 | #define vload_partial_16_15 vload_partial_15 |
| 335 | #define vload_partial_16_16 vload_partial_16 |
| 336 | |
| 337 | /** Partial vload. Load the **lower** 0 to (n-1)th elements of the given vector while minimising the amount of vload ops |
| 338 | * @name vload_partial_n |
| 339 | * |
| 340 | * @note @p DATA needs to be a vector not a scalar |
| 341 | * @note n needs to be <= the vector width of the input variable @p DATA |
| 342 | * eg 1: Valid |
| 343 | * vload_partial_15(var:float16, 0, 0xabcd); |
| 344 | * eg 2: Invalid |
| 345 | * vload_partial_7(var:float4, 0, 0xabcd); |
| 346 | * |
| 347 | * @note in cases n == 1, 2, 3, 4, 8, 16, no extra vload is invoked, thus there's no performance penalty. |
| 348 | * |
| 349 | * @param[in] DATA The name of the variable where to load the values |
| 350 | * @param[in] OFFSET Offset in n |
| 351 | * @param[in] PTR The base pointer |
| 352 | * @{ |
| 353 | */ |
| 354 | #define vload_partial_1(DATA, OFFSET, PTR) \ |
| 355 | DATA.s0 = vload1(OFFSET, PTR); |
| 356 | |
| 357 | #define vload_partial_2(DATA, OFFSET, PTR) \ |
| 358 | DATA.s01 = vload2(OFFSET, PTR); |
| 359 | |
| 360 | #define vload_partial_3(DATA, OFFSET, PTR) \ |
| 361 | DATA.s012 = vload3(OFFSET, PTR); |
| 362 | |
| 363 | #define vload_partial_4(DATA, OFFSET, PTR) \ |
| 364 | DATA.s0123 = vload4(OFFSET, PTR); |
| 365 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 366 | #define vload_partial_5(DATA, OFFSET, PTR) \ |
| 367 | vload_partial_4(DATA.s0123, OFFSET, PTR); \ |
| 368 | DATA.s4 = vload1(OFFSET, PTR + 4); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 369 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 370 | #define vload_partial_6(DATA, OFFSET, PTR) \ |
| 371 | vload_partial_4(DATA.s0123, OFFSET, PTR); \ |
| 372 | vload_partial_2(DATA.s45, OFFSET, PTR + 4); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 373 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 374 | #define vload_partial_7(DATA, OFFSET, PTR) \ |
| 375 | vload_partial_4(DATA.s0123, OFFSET, PTR); \ |
| 376 | vload_partial_3(DATA.s456, OFFSET, PTR + 4); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 377 | |
| 378 | #define vload_partial_8(DATA, OFFSET, PTR) \ |
| 379 | DATA.s01234567 = vload8(OFFSET, PTR); |
| 380 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 381 | #define vload_partial_9(DATA, OFFSET, PTR) \ |
| 382 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 383 | DATA.s8 = vload1(OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 384 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 385 | #define vload_partial_10(DATA, OFFSET, PTR) \ |
| 386 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 387 | vload_partial_2(DATA.s89, OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 388 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 389 | #define vload_partial_11(DATA, OFFSET, PTR) \ |
| 390 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 391 | vload_partial_3(DATA.s89A, OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 392 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 393 | #define vload_partial_12(DATA, OFFSET, PTR) \ |
| 394 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 395 | vload_partial_4(DATA.s89AB, OFFSET, PTR + 8); |
Adnan AlSinan | 3e155a5 | 2021-12-10 12:34:02 +0000 | [diff] [blame] | 396 | // For vload_partial_{13,14,15}, an 8-vector size has been passed, because vectors size of size 5,6,7 are not supported |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 397 | #define vload_partial_13(DATA, OFFSET, PTR) \ |
| 398 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Adnan AlSinan | 3e155a5 | 2021-12-10 12:34:02 +0000 | [diff] [blame] | 399 | vload_partial_5(DATA.s89ABCDEF, OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 400 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 401 | #define vload_partial_14(DATA, OFFSET, PTR) \ |
| 402 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Adnan AlSinan | 3e155a5 | 2021-12-10 12:34:02 +0000 | [diff] [blame] | 403 | vload_partial_6(DATA.s89ABCDEF, OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 404 | |
Giorgio Arena | 88bd35d | 2021-09-08 12:26:27 +0100 | [diff] [blame] | 405 | #define vload_partial_15(DATA, OFFSET, PTR) \ |
| 406 | vload_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Adnan AlSinan | 3e155a5 | 2021-12-10 12:34:02 +0000 | [diff] [blame] | 407 | vload_partial_7(DATA.s89ABCDEF, OFFSET, PTR + 8); |
Giorgio Arena | bde2f35 | 2021-09-07 14:15:28 +0100 | [diff] [blame] | 408 | |
| 409 | #define vload_partial_16(DATA, OFFSET, PTR) \ |
| 410 | DATA = vload16(OFFSET, PTR); |
| 411 | /** @} */ // end of groupd vload_partial_n |
| 412 | /** @} */ // end of groupd VLOAD_PARTIAL |
| 413 | |
Gian Marco Iodice | e3a849a | 2020-06-10 17:59:30 +0100 | [diff] [blame] | 414 | #define PIXEL_UNIT4 1 |
| 415 | #define PIXEL_UNIT8 2 |
| 416 | #define PIXEL_UNIT16 4 |
| 417 | |
| 418 | /** Utility macro to convert a vector size in pixel unit. |
| 419 | * |
| 420 | * @name CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT |
| 421 | * |
| 422 | * @param[in] vec_size Vector size. Only 4,8 and 16 is supported |
| 423 | * |
| 424 | * @return The pixel unit (number of pixels) |
| 425 | * @{ |
| 426 | */ |
| 427 | #define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) PIXEL_UNIT##vec_size |
| 428 | #define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(vec_size) CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) |
| 429 | /** @} */ // end of group CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT |
| 430 | |
| 431 | #define read_image2d_floatx1(img, x_coord, y_coord) (float4)(read_imagef(img, (int2)(x_coord, y_coord))); |
| 432 | #define read_image2d_floatx2(img, x_coord, y_coord) (float8)(read_imagef(img, (int2)(x_coord, y_coord)), read_imagef(img, (int2)(x_coord + 1, y_coord))); |
| 433 | #define read_image2d_floatx4(img, x_coord, y_coord) (float16)(read_imagef(img, (int2)(x_coord, y_coord)), read_imagef(img, (int2)(x_coord + 1, y_coord)), read_imagef(img, (int2)(x_coord + 2, y_coord)), read_imagef(img, (int2)(x_coord + 3, y_coord))); |
| 434 | |
| 435 | #if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
| 436 | #define read_image2d_halfx1(img, x_coord, y_coord) (half4)(read_imageh(img, (int2)(x_coord, y_coord))); |
| 437 | #define read_image2d_halfx2(img, x_coord, y_coord) (half8)(read_imageh(img, (int2)(x_coord, y_coord)), read_imageh(img, (int2)(x_coord + 1, y_coord))); |
| 438 | #define read_image2d_halfx4(img, x_coord, y_coord) (half16)(read_imageh(img, (int2)(x_coord, y_coord)), read_imageh(img, (int2)(x_coord + 1, y_coord)), read_imageh(img, (int2)(x_coord + 2, y_coord)), read_imageh(img, (int2)(x_coord + 3, y_coord))); |
| 439 | #endif // defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
| 440 | |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 441 | #define write_image2d_floatx1(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values)); |
| 442 | #define write_image2d_floatx2(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values.s0123), write_imagef(img, (int2)(x_coord + 1, y_coord), values.s4567)); |
| 443 | #define write_image2d_floatx4(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values.s0123), write_imagef(img, (int2)(x_coord + 1, y_coord), values.s4567), write_imagef(img, (int2)(x_coord + 2, y_coord), values.s89AB), write_imagef(img, (int2)(x_coord + 3, y_coord), values.sCDEF)); |
| 444 | |
| 445 | #if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
| 446 | #define write_image2d_halfx1(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values)); |
| 447 | #define write_image2d_halfx2(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values.s0123), write_imageh(img, (int2)(x_coord + 1, y_coord), values.s4567)); |
| 448 | #define write_image2d_halfx4(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values.s0123), write_imageh(img, (int2)(x_coord + 1, y_coord), values.s4567), write_imageh(img, (int2)(x_coord + 2, y_coord), values.s89AB), write_imageh(img, (int2)(x_coord + 3, y_coord), values.sCDEF)); |
| 449 | #endif // defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) |
| 450 | |
Gian Marco Iodice | e3a849a | 2020-06-10 17:59:30 +0100 | [diff] [blame] | 451 | /** Utility macro to read a 2D OpenCL image object. |
| 452 | * |
| 453 | * @note Coordinates are not normalized |
| 454 | * |
| 455 | * @param[in] data_type Data type |
| 456 | * @param[in] n0 Number of pixel to read. Only 1,2 and 4 is supported |
| 457 | * @param[in] img OpenCL image object |
| 458 | * @param[in] x_coord The x coordinate for the top-left pixel |
| 459 | * @param[in] y_coord The y coordinate for the top-left pixel |
| 460 | * |
| 461 | * @return Pixels from the 2D OpenCL image object |
| 462 | * @{ |
| 463 | */ |
| 464 | #define READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) read_image2d_##data_type##x##n0(img, x_coord, y_coord) |
| 465 | #define READ_IMAGE2D(data_type, n0, img, x_coord, y_coord) READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) |
ramy.elgammal@arm.com | a2561f0 | 2023-06-16 20:45:48 +0100 | [diff] [blame^] | 466 | /** @} */ |
Gian Marco Iodice | e3a849a | 2020-06-10 17:59:30 +0100 | [diff] [blame] | 467 | |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 468 | /** Utility macro to write a 2D OpenCL image object. |
| 469 | * |
| 470 | * @note Coordinates are not normalized |
| 471 | * |
| 472 | * @param[in] data_type Data type |
| 473 | * @param[in] n0 Number of pixel to write. Only 1,2 and 4 is supported |
| 474 | * @param[in] img OpenCL image object |
| 475 | * @param[in] x_coord The x coordinate for the top-left pixel |
| 476 | * @param[in] y_coord The y coordinate for the top-left pixel |
| 477 | * @param[in] values Values to write |
| 478 | * |
| 479 | * @{ |
| 480 | */ |
| 481 | #define WRITE_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord, values) write_image2d_##data_type##x##n0(img, x_coord, y_coord, values) |
| 482 | #define WRITE_IMAGE2D(data_type, n0, img, x_coord, y_coord, values) WRITE_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord, values) |
ramy.elgammal@arm.com | a2561f0 | 2023-06-16 20:45:48 +0100 | [diff] [blame^] | 483 | /** @} */ |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 484 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 485 | #define VSTORE_STR(size) vstore##size |
| 486 | #define VSTORE(size) VSTORE_STR(size) |
| 487 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 488 | #define float1 float |
| 489 | #define half1 half |
Usama Arif | 0681e3b | 2019-04-25 14:28:07 +0100 | [diff] [blame] | 490 | #define char1 char |
| 491 | #define uchar1 uchar |
| 492 | #define short1 short |
| 493 | #define ushort1 ushort |
| 494 | #define int1 int |
| 495 | #define uint1 uint |
| 496 | #define long1 long |
| 497 | #define ulong1 ulong |
| 498 | #define double1 double |
| 499 | |
| 500 | #define vload1(OFFSET, PTR) *(OFFSET + PTR) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 501 | #define vstore1(DATA, OFFSET, PTR) *(OFFSET + PTR) = DATA |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 502 | |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 503 | /** Extended partial vstore that correctly handles scalar values as well. |
| 504 | * Store the **lower** 0 to (n-1)th elements of the given vector while minimising the amount of vstore ops |
| 505 | * @name VSTORE_PARTIAL |
| 506 | * |
| 507 | * @note With this macro, the passed data can be both a vector and a scalar |
| 508 | * @note @p store_size needs to be <= @p size |
| 509 | * eg 1: Valid |
| 510 | * VSTORE_PARTIAL(16, 15) ...; |
| 511 | * eg 2: Invalid |
| 512 | * VSTORE_PARTIAL(4, 7) ...; |
| 513 | * |
| 514 | * @param[in] size The width of @p DATA. Supported values: 1(scalar), 2, 3, 4, 8, 16 |
| 515 | * @param[in] store_size The number of lower elements to store. Supported values: 1-16, but has to be <= @p size |
| 516 | * @{ |
| 517 | */ |
| 518 | #define VSTORE_PARTIAL_STR(size, store_size) vstore_partial_##size##_##store_size |
| 519 | #define VSTORE_PARTIAL(size, store_size) VSTORE_PARTIAL_STR(size, store_size) |
| 520 | |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 521 | #define NO_STORE(data, offs, ptr) \ |
| 522 | { \ |
| 523 | } |
| 524 | |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 525 | // Size == 1 (scalar) |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 526 | #define vstore_partial_1_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 527 | #define vstore_partial_1_1 vstore1 |
SiCong Li | 0ea50e3 | 2020-11-05 09:18:11 +0000 | [diff] [blame] | 528 | #define vstore_partial_1_2 NO_STORE |
| 529 | #define vstore_partial_1_3 NO_STORE |
| 530 | #define vstore_partial_1_4 NO_STORE |
| 531 | #define vstore_partial_1_5 NO_STORE |
| 532 | #define vstore_partial_1_6 NO_STORE |
| 533 | #define vstore_partial_1_7 NO_STORE |
| 534 | #define vstore_partial_1_8 NO_STORE |
| 535 | #define vstore_partial_1_9 NO_STORE |
| 536 | #define vstore_partial_1_10 NO_STORE |
| 537 | #define vstore_partial_1_11 NO_STORE |
| 538 | #define vstore_partial_1_12 NO_STORE |
| 539 | #define vstore_partial_1_13 NO_STORE |
| 540 | #define vstore_partial_1_14 NO_STORE |
| 541 | #define vstore_partial_1_15 NO_STORE |
| 542 | #define vstore_partial_1_16 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 543 | // Size == 2 |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 544 | #define vstore_partial_2_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 545 | #define vstore_partial_2_1 vstore_partial_1 |
| 546 | #define vstore_partial_2_2 vstore_partial_2 |
SiCong Li | 0ea50e3 | 2020-11-05 09:18:11 +0000 | [diff] [blame] | 547 | #define vstore_partial_2_3 NO_STORE |
| 548 | #define vstore_partial_2_4 NO_STORE |
| 549 | #define vstore_partial_2_5 NO_STORE |
| 550 | #define vstore_partial_2_6 NO_STORE |
| 551 | #define vstore_partial_2_7 NO_STORE |
| 552 | #define vstore_partial_2_8 NO_STORE |
| 553 | #define vstore_partial_2_9 NO_STORE |
| 554 | #define vstore_partial_2_10 NO_STORE |
| 555 | #define vstore_partial_2_11 NO_STORE |
| 556 | #define vstore_partial_2_12 NO_STORE |
| 557 | #define vstore_partial_2_13 NO_STORE |
| 558 | #define vstore_partial_2_14 NO_STORE |
| 559 | #define vstore_partial_2_15 NO_STORE |
| 560 | #define vstore_partial_2_16 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 561 | // Size == 3 |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 562 | #define vstore_partial_3_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 563 | #define vstore_partial_3_1 vstore_partial_1 |
| 564 | #define vstore_partial_3_2 vstore_partial_2 |
| 565 | #define vstore_partial_3_3 vstore_partial_3 |
SiCong Li | 0ea50e3 | 2020-11-05 09:18:11 +0000 | [diff] [blame] | 566 | #define vstore_partial_3_4 NO_STORE |
| 567 | #define vstore_partial_3_5 NO_STORE |
| 568 | #define vstore_partial_3_6 NO_STORE |
| 569 | #define vstore_partial_3_7 NO_STORE |
| 570 | #define vstore_partial_3_8 NO_STORE |
| 571 | #define vstore_partial_3_9 NO_STORE |
| 572 | #define vstore_partial_3_10 NO_STORE |
| 573 | #define vstore_partial_3_11 NO_STORE |
| 574 | #define vstore_partial_3_12 NO_STORE |
| 575 | #define vstore_partial_3_13 NO_STORE |
| 576 | #define vstore_partial_3_14 NO_STORE |
| 577 | #define vstore_partial_3_15 NO_STORE |
| 578 | #define vstore_partial_3_16 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 579 | // Size == 4 |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 580 | #define vstore_partial_4_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 581 | #define vstore_partial_4_1 vstore_partial_1 |
| 582 | #define vstore_partial_4_2 vstore_partial_2 |
| 583 | #define vstore_partial_4_3 vstore_partial_3 |
| 584 | #define vstore_partial_4_4 vstore_partial_4 |
SiCong Li | 0ea50e3 | 2020-11-05 09:18:11 +0000 | [diff] [blame] | 585 | #define vstore_partial_4_5 NO_STORE |
| 586 | #define vstore_partial_4_6 NO_STORE |
| 587 | #define vstore_partial_4_7 NO_STORE |
| 588 | #define vstore_partial_4_8 NO_STORE |
| 589 | #define vstore_partial_4_9 NO_STORE |
| 590 | #define vstore_partial_4_10 NO_STORE |
| 591 | #define vstore_partial_4_11 NO_STORE |
| 592 | #define vstore_partial_4_12 NO_STORE |
| 593 | #define vstore_partial_4_13 NO_STORE |
| 594 | #define vstore_partial_4_14 NO_STORE |
| 595 | #define vstore_partial_4_15 NO_STORE |
| 596 | #define vstore_partial_4_16 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 597 | // Size == 8 |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 598 | #define vstore_partial_8_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 599 | #define vstore_partial_8_1 vstore_partial_1 |
| 600 | #define vstore_partial_8_2 vstore_partial_2 |
| 601 | #define vstore_partial_8_3 vstore_partial_3 |
| 602 | #define vstore_partial_8_4 vstore_partial_4 |
| 603 | #define vstore_partial_8_5 vstore_partial_5 |
| 604 | #define vstore_partial_8_6 vstore_partial_6 |
| 605 | #define vstore_partial_8_7 vstore_partial_7 |
| 606 | #define vstore_partial_8_8 vstore_partial_8 |
SiCong Li | 0ea50e3 | 2020-11-05 09:18:11 +0000 | [diff] [blame] | 607 | #define vstore_partial_8_9 NO_STORE |
| 608 | #define vstore_partial_8_10 NO_STORE |
| 609 | #define vstore_partial_8_11 NO_STORE |
| 610 | #define vstore_partial_8_12 NO_STORE |
| 611 | #define vstore_partial_8_13 NO_STORE |
| 612 | #define vstore_partial_8_14 NO_STORE |
| 613 | #define vstore_partial_8_15 NO_STORE |
| 614 | #define vstore_partial_8_16 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 615 | // Size == 16 |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 616 | #define vstore_partial_16_0 NO_STORE |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 617 | #define vstore_partial_16_1 vstore_partial_1 |
| 618 | #define vstore_partial_16_2 vstore_partial_2 |
| 619 | #define vstore_partial_16_3 vstore_partial_3 |
| 620 | #define vstore_partial_16_4 vstore_partial_4 |
| 621 | #define vstore_partial_16_5 vstore_partial_5 |
| 622 | #define vstore_partial_16_6 vstore_partial_6 |
| 623 | #define vstore_partial_16_7 vstore_partial_7 |
| 624 | #define vstore_partial_16_8 vstore_partial_8 |
| 625 | #define vstore_partial_16_9 vstore_partial_9 |
| 626 | #define vstore_partial_16_10 vstore_partial_10 |
| 627 | #define vstore_partial_16_11 vstore_partial_11 |
| 628 | #define vstore_partial_16_12 vstore_partial_12 |
| 629 | #define vstore_partial_16_13 vstore_partial_13 |
| 630 | #define vstore_partial_16_14 vstore_partial_14 |
| 631 | #define vstore_partial_16_15 vstore_partial_15 |
| 632 | #define vstore_partial_16_16 vstore_partial_16 |
| 633 | |
| 634 | /** Partial vstore. Store the **lower** 0 to (n-1)th elements of the given vector while minimising the amount of vstore ops |
| 635 | * @name vstore_partial_n |
| 636 | * |
| 637 | * @note @p DATA needs to be a vector not a scalar |
| 638 | * @note n needs to be <= the vector width of the input variable @p DATA |
| 639 | * eg 1: Valid |
| 640 | * vstore_partial_15(var:float16, 0, 0xabcd); |
| 641 | * eg 2: Invalid |
| 642 | * vstore_partial_7(var:float4, 0, 0xabcd); |
| 643 | * |
| 644 | * @note in cases n == 1, 2, 3, 4, 8, 16, no extra vstore is invoked, thus there's no performance penalty. |
| 645 | * |
| 646 | * @param[in] DATA The name of the variable |
| 647 | * @param[in] OFFSET Offset in n |
| 648 | * @param[in] PTR The base pointer |
| 649 | * @{ |
| 650 | */ |
| 651 | #define vstore_partial_1(DATA, OFFSET, PTR) \ |
| 652 | vstore1(DATA.s0, OFFSET, PTR); |
| 653 | |
| 654 | #define vstore_partial_2(DATA, OFFSET, PTR) \ |
| 655 | vstore2(DATA.s01, OFFSET, PTR); |
| 656 | |
| 657 | #define vstore_partial_3(DATA, OFFSET, PTR) \ |
| 658 | vstore3(DATA.s012, OFFSET, PTR); |
| 659 | |
| 660 | #define vstore_partial_4(DATA, OFFSET, PTR) \ |
| 661 | vstore4(DATA.s0123, OFFSET, PTR); |
| 662 | |
| 663 | #define vstore_partial_5(DATA, OFFSET, PTR) \ |
| 664 | vstore_partial_4(DATA.s0123, OFFSET, PTR); \ |
SiCong Li | 3b64e3e | 2020-07-28 09:01:28 +0100 | [diff] [blame] | 665 | vstore1(DATA.s4, OFFSET, PTR + 4); |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 666 | |
| 667 | #define vstore_partial_6(DATA, OFFSET, PTR) \ |
| 668 | vstore_partial_4(DATA.s0123, OFFSET, PTR); \ |
| 669 | vstore_partial_2(DATA.s45, OFFSET, PTR + 4); |
| 670 | |
| 671 | #define vstore_partial_7(DATA, OFFSET, PTR) \ |
| 672 | vstore_partial_4(DATA.s0123, OFFSET, PTR); \ |
| 673 | vstore_partial_3(DATA.s456, OFFSET, PTR + 4); |
| 674 | |
| 675 | #define vstore_partial_8(DATA, OFFSET, PTR) \ |
| 676 | vstore8(DATA.s01234567, OFFSET, PTR); |
| 677 | |
| 678 | #define vstore_partial_9(DATA, OFFSET, PTR) \ |
| 679 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
SiCong Li | 3b64e3e | 2020-07-28 09:01:28 +0100 | [diff] [blame] | 680 | vstore1(DATA.s8, OFFSET, PTR + 8); |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 681 | |
| 682 | #define vstore_partial_10(DATA, OFFSET, PTR) \ |
| 683 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 684 | vstore_partial_2(DATA.s89, OFFSET, PTR + 8); |
| 685 | |
| 686 | #define vstore_partial_11(DATA, OFFSET, PTR) \ |
| 687 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 688 | vstore_partial_3(DATA.s89a, OFFSET, PTR + 8); |
| 689 | |
| 690 | #define vstore_partial_12(DATA, OFFSET, PTR) \ |
| 691 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
| 692 | vstore_partial_4(DATA.s89ab, OFFSET, PTR + 8); |
| 693 | |
| 694 | #define vstore_partial_13(DATA, OFFSET, PTR) \ |
| 695 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 696 | vstore_partial_5(DATA.s89abcdef, OFFSET, PTR + 8); |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 697 | |
| 698 | #define vstore_partial_14(DATA, OFFSET, PTR) \ |
| 699 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 700 | vstore_partial_6(DATA.s89abcdef, OFFSET, PTR + 8); |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 701 | |
| 702 | #define vstore_partial_15(DATA, OFFSET, PTR) \ |
| 703 | vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 704 | vstore_partial_7(DATA.s89abcdef, OFFSET, PTR + 8); |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 705 | |
| 706 | #define vstore_partial_16(DATA, OFFSET, PTR) \ |
| 707 | vstore16(DATA, OFFSET, PTR); |
| 708 | /** @} */ // end of groupd vstore_partial_n |
| 709 | /** @} */ // end of groupd VSTORE_PARTIAL |
| 710 | |
Gian Marco Iodice | 0c17aa2 | 2019-09-27 09:23:15 +0100 | [diff] [blame] | 711 | // Convert built-in functions with _sat modifier are not supported in floating point so we create defines |
| 712 | // without _sat to overcome this issue |
| 713 | #define convert_float_sat convert_float |
| 714 | #define convert_float1_sat convert_float |
| 715 | #define convert_float2_sat convert_float2 |
| 716 | #define convert_float3_sat convert_float3 |
| 717 | #define convert_float4_sat convert_float4 |
| 718 | #define convert_float8_sat convert_float8 |
| 719 | #define convert_float16_sat convert_float16 |
| 720 | #define convert_half_sat convert_float |
| 721 | #define convert_half1_sat convert_half |
| 722 | #define convert_half2_sat convert_half2 |
| 723 | #define convert_half3_sat convert_half3 |
| 724 | #define convert_half4_sat convert_half4 |
| 725 | #define convert_half8_sat convert_half8 |
| 726 | #define convert_half16_sat convert_half16 |
| 727 | |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 728 | #define convert_float1 convert_float |
| 729 | #define convert_half1 convert_half |
| 730 | #define convert_char1 convert_char |
| 731 | #define convert_uchar1 convert_uchar |
| 732 | #define convert_short1 convert_short |
| 733 | #define convert_ushort1 convert_ushort |
| 734 | #define convert_int1 convert_int |
| 735 | #define convert_uint1 convert_uint |
| 736 | #define convert_long1 convert_long |
| 737 | #define convert_ulong1 convert_ulong |
| 738 | #define convert_double1 convert_double |
| 739 | |
| 740 | #define convert_char1_sat convert_char_sat |
| 741 | #define convert_uchar1_sat convert_uchar_sat |
Sheri Zhang | 4f1650f | 2021-04-15 12:58:20 +0100 | [diff] [blame] | 742 | #define convert_uchar2_sat convert_uchar2_sat |
| 743 | #define convert_uchar3_sat convert_uchar3_sat |
| 744 | #define convert_uchar4_sat convert_uchar4_sat |
| 745 | #define convert_uchar8_sat convert_uchar8_sat |
| 746 | #define convert_uchar16_sat convert_uchar16_sat |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 747 | #define convert_short1_sat convert_short_sat |
| 748 | #define convert_ushort1_sat convert_ushort_sat |
| 749 | #define convert_int1_sat convert_int_sat |
| 750 | #define convert_uint1_sat convert_uint_sat |
| 751 | #define convert_long1_sat convert_long_sat |
| 752 | #define convert_ulong1_sat convert_ulong_sat |
| 753 | #define convert_double1_sat convert_double_sat |
| 754 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 755 | #define VEC_DATA_TYPE_STR(type, size) type##size |
| 756 | #define VEC_DATA_TYPE(type, size) VEC_DATA_TYPE_STR(type, size) |
| 757 | |
| 758 | #define CONVERT_STR(x, type) (convert_##type((x))) |
| 759 | #define CONVERT(x, type) CONVERT_STR(x, type) |
| 760 | |
| 761 | #define CONVERT_SAT_STR(x, type) (convert_##type##_sat((x))) |
| 762 | #define CONVERT_SAT(x, type) CONVERT_SAT_STR(x, type) |
| 763 | |
| 764 | #define CONVERT_SAT_ROUND_STR(x, type, round) (convert_##type##_sat_##round((x))) |
| 765 | #define CONVERT_SAT_ROUND(x, type, round) CONVERT_SAT_ROUND_STR(x, type, round) |
| 766 | |
Giorgio Arena | 2d1a835 | 2020-10-26 15:04:08 +0000 | [diff] [blame] | 767 | #define select_vec_dt_uchar(size) uchar##size |
| 768 | #define select_vec_dt_char(size) char##size |
| 769 | #define select_vec_dt_ushort(size) ushort##size |
| 770 | #define select_vec_dt_short(size) short##size |
| 771 | #define select_vec_dt_half(size) short##size |
| 772 | #define select_vec_dt_uint(size) uint##size |
| 773 | #define select_vec_dt_int(size) int##size |
| 774 | #define select_vec_dt_float(size) int##size |
| 775 | #define select_vec_dt_ulong(size) ulong##size |
| 776 | #define select_vec_dt_long(size) long##size |
Giorgio Arena | d056e57 | 2020-10-12 11:53:51 +0100 | [diff] [blame] | 777 | |
Giorgio Arena | 2d1a835 | 2020-10-26 15:04:08 +0000 | [diff] [blame] | 778 | #define SELECT_VEC_DATA_TYPE_STR(type, size) select_vec_dt_##type(size) |
| 779 | #define SELECT_VEC_DATA_TYPE(type, size) SELECT_VEC_DATA_TYPE_STR(type, size) |
| 780 | #define SELECT_DATA_TYPE(type) SELECT_VEC_DATA_TYPE_STR(type, 1) |
| 781 | |
Giorgio Arena | e36208c | 2021-01-21 14:53:56 +0000 | [diff] [blame] | 782 | #define signed_int_vec_dt_uchar(size) char##size |
| 783 | #define signed_int_vec_dt_char(size) char##size |
| 784 | #define signed_int_vec_dt_ushort(size) short##size |
| 785 | #define signed_int_vec_dt_short(size) short##size |
| 786 | #define signed_int_vec_dt_half(size) short##size |
| 787 | #define signed_int_vec_dt_uint(size) int##size |
| 788 | #define signed_int_vec_dt_int(size) int##size |
| 789 | #define signed_int_vec_dt_float(size) int##size |
| 790 | #define signed_int_vec_dt_ulong(size) long##size |
| 791 | #define signed_int_vec_dt_long(size) long##size |
| 792 | |
| 793 | #define SIGNED_INT_VEC_DATA_TYPE_STR(type, size) signed_int_vec_dt_##type(size) |
| 794 | #define SIGNED_INT_VEC_DATA_TYPE(type, size) SIGNED_INT_VEC_DATA_TYPE_STR(type, size) |
| 795 | #define SIGNED_INT_DATA_TYPE(type) SIGNED_INT_VEC_DATA_TYPE_STR(type, 1) |
| 796 | |
Giorgio Arena | 2d1a835 | 2020-10-26 15:04:08 +0000 | [diff] [blame] | 797 | #define sum_reduce_1(x) (x) |
| 798 | #define sum_reduce_2(x) ((x).s0) + ((x).s1) |
| 799 | #define sum_reduce_3(x) sum_reduce_2((x).s01) + ((x).s2) |
| 800 | #define sum_reduce_4(x) sum_reduce_2((x).s01) + sum_reduce_2((x).s23) |
| 801 | #define sum_reduce_8(x) sum_reduce_4((x).s0123) + sum_reduce_4((x).s4567) |
| 802 | #define sum_reduce_16(x) sum_reduce_8((x).s01234567) + sum_reduce_8((x).s89ABCDEF) |
| 803 | |
| 804 | #define SUM_REDUCE_STR(x, size) sum_reduce_##size(x) |
| 805 | #define SUM_REDUCE(x, size) SUM_REDUCE_STR(x, size) |
| 806 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 807 | #define prod_reduce_1(x) (x) |
| 808 | #define prod_reduce_2(x) ((x).s0) * ((x).s1) |
| 809 | #define prod_reduce_3(x) prod_reduce_2((x).s01) * ((x).s2) |
| 810 | #define prod_reduce_4(x) prod_reduce_2((x).s01) * prod_reduce_2((x).s23) |
| 811 | #define prod_reduce_8(x) prod_reduce_4((x).s0123) * prod_reduce_4((x).s4567) |
| 812 | #define prod_reduce_16(x) prod_reduce_8((x).s01234567) * prod_reduce_8((x).s89ABCDEF) |
| 813 | |
| 814 | #define PROD_REDUCE_STR(x, size) prod_reduce_##size(x) |
| 815 | #define PROD_REDUCE(x, size) PROD_REDUCE_STR(x, size) |
| 816 | |
Giorgio Arena | 2d1a835 | 2020-10-26 15:04:08 +0000 | [diff] [blame] | 817 | #define max_reduce_1(x) (x) |
| 818 | #define max_reduce_2(x) max(((x).s0), ((x).s1)) |
| 819 | #define max_reduce_3(x) max(max_reduce_2((x).s01), ((x).s2)) |
| 820 | #define max_reduce_4(x) max(max_reduce_2((x).s01), max_reduce_2((x).s23)) |
| 821 | #define max_reduce_8(x) max(max_reduce_4((x).s0123), max_reduce_4((x).s4567)) |
| 822 | #define max_reduce_16(x) max(max_reduce_8((x).s01234567), max_reduce_8((x).s89ABCDEF)) |
| 823 | |
| 824 | #define MAX_REDUCE_STR(x, size) max_reduce_##size(x) |
| 825 | #define MAX_REDUCE(x, size) MAX_REDUCE_STR(x, size) |
Giorgio Arena | d056e57 | 2020-10-12 11:53:51 +0100 | [diff] [blame] | 826 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 827 | #define VECTOR_DECLARATION(name) \ |
| 828 | __global uchar *name##_ptr, \ |
| 829 | uint name##_stride_x, \ |
| 830 | uint name##_step_x, \ |
| 831 | uint name##_offset_first_element_in_bytes |
| 832 | |
| 833 | #define IMAGE_DECLARATION(name) \ |
| 834 | __global uchar *name##_ptr, \ |
| 835 | uint name##_stride_x, \ |
| 836 | uint name##_step_x, \ |
| 837 | uint name##_stride_y, \ |
| 838 | uint name##_step_y, \ |
| 839 | uint name##_offset_first_element_in_bytes |
| 840 | |
| 841 | #define TENSOR3D_DECLARATION(name) \ |
| 842 | __global uchar *name##_ptr, \ |
| 843 | uint name##_stride_x, \ |
| 844 | uint name##_step_x, \ |
| 845 | uint name##_stride_y, \ |
| 846 | uint name##_step_y, \ |
| 847 | uint name##_stride_z, \ |
| 848 | uint name##_step_z, \ |
| 849 | uint name##_offset_first_element_in_bytes |
| 850 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 851 | #define TENSOR4D_DECLARATION(name) \ |
| 852 | __global uchar *name##_ptr, \ |
| 853 | uint name##_stride_x, \ |
| 854 | uint name##_step_x, \ |
| 855 | uint name##_stride_y, \ |
| 856 | uint name##_step_y, \ |
| 857 | uint name##_stride_z, \ |
| 858 | uint name##_step_z, \ |
| 859 | uint name##_stride_w, \ |
| 860 | uint name##_step_w, \ |
| 861 | uint name##_offset_first_element_in_bytes |
| 862 | |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 863 | #define TENSOR5D_DECLARATION(name) \ |
| 864 | __global uchar *name##_ptr, \ |
| 865 | uint name##_stride_x, \ |
| 866 | uint name##_step_x, \ |
| 867 | uint name##_stride_y, \ |
| 868 | uint name##_step_y, \ |
| 869 | uint name##_stride_z, \ |
| 870 | uint name##_step_z, \ |
| 871 | uint name##_stride_w, \ |
| 872 | uint name##_step_w, \ |
| 873 | uint name##_stride_v, \ |
| 874 | uint name##_step_v, \ |
| 875 | uint name##_offset_first_element_in_bytes |
| 876 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 877 | #define CONVERT_TO_VECTOR_STRUCT(name) \ |
| 878 | update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x) |
| 879 | |
| 880 | #define CONVERT_TO_VECTOR_STRUCT_NO_STEP(name) \ |
| 881 | update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0) |
| 882 | |
| 883 | #define CONVERT_TO_IMAGE_STRUCT(name) \ |
| 884 | update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y) |
| 885 | |
| 886 | #define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name) \ |
| 887 | update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0) |
| 888 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 889 | #define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ |
| 890 | update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, name##_stride_z, name##_step_z) |
| 891 | |
Anthony Barbier | 7ff47a3 | 2017-07-11 16:54:04 +0100 | [diff] [blame] | 892 | #define CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(name) \ |
| 893 | update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, name##_step_z) |
| 894 | |
steniu01 | 0d523cc | 2017-07-13 14:24:23 +0100 | [diff] [blame] | 895 | #define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ |
| 896 | update_image_from_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, name##_stride_z, name##_step_z) |
| 897 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 898 | #define CONVERT_TO_TENSOR3D_STRUCT(name) \ |
| 899 | update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ |
| 900 | name##_stride_z, name##_step_z) |
| 901 | |
| 902 | #define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name) \ |
| 903 | update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0) |
| 904 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 905 | #define CONVERT_TO_TENSOR4D_STRUCT(name, mod_size) \ |
| 906 | update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ |
Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [diff] [blame] | 907 | name##_stride_z, name##_step_z, name##_stride_w, name##_step_w, mod_size) |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 908 | |
| 909 | #define CONVERT_TO_TENSOR4D_STRUCT_NO_STEP(name, mod_size) \ |
| 910 | update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0, name##_stride_w, 0, mod_size) |
| 911 | |
Gian Marco Iodice | 4d81d75 | 2020-07-14 15:05:31 +0100 | [diff] [blame] | 912 | #define CONVERT_TO_TENSOR3D_STRUCT_NO_UPDATE_PTR(name) \ |
| 913 | tensor3D_ptr_no_update(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ |
| 914 | name##_stride_z, name##_step_z) |
| 915 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 916 | /** Structure to hold Vector information */ |
| 917 | typedef struct Vector |
| 918 | { |
| 919 | __global uchar *ptr; /**< Pointer to the starting postion of the buffer */ |
| 920 | int offset_first_element_in_bytes; /**< The offset of the first element in the source image */ |
| 921 | int stride_x; /**< Stride of the image in X dimension (in bytes) */ |
| 922 | } Vector; |
| 923 | |
| 924 | /** Structure to hold Image information */ |
| 925 | typedef struct Image |
| 926 | { |
| 927 | __global uchar *ptr; /**< Pointer to the starting postion of the buffer */ |
| 928 | int offset_first_element_in_bytes; /**< The offset of the first element in the source image */ |
| 929 | int stride_x; /**< Stride of the image in X dimension (in bytes) */ |
| 930 | int stride_y; /**< Stride of the image in Y dimension (in bytes) */ |
| 931 | } Image; |
| 932 | |
| 933 | /** Structure to hold 3D tensor information */ |
| 934 | typedef struct Tensor3D |
| 935 | { |
| 936 | __global uchar *ptr; /**< Pointer to the starting postion of the buffer */ |
| 937 | int offset_first_element_in_bytes; /**< The offset of the first element in the source image */ |
| 938 | int stride_x; /**< Stride of the image in X dimension (in bytes) */ |
| 939 | int stride_y; /**< Stride of the image in Y dimension (in bytes) */ |
| 940 | int stride_z; /**< Stride of the image in Z dimension (in bytes) */ |
| 941 | } Tensor3D; |
| 942 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 943 | /** Structure to hold 4D tensor information */ |
| 944 | typedef struct Tensor4D |
| 945 | { |
| 946 | __global uchar *ptr; /**< Pointer to the starting postion of the buffer */ |
| 947 | int offset_first_element_in_bytes; /**< The offset of the first element in the source image */ |
| 948 | int stride_x; /**< Stride of the image in X dimension (in bytes) */ |
| 949 | int stride_y; /**< Stride of the image in Y dimension (in bytes) */ |
| 950 | int stride_z; /**< Stride of the image in Z dimension (in bytes) */ |
| 951 | int stride_w; /**< Stride of the image in W dimension (in bytes) */ |
| 952 | } Tensor4D; |
| 953 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 954 | /** Wrap vector information into an Vector structure, and make the pointer point at this workitem's data. |
| 955 | * |
| 956 | * @param[in] ptr Pointer to the starting postion of the buffer |
| 957 | * @param[in] offset_first_element_in_bytes The offset of the first element in the source vector |
| 958 | * @param[in] stride_x Stride of the vector in X dimension (in bytes) |
| 959 | * @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes) |
| 960 | * |
| 961 | * @return An image object |
| 962 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 963 | inline Vector update_vector_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 964 | { |
| 965 | Vector vector = |
| 966 | { |
| 967 | .ptr = ptr, |
| 968 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 969 | .stride_x = stride_x, |
| 970 | }; |
| 971 | vector.ptr += vector.offset_first_element_in_bytes + get_global_id(0) * step_x; |
| 972 | return vector; |
| 973 | } |
| 974 | |
| 975 | /** Wrap image information into an Image structure, and make the pointer point at this workitem's data. |
| 976 | * |
| 977 | * @param[in] ptr Pointer to the starting postion of the buffer |
| 978 | * @param[in] offset_first_element_in_bytes The offset of the first element in the source image |
| 979 | * @param[in] stride_x Stride of the image in X dimension (in bytes) |
| 980 | * @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes) |
| 981 | * @param[in] stride_y Stride of the image in Y dimension (in bytes) |
| 982 | * @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes) |
| 983 | * |
| 984 | * @return An image object |
| 985 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 986 | inline Image update_image_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 987 | { |
| 988 | Image img = |
| 989 | { |
| 990 | .ptr = ptr, |
| 991 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 992 | .stride_x = stride_x, |
| 993 | .stride_y = stride_y |
| 994 | }; |
| 995 | img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y; |
| 996 | return img; |
| 997 | } |
| 998 | |
Anthony Barbier | 7ff47a3 | 2017-07-11 16:54:04 +0100 | [diff] [blame] | 999 | /** Wrap 3D tensor information into an image structure, and make the pointer point at this workitem's data. |
| 1000 | * |
| 1001 | * @param[in] ptr Pointer to the starting postion of the buffer |
| 1002 | * @param[in] offset_first_element_in_bytes The offset of the first element in the source image |
| 1003 | * @param[in] stride_x Stride of the image in X dimension (in bytes) |
| 1004 | * @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes) |
| 1005 | * @param[in] stride_y Stride of the image in Y dimension (in bytes) |
| 1006 | * @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes) |
| 1007 | * @param[in] stride_z Stride of the image in Z dimension (in bytes) |
| 1008 | * @param[in] step_z stride_z * number of elements along Z processed per workitem(in bytes) |
| 1009 | * |
| 1010 | * @return A 3D tensor object |
| 1011 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1012 | inline Image update_image_from_tensor3D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z) |
Anthony Barbier | 7ff47a3 | 2017-07-11 16:54:04 +0100 | [diff] [blame] | 1013 | { |
| 1014 | Image img = |
| 1015 | { |
| 1016 | .ptr = ptr, |
| 1017 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 1018 | .stride_x = stride_x, |
| 1019 | .stride_y = stride_y |
| 1020 | }; |
| 1021 | img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + get_global_id(2) * step_z; |
| 1022 | return img; |
| 1023 | } |
| 1024 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1025 | /** Wrap 3D tensor information into an tensor structure, and make the pointer point at this workitem's data. |
| 1026 | * |
| 1027 | * @param[in] ptr Pointer to the starting postion of the buffer |
| 1028 | * @param[in] offset_first_element_in_bytes The offset of the first element in the source image |
| 1029 | * @param[in] stride_x Stride of the image in X dimension (in bytes) |
| 1030 | * @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes) |
| 1031 | * @param[in] stride_y Stride of the image in Y dimension (in bytes) |
| 1032 | * @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes) |
| 1033 | * @param[in] stride_z Stride of the image in Z dimension (in bytes) |
| 1034 | * @param[in] step_z stride_z * number of elements along Z processed per workitem(in bytes) |
| 1035 | * |
| 1036 | * @return A 3D tensor object |
| 1037 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1038 | inline Tensor3D update_tensor3D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1039 | { |
| 1040 | Tensor3D tensor = |
| 1041 | { |
| 1042 | .ptr = ptr, |
| 1043 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 1044 | .stride_x = stride_x, |
| 1045 | .stride_y = stride_y, |
| 1046 | .stride_z = stride_z |
| 1047 | }; |
| 1048 | tensor.ptr += tensor.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + get_global_id(2) * step_z; |
| 1049 | return tensor; |
| 1050 | } |
| 1051 | |
Gian Marco Iodice | 4d81d75 | 2020-07-14 15:05:31 +0100 | [diff] [blame] | 1052 | /** Wrap 3D tensor information into an tensor structure. |
| 1053 | * |
| 1054 | * @param[in] ptr Pointer to the starting postion of the buffer |
| 1055 | * @param[in] offset_first_element_in_bytes The offset of the first element in the source image |
| 1056 | * @param[in] stride_x Stride of the image in X dimension (in bytes) |
| 1057 | * @param[in] step_x stride_x * number of elements along X processed per workitem(in bytes) |
| 1058 | * @param[in] stride_y Stride of the image in Y dimension (in bytes) |
| 1059 | * @param[in] step_y stride_y * number of elements along Y processed per workitem(in bytes) |
| 1060 | * @param[in] stride_z Stride of the image in Z dimension (in bytes) |
| 1061 | * @param[in] step_z stride_z * number of elements along Z processed per workitem(in bytes) |
| 1062 | * |
| 1063 | * @return A 3D tensor object |
| 1064 | */ |
| 1065 | inline Tensor3D tensor3D_ptr_no_update(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z) |
| 1066 | { |
| 1067 | Tensor3D tensor = |
| 1068 | { |
| 1069 | .ptr = ptr, |
| 1070 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 1071 | .stride_x = stride_x, |
| 1072 | .stride_y = stride_y, |
| 1073 | .stride_z = stride_z |
| 1074 | }; |
| 1075 | return tensor; |
| 1076 | } |
| 1077 | |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1078 | inline Tensor4D update_tensor4D_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z, uint stride_w, |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 1079 | uint step_w, |
| 1080 | uint mod_size) |
| 1081 | { |
| 1082 | Tensor4D tensor = |
| 1083 | { |
| 1084 | .ptr = ptr, |
| 1085 | .offset_first_element_in_bytes = offset_first_element_in_bytes, |
| 1086 | .stride_x = stride_x, |
| 1087 | .stride_y = stride_y, |
| 1088 | .stride_z = stride_z, |
| 1089 | .stride_w = stride_w |
| 1090 | }; |
| 1091 | |
| 1092 | tensor.ptr += tensor.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y + (get_global_id(2) % mod_size) * step_z + (get_global_id(2) / mod_size) * step_w; |
| 1093 | return tensor; |
| 1094 | } |
| 1095 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1096 | /** Get the pointer position of a Vector |
| 1097 | * |
| 1098 | * @param[in] vec Pointer to the starting position of the buffer |
| 1099 | * @param[in] x Relative X position |
| 1100 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1101 | inline __global const uchar *vector_offset(const Vector *vec, int x) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1102 | { |
| 1103 | return vec->ptr + x * vec->stride_x; |
| 1104 | } |
| 1105 | |
| 1106 | /** Get the pointer position of a Image |
| 1107 | * |
| 1108 | * @param[in] img Pointer to the starting position of the buffer |
| 1109 | * @param[in] x Relative X position |
| 1110 | * @param[in] y Relative Y position |
| 1111 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1112 | inline __global uchar *offset(const Image *img, int x, int y) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1113 | { |
| 1114 | return img->ptr + x * img->stride_x + y * img->stride_y; |
| 1115 | } |
| 1116 | |
| 1117 | /** Get the pointer position of a Tensor3D |
| 1118 | * |
Gian Marco Iodice | 3a62324 | 2017-07-25 10:25:53 +0100 | [diff] [blame] | 1119 | * @param[in] tensor Pointer to the starting position of the buffer |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1120 | * @param[in] x Relative X position |
| 1121 | * @param[in] y Relative Y position |
| 1122 | * @param[in] z Relative Z position |
| 1123 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1124 | inline __global const uchar *tensor3D_offset(const Tensor3D *tensor, int x, int y, int z) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1125 | { |
| 1126 | return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z; |
| 1127 | } |
| 1128 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 1129 | /** Get the pointer position of a Tensor4D |
| 1130 | * |
| 1131 | * @param[in] tensor Pointer to the starting position of the buffer |
| 1132 | * @param[in] x Relative X position |
| 1133 | * @param[in] y Relative Y position |
| 1134 | * @param[in] z Relative Z position |
| 1135 | * @param[in] w Relative W position |
| 1136 | */ |
Georgios Pinitas | af7f740 | 2018-10-25 16:04:40 +0100 | [diff] [blame] | 1137 | inline __global const uchar *tensor4D_offset(const Tensor4D *tensor, int x, int y, int z, int w) |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 1138 | { |
| 1139 | return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + w * tensor->stride_w; |
| 1140 | } |
| 1141 | |
Gian Marco Iodice | 4d81d75 | 2020-07-14 15:05:31 +0100 | [diff] [blame] | 1142 | /** Get the offset for a given linear index of a Tensor3D |
| 1143 | * |
| 1144 | * @param[in] tensor Pointer to the starting position of the buffer |
| 1145 | * @param[in] width Width of the input tensor |
| 1146 | * @param[in] height Height of the input tensor |
| 1147 | * @param[in] depth Depth of the input tensor |
| 1148 | * @param[in] index Linear index |
| 1149 | */ |
| 1150 | inline __global const uchar *tensor3D_index2ptr(const Tensor3D *tensor, uint width, uint height, uint depth, uint index) |
| 1151 | { |
| 1152 | uint num_elements = width * height; |
| 1153 | |
| 1154 | const uint z = index / num_elements; |
| 1155 | |
| 1156 | index %= num_elements; |
| 1157 | |
| 1158 | const uint y = index / width; |
| 1159 | |
| 1160 | index %= width; |
| 1161 | |
| 1162 | const uint x = index; |
| 1163 | |
| 1164 | return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + tensor->offset_first_element_in_bytes; |
| 1165 | } |
| 1166 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1167 | #endif // _HELPER_H |