1R"( 2 3#ifndef ARM_COMPUTE_HELPER_H 4#define ARM_COMPUTE_HELPER_H 5 6 7 8 9#define STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 10 VSTORE(N0) \ 11 (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 12 13#define STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 14 STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 15 VSTORE(N0) \ 16 (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 17 18#define STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 19 STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 20 VSTORE(N0) \ 21 (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 22 23#define STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 24 STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 25 VSTORE(N0) \ 26 (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 27 28#define STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 29 STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 30 VSTORE(N0) \ 31 (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 32 33#define STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 34 STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 35 VSTORE(N0) \ 36 (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 37 38#define STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 39 STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 40 VSTORE(N0) \ 41 (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 42 43#define STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 44 STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 45 VSTORE(N0) \ 46 (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 47 48#define STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 49 STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 50 VSTORE(N0) \ 51 (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 52 53#define STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 54 STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 55 VSTORE(N0) \ 56 (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 57 58#define STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 59 STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 60 VSTORE(N0) \ 61 (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 62 63#define STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 64 STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 65 VSTORE(N0) \ 66 (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 67 68#define STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 69 STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 70 VSTORE(N0) \ 71 (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 72 73#define STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 74 STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 75 VSTORE(N0) \ 76 (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 77 78#define STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 79 STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 80 VSTORE(N0) \ 81 (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 82 83#define STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 84 STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 85 VSTORE(N0) \ 86 (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 87 88 89 90#define CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 91 VSTORE(N0) \ 92 (CONVERT_SAT((BASENAME##0), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 93 94#define CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 95 CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 96 VSTORE(N0) \ 97 (CONVERT_SAT((BASENAME##1), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 98 99#define CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 100 CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 101 VSTORE(N0) \ 102 (CONVERT_SAT((BASENAME##2), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 103 104#define CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 105 CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 106 VSTORE(N0) \ 107 (CONVERT_SAT((BASENAME##3), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 108 109#define CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 110 CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 111 VSTORE(N0) \ 112 (CONVERT_SAT((BASENAME##4), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 113 114#define CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 115 CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 116 VSTORE(N0) \ 117 (CONVERT_SAT((BASENAME##5), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 118 119#define CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 120 CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 121 VSTORE(N0) \ 122 (CONVERT_SAT((BASENAME##6), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 123 124#define CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 125 CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 126 VSTORE(N0) \ 127 (CONVERT_SAT((BASENAME##7), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 128 129#define CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 130 CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 131 VSTORE(N0) \ 132 (CONVERT_SAT((BASENAME##8), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 133 134#define CONVERT_STORE_ROW_10(N0, DATA, BASENAME, PTR, STRIDE_Y, Z) \ 135 CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 136 VSTORE(N0) \ 137 (CONVERT_SAT((BASENAME##9), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 138 139#define CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 140 CONVERT_STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 141 VSTORE(N0) \ 142 (CONVERT_SAT((BASENAME##A), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 143 144#define CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 145 CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 146 VSTORE(N0) \ 147 (CONVERT_SAT((BASENAME##B), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 148 149#define CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 150 CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 151 VSTORE(N0) \ 152 (CONVERT_SAT((BASENAME##C), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 153 154#define CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 155 CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 156 VSTORE(N0) \ 157 (CONVERT_SAT((BASENAME##D), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 158 159#define CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 160 CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 161 VSTORE(N0) \ 162 (CONVERT_SAT((BASENAME##E), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 163 164#define CONVERT_STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 165 CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 166 VSTORE(N0) \ 167 (CONVERT_SAT((BASENAME##F), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 168 169 170 171 172#define STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_ROW_##M0(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 173#define STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 174 175 176 177#define CONVERT_STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) CONVERT_STORE_ROW_##M0(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 178#define CONVERT_STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) CONVERT_STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 179 180 181 182#define STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 183 VSTORE_PARTIAL(N0, STORE_N0) \ 184 (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 185 186#define STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 187 STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 188 VSTORE_PARTIAL(N0, STORE_N0) \ 189 (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 190 191#define STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 192 STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 193 VSTORE_PARTIAL(N0, STORE_N0) \ 194 (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 195 196#define STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 197 STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 198 VSTORE_PARTIAL(N0, STORE_N0) \ 199 (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 200 201#define STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 202 STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 203 VSTORE_PARTIAL(N0, STORE_N0) \ 204 (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 205 206#define STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 207 STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 208 VSTORE_PARTIAL(N0, STORE_N0) \ 209 (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 210 211#define STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 212 STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 213 VSTORE_PARTIAL(N0, STORE_N0) \ 214 (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 215 216#define STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 217 STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 218 VSTORE_PARTIAL(N0, STORE_N0) \ 219 (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 220 221#define STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 222 STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 223 VSTORE_PARTIAL(N0, STORE_N0) \ 224 (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 225 226#define STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 227 STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 228 VSTORE_PARTIAL(N0, STORE_N0) \ 229 (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 230 231#define STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 232 STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 233 VSTORE_PARTIAL(N0, STORE_N0) \ 234 (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 235 236#define STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 237 STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 238 VSTORE_PARTIAL(N0, STORE_N0) \ 239 (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 240 241#define STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 242 STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 243 VSTORE_PARTIAL(N0, STORE_N0) \ 244 (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 245 246#define STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 247 STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 248 VSTORE_PARTIAL(N0, STORE_N0) \ 249 (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 250 251#define STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 252 STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 253 VSTORE_PARTIAL(N0, STORE_N0) \ 254 (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 255 256#define STORE_ROW_PARTIAL_16(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 257 STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 258 VSTORE_PARTIAL(N0, STORE_N0) \ 259 (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 260 261 262 263#define STORE_BLOCK_PARTIAL_STR(STORE_M0, STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_ROW_PARTIAL_##STORE_M0(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 264#define STORE_BLOCK_PARTIAL(STORE_M0, STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_BLOCK_PARTIAL_STR(STORE_M0, STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 265 266#define STORE_BLOCK_PARTIAL_IN_X_AND_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) \ 267 if(!(PARTIAL_COND_X) && !(PARTIAL_COND_Y)) \ 268 { \ 269 STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 270 } \ 271 else if((PARTIAL_COND_Y) && !(PARTIAL_COND_X)) \ 272 { \ 273 STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 274 } \ 275 else if(!(PARTIAL_COND_Y) && (PARTIAL_COND_X)) \ 276 { \ 277 STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 278 } \ 279 else \ 280 { \ 281 STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 282 } 283 284#define STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) \ 285 if(!(PARTIAL_COND_X)) \ 286 { \ 287 STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 288 } \ 289 else \ 290 { \ 291 STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 292 } 293 294#define STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) \ 295 if(!(PARTIAL_COND_Y)) \ 296 { \ 297 STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 298 } \ 299 else \ 300 { \ 301 STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 302 } 303 304 305#if defined(PARTIAL_STORE_M0) && defined(PARTIAL_STORE_N0) 306 307 308#if PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 == 0 309 310#define STORE_BLOCK_BOUNDARY_AWARE(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) \ 311 STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 312 313#elif PARTIAL_STORE_M0 > 0 && PARTIAL_STORE_N0 == 0 314 315#define STORE_BLOCK_BOUNDARY_AWARE(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) \ 316 STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) 317 318#elif PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 > 0 319 320#define STORE_BLOCK_BOUNDARY_AWARE(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) \ 321 STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) 322 323#else 324 325#define STORE_BLOCK_BOUNDARY_AWARE(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) \ 326 STORE_BLOCK_PARTIAL_IN_X_AND_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_STORE_N0, PARTIAL_COND_Y, PARTIAL_COND_X) 327 328#endif 329 330#endif 331 332 333#if defined(PARTIAL_STORE_M0) 334 335#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 336 ((uint)(max(0, (int)(y * M0) - (int)((M0 - PARTIAL_STORE_M0) % M0)))) 337#else 338#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 339 ((uint)(y * M0)) 340#endif 341 342 343 344#define STORE_VECTOR_SELECT(basename, data_type, ptr, vec_size, leftover, cond) \ 345 STORE_BLOCK_PARTIAL_IN_X(1, vec_size, data_type, basename, ptr, 0, 0, leftover, cond) 346 347 348#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 349#pragma OPENCL EXTENSION cl_khr_fp16 : enable 350#endif 351 352#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) 353#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable 354#endif 355 356#if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) 357#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable 358#endif 359 360#if defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf) 361#pragma OPENCL EXTENSION cl_arm_printf : enable 362#endif 363 364#define GPU_ARCH_MIDGARD 0x100 365#define GPU_ARCH_BIFROST 0x200 366#define GPU_ARCH_VALHALL 0x300 367 368 369#define CONCAT(a, b) a##b 370 371 372#define EXPAND(x) x 373 374 375#define CLAMP(x, min_val, max_val) min(max(x, min_val), max_val) 376 377 378#define REV1(x) ((x)) 379#define REV2(x) ((x).s10) 380#define REV3(x) ((x).s210) 381#define REV4(x) ((x).s3210) 382#define REV8(x) ((x).s76543210) 383#define REV16(x) ((x).sFEDCBA9876543210) 384 385 386 387#define REVERSE_STR(x, s) REV##s((x)) 388#define REVERSE(x, s) REVERSE_STR(x, s) 389 390 391 392#define ROT1_0(x) ((x)) 393#define ROT1_1(x) ((x)) 394 395#define ROT2_0(x) ((x)) 396#define ROT2_1(x) ((x).s10) 397#define ROT2_2(x) ((x)) 398 399#define ROT3_0(x) ((x)) 400#define ROT3_1(x) ((x).s201) 401#define ROT3_2(x) ((x).s120) 402#define ROT3_3(x) ((x)) 403 404#define ROT4_0(x) ((x)) 405#define ROT4_1(x) ((x).s3012) 406#define ROT4_2(x) ((x).s2301) 407#define ROT4_3(x) ((x).s1230) 408#define ROT4_4(x) ((x)) 409 410#define ROT8_0(x) ((x)) 411#define ROT8_1(x) ((x).s70123456) 412#define ROT8_2(x) ((x).s67012345) 413#define ROT8_3(x) ((x).s56701234) 414#define ROT8_4(x) ((x).s45670123) 415#define ROT8_5(x) ((x).s34567012) 416#define ROT8_6(x) ((x).s23456701) 417#define ROT8_7(x) ((x).s12345670) 418#define ROT8_8(x) ((x)) 419 420#define ROT16_0(x) ((x)) 421#define ROT16_1(x) ((x).sF0123456789ABCDE) 422#define ROT16_2(x) ((x).sEF0123456789ABCD) 423#define ROT16_3(x) ((x).sDEF0123456789ABC) 424#define ROT16_4(x) ((x).sCDEF0123456789AB) 425#define ROT16_5(x) ((x).sBCDEF0123456789A) 426#define ROT16_6(x) ((x).sABCDEF0123456789) 427#define ROT16_7(x) ((x).s9ABCDEF012345678) 428#define ROT16_8(x) ((x).s89ABCDEF01234567) 429#define ROT16_9(x) ((x).s789ABCDEF0123456) 430#define ROT16_10(x) ((x).s6789ABCDEF012345) 431#define ROT16_11(x) ((x).s56789ABCDEF01234) 432#define ROT16_12(x) ((x).s456789ABCDEF0123) 433#define ROT16_13(x) ((x).s3456789ABCDEF012) 434#define ROT16_14(x) ((x).s23456789ABCDEF01) 435#define ROT16_15(x) ((x).s123456789ABCDEF0) 436#define ROT16_16(x) ((x)) 437 438 439 440#define ROTATE_STR(x, s, n) ROT##s##_##n(x) 441#define ROTATE(x, s, n) ROTATE_STR(x, s, n) 442 443 444 445#define V_OFFS1(dt) (dt##1)(0) 446#define V_OFFS2(dt) (dt##2)(0, 1) 447#define V_OFFS3(dt) (dt##3)(0, 1, 2) 448#define V_OFFS4(dt) (dt##4)(0, 1, 2, 3) 449#define V_OFFS8(dt) (dt##8)(0, 1, 2, 3, 4, 5, 6, 7) 450#define V_OFFS16(dt) (dt##16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) 451 452 453 454#define VEC_OFFS_STR(dt, s) V_OFFS##s(dt) 455#define VEC_OFFS(dt, s) VEC_OFFS_STR(dt, s) 456 457 458#define VLOAD_STR(size) vload##size 459#define VLOAD(size) VLOAD_STR(size) 460 461 462#define VLOAD_PARTIAL_STR(size, load_size) vload_partial_##size##_##load_size 463#define VLOAD_PARTIAL(size, load_size) VLOAD_PARTIAL_STR(size, load_size) 464 465#define NO_LOAD(data, offs, ptr) \ 466 { \ 467 } 468 469 470#define vload_partial_1_0 NO_LOAD 471#define vload_partial_1_1 vload1 472#define vload_partial_1_2 NO_LOAD 473#define vload_partial_1_3 NO_LOAD 474#define vload_partial_1_4 NO_LOAD 475#define vload_partial_1_5 NO_LOAD 476#define vload_partial_1_6 NO_LOAD 477#define vload_partial_1_7 NO_LOAD 478#define vload_partial_1_8 NO_LOAD 479#define vload_partial_1_9 NO_LOAD 480#define vload_partial_1_10 NO_LOAD 481#define vload_partial_1_11 NO_LOAD 482#define vload_partial_1_12 NO_LOAD 483#define vload_partial_1_13 NO_LOAD 484#define vload_partial_1_14 NO_LOAD 485#define vload_partial_1_15 NO_LOAD 486#define vload_partial_1_16 NO_LOAD 487 488#define vload_partial_2_0 NO_LOAD 489#define vload_partial_2_1 vload_partial_1 490#define vload_partial_2_2 vload_partial_2 491#define vload_partial_2_3 NO_LOAD 492#define vload_partial_2_4 NO_LOAD 493#define vload_partial_2_5 NO_LOAD 494#define vload_partial_2_6 NO_LOAD 495#define vload_partial_2_7 NO_LOAD 496#define vload_partial_2_8 NO_LOAD 497#define vload_partial_2_9 NO_LOAD 498#define vload_partial_2_10 NO_LOAD 499#define vload_partial_2_11 NO_LOAD 500#define vload_partial_2_12 NO_LOAD 501#define vload_partial_2_13 NO_LOAD 502#define vload_partial_2_14 NO_LOAD 503#define vload_partial_2_15 NO_LOAD 504#define vload_partial_2_16 NO_LOAD 505 506#define vload_partial_3_0 NO_LOAD 507#define vload_partial_3_1 vload_partial_1 508#define vload_partial_3_2 vload_partial_2 509#define vload_partial_3_3 vload_partial_3 510#define vload_partial_3_4 NO_LOAD 511#define vload_partial_3_5 NO_LOAD 512#define vload_partial_3_6 NO_LOAD 513#define vload_partial_3_7 NO_LOAD 514#define vload_partial_3_8 NO_LOAD 515#define vload_partial_3_9 NO_LOAD 516#define vload_partial_3_10 NO_LOAD 517#define vload_partial_3_11 NO_LOAD 518#define vload_partial_3_12 NO_LOAD 519#define vload_partial_3_13 NO_LOAD 520#define vload_partial_3_14 NO_LOAD 521#define vload_partial_3_15 NO_LOAD 522#define vload_partial_3_16 NO_LOAD 523 524#define vload_partial_4_0 NO_LOAD 525#define vload_partial_4_1 vload_partial_1 526#define vload_partial_4_2 vload_partial_2 527#define vload_partial_4_3 vload_partial_3 528#define vload_partial_4_4 vload_partial_4 529#define vload_partial_4_5 NO_LOAD 530#define vload_partial_4_6 NO_LOAD 531#define vload_partial_4_7 NO_LOAD 532#define vload_partial_4_8 NO_LOAD 533#define vload_partial_4_9 NO_LOAD 534#define vload_partial_4_10 NO_LOAD 535#define vload_partial_4_11 NO_LOAD 536#define vload_partial_4_12 NO_LOAD 537#define vload_partial_4_13 NO_LOAD 538#define vload_partial_4_14 NO_LOAD 539#define vload_partial_4_15 NO_LOAD 540#define vload_partial_4_16 NO_LOAD 541 542#define vload_partial_8_0 NO_LOAD 543#define vload_partial_8_1 vload_partial_1 544#define vload_partial_8_2 vload_partial_2 545#define vload_partial_8_3 vload_partial_3 546#define vload_partial_8_4 vload_partial_4 547#define vload_partial_8_5 vload_partial_5 548#define vload_partial_8_6 vload_partial_6 549#define vload_partial_8_7 vload_partial_7 550#define vload_partial_8_8 vload_partial_8 551#define vload_partial_8_9 NO_LOAD 552#define vload_partial_8_10 NO_LOAD 553#define vload_partial_8_11 NO_LOAD 554#define vload_partial_8_12 NO_LOAD 555#define vload_partial_8_13 NO_LOAD 556#define vload_partial_8_14 NO_LOAD 557#define vload_partial_8_15 NO_LOAD 558#define vload_partial_8_16 NO_LOAD 559 560#define vload_partial_16_0 NO_LOAD 561#define vload_partial_16_1 vload_partial_1 562#define vload_partial_16_2 vload_partial_2 563#define vload_partial_16_3 vload_partial_3 564#define vload_partial_16_4 vload_partial_4 565#define vload_partial_16_5 vload_partial_5 566#define vload_partial_16_6 vload_partial_6 567#define vload_partial_16_7 vload_partial_7 568#define vload_partial_16_8 vload_partial_8 569#define vload_partial_16_9 vload_partial_9 570#define vload_partial_16_10 vload_partial_10 571#define vload_partial_16_11 vload_partial_11 572#define vload_partial_16_12 vload_partial_12 573#define vload_partial_16_13 vload_partial_13 574#define vload_partial_16_14 vload_partial_14 575#define vload_partial_16_15 vload_partial_15 576#define vload_partial_16_16 vload_partial_16 577 578 579#define vload_partial_1(DATA, OFFSET, PTR) \ 580 DATA.s0 = vload1(OFFSET, PTR); 581 582#define vload_partial_2(DATA, OFFSET, PTR) \ 583 DATA.s01 = vload2(OFFSET, PTR); 584 585#define vload_partial_3(DATA, OFFSET, PTR) \ 586 DATA.s012 = vload3(OFFSET, PTR); 587 588#define vload_partial_4(DATA, OFFSET, PTR) \ 589 DATA.s0123 = vload4(OFFSET, PTR); 590 591#define vload_partial_5(DATA, OFFSET, PTR) \ 592 vload_partial_4(DATA.s0123, OFFSET, PTR); \ 593 DATA.s4 = vload1(OFFSET, PTR + 4); 594 595#define vload_partial_6(DATA, OFFSET, PTR) \ 596 vload_partial_4(DATA.s0123, OFFSET, PTR); \ 597 vload_partial_2(DATA.s45, OFFSET, PTR + 4); 598 599#define vload_partial_7(DATA, OFFSET, PTR) \ 600 vload_partial_4(DATA.s0123, OFFSET, PTR); \ 601 vload_partial_3(DATA.s456, OFFSET, PTR + 4); 602 603#define vload_partial_8(DATA, OFFSET, PTR) \ 604 DATA.s01234567 = vload8(OFFSET, PTR); 605 606#define vload_partial_9(DATA, OFFSET, PTR) \ 607 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 608 DATA.s8 = vload1(OFFSET, PTR + 8); 609 610#define vload_partial_10(DATA, OFFSET, PTR) \ 611 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 612 vload_partial_2(DATA.s89, OFFSET, PTR + 8); 613 614#define vload_partial_11(DATA, OFFSET, PTR) \ 615 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 616 vload_partial_3(DATA.s89A, OFFSET, PTR + 8); 617 618#define vload_partial_12(DATA, OFFSET, PTR) \ 619 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 620 vload_partial_4(DATA.s89AB, OFFSET, PTR + 8); 621 622#define vload_partial_13(DATA, OFFSET, PTR) \ 623 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 624 vload_partial_5(DATA.s89ABCDEF, OFFSET, PTR + 8); 625 626#define vload_partial_14(DATA, OFFSET, PTR) \ 627 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 628 vload_partial_6(DATA.s89ABCDEF, OFFSET, PTR + 8); 629 630#define vload_partial_15(DATA, OFFSET, PTR) \ 631 vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 632 vload_partial_7(DATA.s89ABCDEF, OFFSET, PTR + 8); 633 634#define vload_partial_16(DATA, OFFSET, PTR) \ 635 DATA = vload16(OFFSET, PTR); 636 637 638 639#define PIXEL_UNIT4 1 640#define PIXEL_UNIT8 2 641#define PIXEL_UNIT16 4 642 643 644#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) PIXEL_UNIT##vec_size 645#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(vec_size) CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) 646 647 648#define read_image2d_floatx1(img, x_coord, y_coord) (float4)(read_imagef(img, (int2)(x_coord, y_coord))); 649#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))); 650#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))); 651 652#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 653#define read_image2d_halfx1(img, x_coord, y_coord) (half4)(read_imageh(img, (int2)(x_coord, y_coord))); 654#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))); 655#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))); 656#endif 657 658#define write_image2d_floatx1(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values)); 659#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)); 660#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)); 661 662#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 663#define write_image2d_halfx1(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values)); 664#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)); 665#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)); 666#endif 667 668 669#define READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) read_image2d_##data_type##x##n0(img, x_coord, y_coord) 670#define READ_IMAGE2D(data_type, n0, img, x_coord, y_coord) READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) 671 672 673#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) 674#define WRITE_IMAGE2D(data_type, n0, img, x_coord, y_coord, values) WRITE_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord, values) 675 676#define VSTORE_STR(size) vstore##size 677#define VSTORE(size) VSTORE_STR(size) 678 679#define float1 float 680#define half1 half 681#define char1 char 682#define uchar1 uchar 683#define short1 short 684#define ushort1 ushort 685#define int1 int 686#define uint1 uint 687#define long1 long 688#define ulong1 ulong 689#define double1 double 690 691#define vload1(OFFSET, PTR) *(OFFSET + PTR) 692#define vstore1(DATA, OFFSET, PTR) *(OFFSET + PTR) = DATA 693 694 695#define VSTORE_PARTIAL_STR(size, store_size) vstore_partial_##size##_##store_size 696#define VSTORE_PARTIAL(size, store_size) VSTORE_PARTIAL_STR(size, store_size) 697 698#define NO_STORE(data, offs, ptr) \ 699 { \ 700 } 701 702 703#define vstore_partial_1_0 NO_STORE 704#define vstore_partial_1_1 vstore1 705#define vstore_partial_1_2 NO_STORE 706#define vstore_partial_1_3 NO_STORE 707#define vstore_partial_1_4 NO_STORE 708#define vstore_partial_1_5 NO_STORE 709#define vstore_partial_1_6 NO_STORE 710#define vstore_partial_1_7 NO_STORE 711#define vstore_partial_1_8 NO_STORE 712#define vstore_partial_1_9 NO_STORE 713#define vstore_partial_1_10 NO_STORE 714#define vstore_partial_1_11 NO_STORE 715#define vstore_partial_1_12 NO_STORE 716#define vstore_partial_1_13 NO_STORE 717#define vstore_partial_1_14 NO_STORE 718#define vstore_partial_1_15 NO_STORE 719#define vstore_partial_1_16 NO_STORE 720 721#define vstore_partial_2_0 NO_STORE 722#define vstore_partial_2_1 vstore_partial_1 723#define vstore_partial_2_2 vstore_partial_2 724#define vstore_partial_2_3 NO_STORE 725#define vstore_partial_2_4 NO_STORE 726#define vstore_partial_2_5 NO_STORE 727#define vstore_partial_2_6 NO_STORE 728#define vstore_partial_2_7 NO_STORE 729#define vstore_partial_2_8 NO_STORE 730#define vstore_partial_2_9 NO_STORE 731#define vstore_partial_2_10 NO_STORE 732#define vstore_partial_2_11 NO_STORE 733#define vstore_partial_2_12 NO_STORE 734#define vstore_partial_2_13 NO_STORE 735#define vstore_partial_2_14 NO_STORE 736#define vstore_partial_2_15 NO_STORE 737#define vstore_partial_2_16 NO_STORE 738 739#define vstore_partial_3_0 NO_STORE 740#define vstore_partial_3_1 vstore_partial_1 741#define vstore_partial_3_2 vstore_partial_2 742#define vstore_partial_3_3 vstore_partial_3 743#define vstore_partial_3_4 NO_STORE 744#define vstore_partial_3_5 NO_STORE 745#define vstore_partial_3_6 NO_STORE 746#define vstore_partial_3_7 NO_STORE 747#define vstore_partial_3_8 NO_STORE 748#define vstore_partial_3_9 NO_STORE 749#define vstore_partial_3_10 NO_STORE 750#define vstore_partial_3_11 NO_STORE 751#define vstore_partial_3_12 NO_STORE 752#define vstore_partial_3_13 NO_STORE 753#define vstore_partial_3_14 NO_STORE 754#define vstore_partial_3_15 NO_STORE 755#define vstore_partial_3_16 NO_STORE 756 757#define vstore_partial_4_0 NO_STORE 758#define vstore_partial_4_1 vstore_partial_1 759#define vstore_partial_4_2 vstore_partial_2 760#define vstore_partial_4_3 vstore_partial_3 761#define vstore_partial_4_4 vstore_partial_4 762#define vstore_partial_4_5 NO_STORE 763#define vstore_partial_4_6 NO_STORE 764#define vstore_partial_4_7 NO_STORE 765#define vstore_partial_4_8 NO_STORE 766#define vstore_partial_4_9 NO_STORE 767#define vstore_partial_4_10 NO_STORE 768#define vstore_partial_4_11 NO_STORE 769#define vstore_partial_4_12 NO_STORE 770#define vstore_partial_4_13 NO_STORE 771#define vstore_partial_4_14 NO_STORE 772#define vstore_partial_4_15 NO_STORE 773#define vstore_partial_4_16 NO_STORE 774 775#define vstore_partial_8_0 NO_STORE 776#define vstore_partial_8_1 vstore_partial_1 777#define vstore_partial_8_2 vstore_partial_2 778#define vstore_partial_8_3 vstore_partial_3 779#define vstore_partial_8_4 vstore_partial_4 780#define vstore_partial_8_5 vstore_partial_5 781#define vstore_partial_8_6 vstore_partial_6 782#define vstore_partial_8_7 vstore_partial_7 783#define vstore_partial_8_8 vstore_partial_8 784#define vstore_partial_8_9 NO_STORE 785#define vstore_partial_8_10 NO_STORE 786#define vstore_partial_8_11 NO_STORE 787#define vstore_partial_8_12 NO_STORE 788#define vstore_partial_8_13 NO_STORE 789#define vstore_partial_8_14 NO_STORE 790#define vstore_partial_8_15 NO_STORE 791#define vstore_partial_8_16 NO_STORE 792 793#define vstore_partial_16_0 NO_STORE 794#define vstore_partial_16_1 vstore_partial_1 795#define vstore_partial_16_2 vstore_partial_2 796#define vstore_partial_16_3 vstore_partial_3 797#define vstore_partial_16_4 vstore_partial_4 798#define vstore_partial_16_5 vstore_partial_5 799#define vstore_partial_16_6 vstore_partial_6 800#define vstore_partial_16_7 vstore_partial_7 801#define vstore_partial_16_8 vstore_partial_8 802#define vstore_partial_16_9 vstore_partial_9 803#define vstore_partial_16_10 vstore_partial_10 804#define vstore_partial_16_11 vstore_partial_11 805#define vstore_partial_16_12 vstore_partial_12 806#define vstore_partial_16_13 vstore_partial_13 807#define vstore_partial_16_14 vstore_partial_14 808#define vstore_partial_16_15 vstore_partial_15 809#define vstore_partial_16_16 vstore_partial_16 810 811 812#define vstore_partial_1(DATA, OFFSET, PTR) \ 813 vstore1(DATA.s0, OFFSET, PTR); 814 815#define vstore_partial_2(DATA, OFFSET, PTR) \ 816 vstore2(DATA.s01, OFFSET, PTR); 817 818#define vstore_partial_3(DATA, OFFSET, PTR) \ 819 vstore3(DATA.s012, OFFSET, PTR); 820 821#define vstore_partial_4(DATA, OFFSET, PTR) \ 822 vstore4(DATA.s0123, OFFSET, PTR); 823 824#define vstore_partial_5(DATA, OFFSET, PTR) \ 825 vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 826 vstore1(DATA.s4, OFFSET, PTR + 4); 827 828#define vstore_partial_6(DATA, OFFSET, PTR) \ 829 vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 830 vstore_partial_2(DATA.s45, OFFSET, PTR + 4); 831 832#define vstore_partial_7(DATA, OFFSET, PTR) \ 833 vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 834 vstore_partial_3(DATA.s456, OFFSET, PTR + 4); 835 836#define vstore_partial_8(DATA, OFFSET, PTR) \ 837 vstore8(DATA.s01234567, OFFSET, PTR); 838 839#define vstore_partial_9(DATA, OFFSET, PTR) \ 840 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 841 vstore1(DATA.s8, OFFSET, PTR + 8); 842 843#define vstore_partial_10(DATA, OFFSET, PTR) \ 844 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 845 vstore_partial_2(DATA.s89, OFFSET, PTR + 8); 846 847#define vstore_partial_11(DATA, OFFSET, PTR) \ 848 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 849 vstore_partial_3(DATA.s89a, OFFSET, PTR + 8); 850 851#define vstore_partial_12(DATA, OFFSET, PTR) \ 852 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 853 vstore_partial_4(DATA.s89ab, OFFSET, PTR + 8); 854 855#define vstore_partial_13(DATA, OFFSET, PTR) \ 856 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 857 vstore_partial_5(DATA.s89abcdef, OFFSET, PTR + 8); 858 859#define vstore_partial_14(DATA, OFFSET, PTR) \ 860 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 861 vstore_partial_6(DATA.s89abcdef, OFFSET, PTR + 8); 862 863#define vstore_partial_15(DATA, OFFSET, PTR) \ 864 vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 865 vstore_partial_7(DATA.s89abcdef, OFFSET, PTR + 8); 866 867#define vstore_partial_16(DATA, OFFSET, PTR) \ 868 vstore16(DATA, OFFSET, PTR); 869 870 871 872 873 874#define convert_float_sat convert_float 875#define convert_float1_sat convert_float 876#define convert_float2_sat convert_float2 877#define convert_float3_sat convert_float3 878#define convert_float4_sat convert_float4 879#define convert_float8_sat convert_float8 880#define convert_float16_sat convert_float16 881#define convert_half_sat convert_float 882#define convert_half1_sat convert_half 883#define convert_half2_sat convert_half2 884#define convert_half3_sat convert_half3 885#define convert_half4_sat convert_half4 886#define convert_half8_sat convert_half8 887#define convert_half16_sat convert_half16 888 889#define convert_float1 convert_float 890#define convert_half1 convert_half 891#define convert_char1 convert_char 892#define convert_uchar1 convert_uchar 893#define convert_short1 convert_short 894#define convert_ushort1 convert_ushort 895#define convert_int1 convert_int 896#define convert_uint1 convert_uint 897#define convert_long1 convert_long 898#define convert_ulong1 convert_ulong 899#define convert_double1 convert_double 900 901#define convert_char1_sat convert_char_sat 902#define convert_uchar1_sat convert_uchar_sat 903#define convert_uchar2_sat convert_uchar2_sat 904#define convert_uchar3_sat convert_uchar3_sat 905#define convert_uchar4_sat convert_uchar4_sat 906#define convert_uchar8_sat convert_uchar8_sat 907#define convert_uchar16_sat convert_uchar16_sat 908#define convert_short1_sat convert_short_sat 909#define convert_ushort1_sat convert_ushort_sat 910#define convert_int1_sat convert_int_sat 911#define convert_uint1_sat convert_uint_sat 912#define convert_long1_sat convert_long_sat 913#define convert_ulong1_sat convert_ulong_sat 914#define convert_double1_sat convert_double_sat 915 916#define VEC_DATA_TYPE_STR(type, size) type##size 917#define VEC_DATA_TYPE(type, size) VEC_DATA_TYPE_STR(type, size) 918 919#define CONVERT_STR(x, type) (convert_##type((x))) 920#define CONVERT(x, type) CONVERT_STR(x, type) 921 922#define CONVERT_SAT_STR(x, type) (convert_##type##_sat((x))) 923#define CONVERT_SAT(x, type) CONVERT_SAT_STR(x, type) 924 925#define CONVERT_SAT_ROUND_STR(x, type, round) (convert_##type##_sat_##round((x))) 926#define CONVERT_SAT_ROUND(x, type, round) CONVERT_SAT_ROUND_STR(x, type, round) 927 928#define select_vec_dt_uchar(size) uchar##size 929#define select_vec_dt_char(size) char##size 930#define select_vec_dt_ushort(size) ushort##size 931#define select_vec_dt_short(size) short##size 932#define select_vec_dt_half(size) short##size 933#define select_vec_dt_uint(size) uint##size 934#define select_vec_dt_int(size) int##size 935#define select_vec_dt_float(size) int##size 936#define select_vec_dt_ulong(size) ulong##size 937#define select_vec_dt_long(size) long##size 938 939#define SELECT_VEC_DATA_TYPE_STR(type, size) select_vec_dt_##type(size) 940#define SELECT_VEC_DATA_TYPE(type, size) SELECT_VEC_DATA_TYPE_STR(type, size) 941#define SELECT_DATA_TYPE(type) SELECT_VEC_DATA_TYPE_STR(type, 1) 942 943#define signed_int_vec_dt_uchar(size) char##size 944#define signed_int_vec_dt_char(size) char##size 945#define signed_int_vec_dt_ushort(size) short##size 946#define signed_int_vec_dt_short(size) short##size 947#define signed_int_vec_dt_half(size) short##size 948#define signed_int_vec_dt_uint(size) int##size 949#define signed_int_vec_dt_int(size) int##size 950#define signed_int_vec_dt_float(size) int##size 951#define signed_int_vec_dt_ulong(size) long##size 952#define signed_int_vec_dt_long(size) long##size 953 954#define SIGNED_INT_VEC_DATA_TYPE_STR(type, size) signed_int_vec_dt_##type(size) 955#define SIGNED_INT_VEC_DATA_TYPE(type, size) SIGNED_INT_VEC_DATA_TYPE_STR(type, size) 956#define SIGNED_INT_DATA_TYPE(type) SIGNED_INT_VEC_DATA_TYPE_STR(type, 1) 957 958#define sum_reduce_1(x) (x) 959#define sum_reduce_2(x) ((x).s0) + ((x).s1) 960#define sum_reduce_3(x) sum_reduce_2((x).s01) + ((x).s2) 961#define sum_reduce_4(x) sum_reduce_2((x).s01) + sum_reduce_2((x).s23) 962#define sum_reduce_8(x) sum_reduce_4((x).s0123) + sum_reduce_4((x).s4567) 963#define sum_reduce_16(x) sum_reduce_8((x).s01234567) + sum_reduce_8((x).s89ABCDEF) 964 965#define SUM_REDUCE_STR(x, size) sum_reduce_##size(x) 966#define SUM_REDUCE(x, size) SUM_REDUCE_STR(x, size) 967 968#define prod_reduce_1(x) (x) 969#define prod_reduce_2(x) ((x).s0) * ((x).s1) 970#define prod_reduce_3(x) prod_reduce_2((x).s01) * ((x).s2) 971#define prod_reduce_4(x) prod_reduce_2((x).s01) * prod_reduce_2((x).s23) 972#define prod_reduce_8(x) prod_reduce_4((x).s0123) * prod_reduce_4((x).s4567) 973#define prod_reduce_16(x) prod_reduce_8((x).s01234567) * prod_reduce_8((x).s89ABCDEF) 974 975#define PROD_REDUCE_STR(x, size) prod_reduce_##size(x) 976#define PROD_REDUCE(x, size) PROD_REDUCE_STR(x, size) 977 978#define max_reduce_1(x) (x) 979#define max_reduce_2(x) max(((x).s0), ((x).s1)) 980#define max_reduce_3(x) max(max_reduce_2((x).s01), ((x).s2)) 981#define max_reduce_4(x) max(max_reduce_2((x).s01), max_reduce_2((x).s23)) 982#define max_reduce_8(x) max(max_reduce_4((x).s0123), max_reduce_4((x).s4567)) 983#define max_reduce_16(x) max(max_reduce_8((x).s01234567), max_reduce_8((x).s89ABCDEF)) 984 985#define MAX_REDUCE_STR(x, size) max_reduce_##size(x) 986#define MAX_REDUCE(x, size) MAX_REDUCE_STR(x, size) 987 988#define VECTOR_DECLARATION(name) \ 989 __global uchar *name##_ptr, \ 990 uint name##_stride_x, \ 991 uint name##_step_x, \ 992 uint name##_offset_first_element_in_bytes 993 994#define IMAGE_DECLARATION(name) \ 995 __global uchar *name##_ptr, \ 996 uint name##_stride_x, \ 997 uint name##_step_x, \ 998 uint name##_stride_y, \ 999 uint name##_step_y, \ 1000 uint name##_offset_first_element_in_bytes 1001 1002#define TENSOR3D_DECLARATION(name) \ 1003 __global uchar *name##_ptr, \ 1004 uint name##_stride_x, \ 1005 uint name##_step_x, \ 1006 uint name##_stride_y, \ 1007 uint name##_step_y, \ 1008 uint name##_stride_z, \ 1009 uint name##_step_z, \ 1010 uint name##_offset_first_element_in_bytes 1011 1012#define TENSOR4D_DECLARATION(name) \ 1013 __global uchar *name##_ptr, \ 1014 uint name##_stride_x, \ 1015 uint name##_step_x, \ 1016 uint name##_stride_y, \ 1017 uint name##_step_y, \ 1018 uint name##_stride_z, \ 1019 uint name##_step_z, \ 1020 uint name##_stride_w, \ 1021 uint name##_step_w, \ 1022 uint name##_offset_first_element_in_bytes 1023 1024#define TENSOR5D_DECLARATION(name) \ 1025 __global uchar *name##_ptr, \ 1026 uint name##_stride_x, \ 1027 uint name##_step_x, \ 1028 uint name##_stride_y, \ 1029 uint name##_step_y, \ 1030 uint name##_stride_z, \ 1031 uint name##_step_z, \ 1032 uint name##_stride_w, \ 1033 uint name##_step_w, \ 1034 uint name##_stride_v, \ 1035 uint name##_step_v, \ 1036 uint name##_offset_first_element_in_bytes 1037 1038#define CONVERT_TO_VECTOR_STRUCT(name) \ 1039 update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x) 1040 1041#define CONVERT_TO_VECTOR_STRUCT_NO_STEP(name) \ 1042 update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0) 1043 1044#define CONVERT_TO_IMAGE_STRUCT(name) \ 1045 update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y) 1046 1047#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name) \ 1048 update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0) 1049 1050#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 1051 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) 1052 1053#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(name) \ 1054 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) 1055 1056#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 1057 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) 1058 1059#define CONVERT_TO_TENSOR3D_STRUCT(name) \ 1060 update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 1061 name##_stride_z, name##_step_z) 1062 1063#define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name) \ 1064 update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0) 1065 1066#define CONVERT_TO_TENSOR4D_STRUCT(name, mod_size) \ 1067 update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 1068 name##_stride_z, name##_step_z, name##_stride_w, name##_step_w, mod_size) 1069 1070#define CONVERT_TO_TENSOR4D_STRUCT_NO_STEP(name, mod_size) \ 1071 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) 1072 1073#define CONVERT_TO_TENSOR3D_STRUCT_NO_UPDATE_PTR(name) \ 1074 tensor3D_ptr_no_update(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 1075 name##_stride_z, name##_step_z) 1076 1077 1078typedef struct Vector 1079{ 1080 __global uchar *ptr; 1081 int offset_first_element_in_bytes; 1082 int stride_x; 1083} Vector; 1084 1085 1086typedef struct Image 1087{ 1088 __global uchar *ptr; 1089 int offset_first_element_in_bytes; 1090 int stride_x; 1091 int stride_y; 1092} Image; 1093 1094 1095typedef struct Tensor3D 1096{ 1097 __global uchar *ptr; 1098 int offset_first_element_in_bytes; 1099 int stride_x; 1100 int stride_y; 1101 int stride_z; 1102} Tensor3D; 1103 1104 1105typedef struct Tensor4D 1106{ 1107 __global uchar *ptr; 1108 int offset_first_element_in_bytes; 1109 int stride_x; 1110 int stride_y; 1111 int stride_z; 1112 int stride_w; 1113} Tensor4D; 1114 1115 1116inline Vector update_vector_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x) 1117{ 1118 Vector vector = 1119 { 1120 .ptr = ptr, 1121 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1122 .stride_x = stride_x, 1123 }; 1124 vector.ptr += vector.offset_first_element_in_bytes + get_global_id(0) * step_x; 1125 return vector; 1126} 1127 1128 1129inline 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) 1130{ 1131 Image img = 1132 { 1133 .ptr = ptr, 1134 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1135 .stride_x = stride_x, 1136 .stride_y = stride_y 1137 }; 1138 img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y; 1139 return img; 1140} 1141 1142 1143inline 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) 1144{ 1145 Image img = 1146 { 1147 .ptr = ptr, 1148 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1149 .stride_x = stride_x, 1150 .stride_y = stride_y 1151 }; 1152 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; 1153 return img; 1154} 1155 1156 1157inline 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) 1158{ 1159 Tensor3D tensor = 1160 { 1161 .ptr = ptr, 1162 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1163 .stride_x = stride_x, 1164 .stride_y = stride_y, 1165 .stride_z = stride_z 1166 }; 1167 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; 1168 return tensor; 1169} 1170 1171 1172inline 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) 1173{ 1174 Tensor3D tensor = 1175 { 1176 .ptr = ptr, 1177 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1178 .stride_x = stride_x, 1179 .stride_y = stride_y, 1180 .stride_z = stride_z 1181 }; 1182 return tensor; 1183} 1184 1185inline 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, 1186 uint step_w, 1187 uint mod_size) 1188{ 1189 Tensor4D tensor = 1190 { 1191 .ptr = ptr, 1192 .offset_first_element_in_bytes = offset_first_element_in_bytes, 1193 .stride_x = stride_x, 1194 .stride_y = stride_y, 1195 .stride_z = stride_z, 1196 .stride_w = stride_w 1197 }; 1198 1199 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; 1200 return tensor; 1201} 1202 1203 1204inline __global const uchar *vector_offset(const Vector *vec, int x) 1205{ 1206 return vec->ptr + x * vec->stride_x; 1207} 1208 1209 1210inline __global uchar *offset(const Image *img, int x, int y) 1211{ 1212 return img->ptr + x * img->stride_x + y * img->stride_y; 1213} 1214 1215 1216inline __global const uchar *tensor3D_offset(const Tensor3D *tensor, int x, int y, int z) 1217{ 1218 return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z; 1219} 1220 1221 1222inline __global const uchar *tensor4D_offset(const Tensor4D *tensor, int x, int y, int z, int w) 1223{ 1224 return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + w * tensor->stride_w; 1225} 1226 1227 1228inline __global const uchar *tensor3D_index2ptr(const Tensor3D *tensor, uint width, uint height, uint depth, uint index) 1229{ 1230 uint num_elements = width * height; 1231 1232 const uint z = index / num_elements; 1233 1234 index %= num_elements; 1235 1236 const uint y = index / width; 1237 1238 index %= width; 1239 1240 const uint x = index; 1241 1242 return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + tensor->offset_first_element_in_bytes; 1243} 1244 1245#endif 1246 1247#ifndef SRC_CORE_CL_CL_KERNELS_TILE_HELPERS 1248#define SRC_CORE_CL_CL_KERNELS_TILE_HELPERS 1249 1250 1251 1252 1253#define TILE_VECTOR_SIZE1 1 1254#define TILE_VECTOR_SIZE2 2 1255#define TILE_VECTOR_SIZE3 3 1256#define TILE_VECTOR_SIZE4 4 1257#define TILE_VECTOR_SIZE5 8 1258#define TILE_VECTOR_SIZE6 8 1259#define TILE_VECTOR_SIZE7 8 1260#define TILE_VECTOR_SIZE8 8 1261#define TILE_VECTOR_SIZE9 16 1262#define TILE_VECTOR_SIZE10 16 1263#define TILE_VECTOR_SIZE11 16 1264#define TILE_VECTOR_SIZE12 16 1265#define TILE_VECTOR_SIZE13 16 1266#define TILE_VECTOR_SIZE14 16 1267#define TILE_VECTOR_SIZE15 16 1268#define TILE_VECTOR_SIZE16 16 1269 1270#define TILE_VECTOR_TYPE1(DATA_TYPE) DATA_TYPE##1 1271#define TILE_VECTOR_TYPE2(DATA_TYPE) DATA_TYPE##2 1272#define TILE_VECTOR_TYPE3(DATA_TYPE) DATA_TYPE##3 1273#define TILE_VECTOR_TYPE4(DATA_TYPE) DATA_TYPE##4 1274#define TILE_VECTOR_TYPE5(DATA_TYPE) DATA_TYPE##8 1275#define TILE_VECTOR_TYPE6(DATA_TYPE) DATA_TYPE##8 1276#define TILE_VECTOR_TYPE7(DATA_TYPE) DATA_TYPE##8 1277#define TILE_VECTOR_TYPE8(DATA_TYPE) DATA_TYPE##8 1278#define TILE_VECTOR_TYPE9(DATA_TYPE) DATA_TYPE##16 1279#define TILE_VECTOR_TYPE10(DATA_TYPE) DATA_TYPE##16 1280#define TILE_VECTOR_TYPE11(DATA_TYPE) DATA_TYPE##16 1281#define TILE_VECTOR_TYPE12(DATA_TYPE) DATA_TYPE##16 1282#define TILE_VECTOR_TYPE13(DATA_TYPE) DATA_TYPE##16 1283#define TILE_VECTOR_TYPE14(DATA_TYPE) DATA_TYPE##16 1284#define TILE_VECTOR_TYPE15(DATA_TYPE) DATA_TYPE##16 1285#define TILE_VECTOR_TYPE16(DATA_TYPE) DATA_TYPE##16 1286 1287 1288#define TILE(DATA_TYPE, H, W, BASENAME) TILE_STR(DATA_TYPE, H, W, BASENAME) 1289#define TILE_STR(DATA_TYPE, H, W, BASENAME) \ 1290 union { \ 1291 DATA_TYPE s[TILE_VECTOR_SIZE##W]; \ 1292 TILE_VECTOR_TYPE##W(DATA_TYPE) v; \ 1293 } BASENAME[H] 1294 1295#define TENSOR4D_IMAGE(name) \ 1296 __read_only image2d_t name##_img, \ 1297 __global uchar *name##_ptr, \ 1298 uint name##_stride_x, \ 1299 uint name##_step_x, \ 1300 uint name##_stride_y, \ 1301 uint name##_step_y, \ 1302 uint name##_stride_z, \ 1303 uint name##_step_z, \ 1304 uint name##_stride_w, \ 1305 uint name##_step_w, \ 1306 uint name##_offset_first_element_in_bytes 1307 1308#define TENSOR4D_BUFFER(name) \ 1309 __global uchar *name##_ptr, \ 1310 uint name##_stride_x, \ 1311 uint name##_step_x, \ 1312 uint name##_stride_y, \ 1313 uint name##_step_y, \ 1314 uint name##_stride_z, \ 1315 uint name##_step_z, \ 1316 uint name##_stride_w, \ 1317 uint name##_step_w, \ 1318 uint name##_offset_first_element_in_bytes 1319 1320#define TENSOR4D_STR(name, type) TENSOR4D_##type(name) 1321#define TENSOR4D(name, type) TENSOR4D_STR(name, type) 1322 1323#define TENSOR4D_T_IMAGE(name) \ 1324 __read_only image2d_t name##_img, \ 1325 __global uchar *name##_ptr, \ 1326 uint name##_stride_y, \ 1327 uint name##_stride_z, \ 1328 uint name##_stride_w, \ 1329 uint name##_c, \ 1330 uint name##_w, \ 1331 uint name##_h, \ 1332 uint name##_n, \ 1333 uint name##_offset_first_element_in_bytes 1334 1335#define TENSOR4D_T_BUFFER(name) \ 1336 __global uchar *name##_ptr, \ 1337 uint name##_stride_y, \ 1338 uint name##_stride_z, \ 1339 uint name##_stride_w, \ 1340 uint name##_c, \ 1341 uint name##_w, \ 1342 uint name##_h, \ 1343 uint name##_n, \ 1344 uint name##_offset_first_element_in_bytes 1345 1346#define TENSOR4D_T_STR(name, type) TENSOR4D_T_##type(name) 1347 1348 1349#define TENSOR4D_T(name, type) TENSOR4D_T_STR(name, type) 1350 1351#define TENSOR4D_RO_T_IMAGE(name) \ 1352 __read_only image2d_t name##_img, \ 1353 TENSOR4D_T_BUFFER(name) 1354 1355#define TENSOR4D_RO_T_BUFFER(name) TENSOR4D_T_BUFFER(name) 1356 1357#define TENSOR4D_RO_T_STR(name, type) TENSOR4D_RO_T_##type(name) 1358 1359 1360#define TENSOR4D_RO_T(name, type) TENSOR4D_RO_T_STR(name, type) 1361 1362#define TENSOR4D_WO_T_IMAGE(name) \ 1363 __write_only image2d_t name##_img, \ 1364 TENSOR4D_T_BUFFER(name) 1365 1366#define TENSOR4D_WO_T_BUFFER(name) TENSOR4D_T_BUFFER(name) 1367 1368#define TENSOR4D_WO_T_STR(name, type) TENSOR4D_WO_T_##type(name) 1369 1370 1371#define TENSOR4D_WO_T(name, type) TENSOR4D_WO_T_STR(name, type) 1372 1373#define TENSOR3D_T_IMAGE(name) \ 1374 __read_only image2d_t name##_img, \ 1375 __global uchar *name##_ptr, \ 1376 uint name##_stride_y, \ 1377 uint name##_stride_z, \ 1378 uint name##_w, \ 1379 uint name##_h, \ 1380 uint name##_n, \ 1381 uint name##_offset_first_element_in_bytes 1382 1383#define TENSOR3D_T_BUFFER(name) \ 1384 __global uchar *name##_ptr, \ 1385 uint name##_stride_y, \ 1386 uint name##_stride_z, \ 1387 uint name##_w, \ 1388 uint name##_h, \ 1389 uint name##_n, \ 1390 uint name##_offset_first_element_in_bytes 1391 1392#define TENSOR3D_T_STR(name, type) TENSOR3D_T_##type(name) 1393#define TENSOR3D_T(name, type) TENSOR3D_T_STR(name, type) 1394 1395#if !defined(UNROLL_WITH_PRAGMA) 1396#define UNROLL_INCR(idx, step, macro) idx += (step); (macro) 1397 1398#define LOOP_UNROLLING_1(idx, step, macro) (macro) 1399#define LOOP_UNROLLING_2(idx, step, macro) LOOP_UNROLLING_1(idx, step, macro); UNROLL_INCR(idx, step, macro) 1400#define LOOP_UNROLLING_3(idx, step, macro) LOOP_UNROLLING_2(idx, step, macro); UNROLL_INCR(idx, step, macro) 1401#define LOOP_UNROLLING_4(idx, step, macro) LOOP_UNROLLING_3(idx, step, macro); UNROLL_INCR(idx, step, macro) 1402#define LOOP_UNROLLING_5(idx, step, macro) LOOP_UNROLLING_4(idx, step, macro); UNROLL_INCR(idx, step, macro) 1403#define LOOP_UNROLLING_6(idx, step, macro) LOOP_UNROLLING_5(idx, step, macro); UNROLL_INCR(idx, step, macro) 1404#define LOOP_UNROLLING_7(idx, step, macro) LOOP_UNROLLING_6(idx, step, macro); UNROLL_INCR(idx, step, macro) 1405#define LOOP_UNROLLING_8(idx, step, macro) LOOP_UNROLLING_7(idx, step, macro); UNROLL_INCR(idx, step, macro) 1406#define LOOP_UNROLLING_9(idx, step, macro) LOOP_UNROLLING_8(idx, step, macro); UNROLL_INCR(idx, step, macro) 1407#define LOOP_UNROLLING_10(idx, step, macro) LOOP_UNROLLING_9(idx, step, macro); UNROLL_INCR(idx, step, macro) 1408#define LOOP_UNROLLING_11(idx, step, macro) LOOP_UNROLLING_10(idx, step, macro); UNROLL_INCR(idx, step, macro) 1409#define LOOP_UNROLLING_12(idx, step, macro) LOOP_UNROLLING_11(idx, step, macro); UNROLL_INCR(idx, step, macro) 1410#define LOOP_UNROLLING_13(idx, step, macro) LOOP_UNROLLING_12(idx, step, macro); UNROLL_INCR(idx, step, macro) 1411#define LOOP_UNROLLING_14(idx, step, macro) LOOP_UNROLLING_13(idx, step, macro); UNROLL_INCR(idx, step, macro) 1412#define LOOP_UNROLLING_15(idx, step, macro) LOOP_UNROLLING_14(idx, step, macro); UNROLL_INCR(idx, step, macro) 1413#define LOOP_UNROLLING_16(idx, step, macro) LOOP_UNROLLING_15(idx, step, macro); UNROLL_INCR(idx, step, macro) 1414#define LOOP_UNROLLING_17(idx, step, macro) LOOP_UNROLLING_16(idx, step, macro); UNROLL_INCR(idx, step, macro) 1415#define LOOP_UNROLLING_18(idx, step, macro) LOOP_UNROLLING_17(idx, step, macro); UNROLL_INCR(idx, step, macro) 1416#define LOOP_UNROLLING_19(idx, step, macro) LOOP_UNROLLING_18(idx, step, macro); UNROLL_INCR(idx, step, macro) 1417#define LOOP_UNROLLING_20(idx, step, macro) LOOP_UNROLLING_19(idx, step, macro); UNROLL_INCR(idx, step, macro) 1418#define LOOP_UNROLLING_21(idx, step, macro) LOOP_UNROLLING_20(idx, step, macro); UNROLL_INCR(idx, step, macro) 1419#define LOOP_UNROLLING_22(idx, step, macro) LOOP_UNROLLING_21(idx, step, macro); UNROLL_INCR(idx, step, macro) 1420#define LOOP_UNROLLING_23(idx, step, macro) LOOP_UNROLLING_22(idx, step, macro); UNROLL_INCR(idx, step, macro) 1421#define LOOP_UNROLLING_24(idx, step, macro) LOOP_UNROLLING_23(idx, step, macro); UNROLL_INCR(idx, step, macro) 1422#define LOOP_UNROLLING_25(idx, step, macro) LOOP_UNROLLING_24(idx, step, macro); UNROLL_INCR(idx, step, macro) 1423#define LOOP_UNROLLING_26(idx, step, macro) LOOP_UNROLLING_25(idx, step, macro); UNROLL_INCR(idx, step, macro) 1424#define LOOP_UNROLLING_27(idx, step, macro) LOOP_UNROLLING_26(idx, step, macro); UNROLL_INCR(idx, step, macro) 1425#define LOOP_UNROLLING_28(idx, step, macro) LOOP_UNROLLING_27(idx, step, macro); UNROLL_INCR(idx, step, macro) 1426#define LOOP_UNROLLING_29(idx, step, macro) LOOP_UNROLLING_28(idx, step, macro); UNROLL_INCR(idx, step, macro) 1427#define LOOP_UNROLLING_30(idx, step, macro) LOOP_UNROLLING_29(idx, step, macro); UNROLL_INCR(idx, step, macro) 1428#define LOOP_UNROLLING_31(idx, step, macro) LOOP_UNROLLING_30(idx, step, macro); UNROLL_INCR(idx, step, macro) 1429#define LOOP_UNROLLING_32(idx, step, macro) LOOP_UNROLLING_31(idx, step, macro); UNROLL_INCR(idx, step, macro) 1430#define LOOP_UNROLLING_33(idx, step, macro) LOOP_UNROLLING_32(idx, step, macro); UNROLL_INCR(idx, step, macro) 1431#define LOOP_UNROLLING_34(idx, step, macro) LOOP_UNROLLING_33(idx, step, macro); UNROLL_INCR(idx, step, macro) 1432#define LOOP_UNROLLING_35(idx, step, macro) LOOP_UNROLLING_34(idx, step, macro); UNROLL_INCR(idx, step, macro) 1433#define LOOP_UNROLLING_36(idx, step, macro) LOOP_UNROLLING_35(idx, step, macro); UNROLL_INCR(idx, step, macro) 1434#define LOOP_UNROLLING_37(idx, step, macro) LOOP_UNROLLING_36(idx, step, macro); UNROLL_INCR(idx, step, macro) 1435#define LOOP_UNROLLING_38(idx, step, macro) LOOP_UNROLLING_37(idx, step, macro); UNROLL_INCR(idx, step, macro) 1436#define LOOP_UNROLLING_39(idx, step, macro) LOOP_UNROLLING_38(idx, step, macro); UNROLL_INCR(idx, step, macro) 1437#define LOOP_UNROLLING_40(idx, step, macro) LOOP_UNROLLING_39(idx, step, macro); UNROLL_INCR(idx, step, macro) 1438#define LOOP_UNROLLING_41(idx, step, macro) LOOP_UNROLLING_40(idx, step, macro); UNROLL_INCR(idx, step, macro) 1439#define LOOP_UNROLLING_42(idx, step, macro) LOOP_UNROLLING_41(idx, step, macro); UNROLL_INCR(idx, step, macro) 1440#define LOOP_UNROLLING_43(idx, step, macro) LOOP_UNROLLING_42(idx, step, macro); UNROLL_INCR(idx, step, macro) 1441#define LOOP_UNROLLING_44(idx, step, macro) LOOP_UNROLLING_43(idx, step, macro); UNROLL_INCR(idx, step, macro) 1442#define LOOP_UNROLLING_45(idx, step, macro) LOOP_UNROLLING_44(idx, step, macro); UNROLL_INCR(idx, step, macro) 1443#define LOOP_UNROLLING_46(idx, step, macro) LOOP_UNROLLING_45(idx, step, macro); UNROLL_INCR(idx, step, macro) 1444#define LOOP_UNROLLING_47(idx, step, macro) LOOP_UNROLLING_46(idx, step, macro); UNROLL_INCR(idx, step, macro) 1445#define LOOP_UNROLLING_48(idx, step, macro) LOOP_UNROLLING_47(idx, step, macro); UNROLL_INCR(idx, step, macro) 1446#define LOOP_UNROLLING_49(idx, step, macro) LOOP_UNROLLING_48(idx, step, macro); UNROLL_INCR(idx, step, macro) 1447#define LOOP_UNROLLING_50(idx, step, macro) LOOP_UNROLLING_49(idx, step, macro); UNROLL_INCR(idx, step, macro) 1448#define LOOP_UNROLLING_51(idx, step, macro) LOOP_UNROLLING_50(idx, step, macro); UNROLL_INCR(idx, step, macro) 1449#define LOOP_UNROLLING_52(idx, step, macro) LOOP_UNROLLING_51(idx, step, macro); UNROLL_INCR(idx, step, macro) 1450#define LOOP_UNROLLING_53(idx, step, macro) LOOP_UNROLLING_52(idx, step, macro); UNROLL_INCR(idx, step, macro) 1451#define LOOP_UNROLLING_54(idx, step, macro) LOOP_UNROLLING_53(idx, step, macro); UNROLL_INCR(idx, step, macro) 1452#define LOOP_UNROLLING_55(idx, step, macro) LOOP_UNROLLING_54(idx, step, macro); UNROLL_INCR(idx, step, macro) 1453#define LOOP_UNROLLING_56(idx, step, macro) LOOP_UNROLLING_55(idx, step, macro); UNROLL_INCR(idx, step, macro) 1454#define LOOP_UNROLLING_57(idx, step, macro) LOOP_UNROLLING_56(idx, step, macro); UNROLL_INCR(idx, step, macro) 1455#define LOOP_UNROLLING_58(idx, step, macro) LOOP_UNROLLING_57(idx, step, macro); UNROLL_INCR(idx, step, macro) 1456#define LOOP_UNROLLING_59(idx, step, macro) LOOP_UNROLLING_58(idx, step, macro); UNROLL_INCR(idx, step, macro) 1457#define LOOP_UNROLLING_60(idx, step, macro) LOOP_UNROLLING_59(idx, step, macro); UNROLL_INCR(idx, step, macro) 1458#define LOOP_UNROLLING_61(idx, step, macro) LOOP_UNROLLING_60(idx, step, macro); UNROLL_INCR(idx, step, macro) 1459#define LOOP_UNROLLING_62(idx, step, macro) LOOP_UNROLLING_61(idx, step, macro); UNROLL_INCR(idx, step, macro) 1460#define LOOP_UNROLLING_63(idx, step, macro) LOOP_UNROLLING_62(idx, step, macro); UNROLL_INCR(idx, step, macro) 1461#define LOOP_UNROLLING_64(idx, step, macro) LOOP_UNROLLING_63(idx, step, macro); UNROLL_INCR(idx, step, macro) 1462#define LOOP_UNROLLING_65(idx, step, macro) LOOP_UNROLLING_64(idx, step, macro); UNROLL_INCR(idx, step, macro) 1463#define LOOP_UNROLLING_66(idx, step, macro) LOOP_UNROLLING_65(idx, step, macro); UNROLL_INCR(idx, step, macro) 1464#define LOOP_UNROLLING_67(idx, step, macro) LOOP_UNROLLING_66(idx, step, macro); UNROLL_INCR(idx, step, macro) 1465#define LOOP_UNROLLING_68(idx, step, macro) LOOP_UNROLLING_67(idx, step, macro); UNROLL_INCR(idx, step, macro) 1466#define LOOP_UNROLLING_69(idx, step, macro) LOOP_UNROLLING_68(idx, step, macro); UNROLL_INCR(idx, step, macro) 1467#define LOOP_UNROLLING_70(idx, step, macro) LOOP_UNROLLING_69(idx, step, macro); UNROLL_INCR(idx, step, macro) 1468#define LOOP_UNROLLING_71(idx, step, macro) LOOP_UNROLLING_70(idx, step, macro); UNROLL_INCR(idx, step, macro) 1469#define LOOP_UNROLLING_72(idx, step, macro) LOOP_UNROLLING_71(idx, step, macro); UNROLL_INCR(idx, step, macro) 1470#define LOOP_UNROLLING_73(idx, step, macro) LOOP_UNROLLING_72(idx, step, macro); UNROLL_INCR(idx, step, macro) 1471#define LOOP_UNROLLING_74(idx, step, macro) LOOP_UNROLLING_73(idx, step, macro); UNROLL_INCR(idx, step, macro) 1472#define LOOP_UNROLLING_75(idx, step, macro) LOOP_UNROLLING_74(idx, step, macro); UNROLL_INCR(idx, step, macro) 1473#define LOOP_UNROLLING_76(idx, step, macro) LOOP_UNROLLING_75(idx, step, macro); UNROLL_INCR(idx, step, macro) 1474#define LOOP_UNROLLING_77(idx, step, macro) LOOP_UNROLLING_76(idx, step, macro); UNROLL_INCR(idx, step, macro) 1475#define LOOP_UNROLLING_78(idx, step, macro) LOOP_UNROLLING_77(idx, step, macro); UNROLL_INCR(idx, step, macro) 1476#define LOOP_UNROLLING_79(idx, step, macro) LOOP_UNROLLING_78(idx, step, macro); UNROLL_INCR(idx, step, macro) 1477#define LOOP_UNROLLING_80(idx, step, macro) LOOP_UNROLLING_79(idx, step, macro); UNROLL_INCR(idx, step, macro) 1478#define LOOP_UNROLLING_81(idx, step, macro) LOOP_UNROLLING_80(idx, step, macro); UNROLL_INCR(idx, step, macro) 1479#define LOOP_UNROLLING_82(idx, step, macro) LOOP_UNROLLING_81(idx, step, macro); UNROLL_INCR(idx, step, macro) 1480#define LOOP_UNROLLING_83(idx, step, macro) LOOP_UNROLLING_82(idx, step, macro); UNROLL_INCR(idx, step, macro) 1481#define LOOP_UNROLLING_84(idx, step, macro) LOOP_UNROLLING_83(idx, step, macro); UNROLL_INCR(idx, step, macro) 1482#define LOOP_UNROLLING_85(idx, step, macro) LOOP_UNROLLING_84(idx, step, macro); UNROLL_INCR(idx, step, macro) 1483#define LOOP_UNROLLING_86(idx, step, macro) LOOP_UNROLLING_85(idx, step, macro); UNROLL_INCR(idx, step, macro) 1484#define LOOP_UNROLLING_87(idx, step, macro) LOOP_UNROLLING_86(idx, step, macro); UNROLL_INCR(idx, step, macro) 1485#define LOOP_UNROLLING_88(idx, step, macro) LOOP_UNROLLING_87(idx, step, macro); UNROLL_INCR(idx, step, macro) 1486#define LOOP_UNROLLING_89(idx, step, macro) LOOP_UNROLLING_88(idx, step, macro); UNROLL_INCR(idx, step, macro) 1487#define LOOP_UNROLLING_90(idx, step, macro) LOOP_UNROLLING_89(idx, step, macro); UNROLL_INCR(idx, step, macro) 1488#define LOOP_UNROLLING_91(idx, step, macro) LOOP_UNROLLING_90(idx, step, macro); UNROLL_INCR(idx, step, macro) 1489#define LOOP_UNROLLING_92(idx, step, macro) LOOP_UNROLLING_91(idx, step, macro); UNROLL_INCR(idx, step, macro) 1490#define LOOP_UNROLLING_93(idx, step, macro) LOOP_UNROLLING_92(idx, step, macro); UNROLL_INCR(idx, step, macro) 1491#define LOOP_UNROLLING_94(idx, step, macro) LOOP_UNROLLING_93(idx, step, macro); UNROLL_INCR(idx, step, macro) 1492#define LOOP_UNROLLING_95(idx, step, macro) LOOP_UNROLLING_94(idx, step, macro); UNROLL_INCR(idx, step, macro) 1493#define LOOP_UNROLLING_96(idx, step, macro) LOOP_UNROLLING_95(idx, step, macro); UNROLL_INCR(idx, step, macro) 1494#define LOOP_UNROLLING_97(idx, step, macro) LOOP_UNROLLING_96(idx, step, macro); UNROLL_INCR(idx, step, macro) 1495#define LOOP_UNROLLING_98(idx, step, macro) LOOP_UNROLLING_97(idx, step, macro); UNROLL_INCR(idx, step, macro) 1496#define LOOP_UNROLLING_99(idx, step, macro) LOOP_UNROLLING_98(idx, step, macro); UNROLL_INCR(idx, step, macro) 1497#define LOOP_UNROLLING_100(idx, step, macro) LOOP_UNROLLING_99(idx, step, macro); UNROLL_INCR(idx, step, macro) 1498#define LOOP_UNROLLING_101(idx, step, macro) LOOP_UNROLLING_100(idx, step, macro); UNROLL_INCR(idx, step, macro) 1499#define LOOP_UNROLLING_102(idx, step, macro) LOOP_UNROLLING_101(idx, step, macro); UNROLL_INCR(idx, step, macro) 1500#define LOOP_UNROLLING_103(idx, step, macro) LOOP_UNROLLING_102(idx, step, macro); UNROLL_INCR(idx, step, macro) 1501#define LOOP_UNROLLING_104(idx, step, macro) LOOP_UNROLLING_103(idx, step, macro); UNROLL_INCR(idx, step, macro) 1502#define LOOP_UNROLLING_105(idx, step, macro) LOOP_UNROLLING_104(idx, step, macro); UNROLL_INCR(idx, step, macro) 1503#define LOOP_UNROLLING_106(idx, step, macro) LOOP_UNROLLING_105(idx, step, macro); UNROLL_INCR(idx, step, macro) 1504#define LOOP_UNROLLING_107(idx, step, macro) LOOP_UNROLLING_106(idx, step, macro); UNROLL_INCR(idx, step, macro) 1505#define LOOP_UNROLLING_108(idx, step, macro) LOOP_UNROLLING_107(idx, step, macro); UNROLL_INCR(idx, step, macro) 1506#define LOOP_UNROLLING_109(idx, step, macro) LOOP_UNROLLING_108(idx, step, macro); UNROLL_INCR(idx, step, macro) 1507#define LOOP_UNROLLING_110(idx, step, macro) LOOP_UNROLLING_109(idx, step, macro); UNROLL_INCR(idx, step, macro) 1508#define LOOP_UNROLLING_111(idx, step, macro) LOOP_UNROLLING_110(idx, step, macro); UNROLL_INCR(idx, step, macro) 1509#define LOOP_UNROLLING_112(idx, step, macro) LOOP_UNROLLING_111(idx, step, macro); UNROLL_INCR(idx, step, macro) 1510#define LOOP_UNROLLING_113(idx, step, macro) LOOP_UNROLLING_112(idx, step, macro); UNROLL_INCR(idx, step, macro) 1511#define LOOP_UNROLLING_114(idx, step, macro) LOOP_UNROLLING_113(idx, step, macro); UNROLL_INCR(idx, step, macro) 1512#define LOOP_UNROLLING_115(idx, step, macro) LOOP_UNROLLING_114(idx, step, macro); UNROLL_INCR(idx, step, macro) 1513#define LOOP_UNROLLING_116(idx, step, macro) LOOP_UNROLLING_115(idx, step, macro); UNROLL_INCR(idx, step, macro) 1514#define LOOP_UNROLLING_117(idx, step, macro) LOOP_UNROLLING_116(idx, step, macro); UNROLL_INCR(idx, step, macro) 1515#define LOOP_UNROLLING_118(idx, step, macro) LOOP_UNROLLING_117(idx, step, macro); UNROLL_INCR(idx, step, macro) 1516#define LOOP_UNROLLING_119(idx, step, macro) LOOP_UNROLLING_118(idx, step, macro); UNROLL_INCR(idx, step, macro) 1517#define LOOP_UNROLLING_120(idx, step, macro) LOOP_UNROLLING_119(idx, step, macro); UNROLL_INCR(idx, step, macro) 1518#define LOOP_UNROLLING_121(idx, step, macro) LOOP_UNROLLING_120(idx, step, macro); UNROLL_INCR(idx, step, macro) 1519#define LOOP_UNROLLING_122(idx, step, macro) LOOP_UNROLLING_121(idx, step, macro); UNROLL_INCR(idx, step, macro) 1520#define LOOP_UNROLLING_123(idx, step, macro) LOOP_UNROLLING_122(idx, step, macro); UNROLL_INCR(idx, step, macro) 1521#define LOOP_UNROLLING_124(idx, step, macro) LOOP_UNROLLING_123(idx, step, macro); UNROLL_INCR(idx, step, macro) 1522#define LOOP_UNROLLING_125(idx, step, macro) LOOP_UNROLLING_124(idx, step, macro); UNROLL_INCR(idx, step, macro) 1523#define LOOP_UNROLLING_126(idx, step, macro) LOOP_UNROLLING_125(idx, step, macro); UNROLL_INCR(idx, step, macro) 1524#define LOOP_UNROLLING_127(idx, step, macro) LOOP_UNROLLING_126(idx, step, macro); UNROLL_INCR(idx, step, macro) 1525#define LOOP_UNROLLING_128(idx, step, macro) LOOP_UNROLLING_127(idx, step, macro); UNROLL_INCR(idx, step, macro) 1526 1527#define LOOP_UNROLLING_STR(type, idx, start, step, num, macro) \ 1528 { \ 1529 type idx = start; \ 1530 LOOP_UNROLLING_##num(idx, step, macro); \ 1531 } 1532#else 1533#define LOOP_UNROLLING_STR(type, idx, start, step, num, macro) \ 1534 { \ 1535 _Pragma("unroll") \ 1536 for(type idx = start; idx < (num * step); idx += step) \ 1537 { \ 1538 (macro); \ 1539 } \ 1540 } 1541#endif 1542#define LOOP_UNROLLING(type, idx, start, step, num, macro) LOOP_UNROLLING_STR(type, idx, start, step, num, macro) 1543 1544 1545#define GET_SPATIAL_IDX(IDX, N0, PARTIAL_N0) (max((int)(get_global_id(IDX) * N0 - (N0 - PARTIAL_N0) % N0), 0)) 1546 1547 1548#define DOT_PRODUCT_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, b, c) DOT_PRODUCT_INTEGER8_STR(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, b, c) 1549#define DOT_PRODUCT_INTEGER8_STR(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, b, c) DOT_PRODUCT##K0##_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) 1550#define DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1551 ({ \ 1552 c += (C_DATA_TYPE)(a) * (C_DATA_TYPE)(b); \ 1553 }) 1554#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_khr_integer_dot_product) 1555#define DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += dot((A_DATA_TYPE##4)((a).s01, (A_DATA_TYPE##2)(0)), (B_DATA_TYPE##4)(((b).s01), (B_DATA_TYPE##2)(0))); 1556#define DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += dot((A_DATA_TYPE##4)((a).s012, (A_DATA_TYPE)0), (B_DATA_TYPE##4)(((b).s012), (B_DATA_TYPE)0)); 1557#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += dot((a), (b)); 1558#elif defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) 1559#define DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c = arm_dot_acc((A_DATA_TYPE##4)((a).s01, (A_DATA_TYPE##2)(0)), (B_DATA_TYPE##4)(((b).s01), (B_DATA_TYPE##2)(0)), (c)); 1560#define DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c = arm_dot_acc((A_DATA_TYPE##4)((a).s012, (A_DATA_TYPE)0), (B_DATA_TYPE##4)(((b).s012), (B_DATA_TYPE)0), (c)); 1561#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c = arm_dot_acc((a), (b), (c)); 1562#elif defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) 1563#define DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += arm_dot((A_DATA_TYPE##4)((a).s01, (A_DATA_TYPE##2)(0)), (B_DATA_TYPE##4)(((b).s01), (B_DATA_TYPE##2)(0))); 1564#define DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += arm_dot((A_DATA_TYPE##4)((a).s012, (A_DATA_TYPE)0), (B_DATA_TYPE##4)(((b).s012), (B_DATA_TYPE)0)); 1565#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += arm_dot((a), (b)); 1566#else 1567#define DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1568 ({ \ 1569 c += (C_DATA_TYPE)(a).s0 * (C_DATA_TYPE)(b).s0; \ 1570 c += (C_DATA_TYPE)(a).s1 * (C_DATA_TYPE)(b).s1; \ 1571 }) 1572#define DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1573 ({ \ 1574 DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c); \ 1575 c += (C_DATA_TYPE)(a).s2 * (C_DATA_TYPE)(b).s2; \ 1576 }) 1577#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, x, y, val) \ 1578 ({ \ 1579 val += (C_DATA_TYPE)(x).s0 * (C_DATA_TYPE)(y).s0; \ 1580 val += (C_DATA_TYPE)(x).s1 * (C_DATA_TYPE)(y).s1; \ 1581 val += (C_DATA_TYPE)(x).s2 * (C_DATA_TYPE)(y).s2; \ 1582 val += (C_DATA_TYPE)(x).s3 * (C_DATA_TYPE)(y).s3; \ 1583 }) 1584#endif 1585#define DOT_PRODUCT5_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1586 ({ \ 1587 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 1588 DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s4), ((b).s4), c); \ 1589 }) 1590#define DOT_PRODUCT6_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1591 ({ \ 1592 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 1593 DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s45), ((b).s45), c); \ 1594 }) 1595#define DOT_PRODUCT7_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1596 ({ \ 1597 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 1598 DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s456), ((b).s456), c); \ 1599 }) 1600#define DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1601 ({ \ 1602 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).lo), ((b).lo), c); \ 1603 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).hi), ((b).hi), c); \ 1604 }) 1605#define DOT_PRODUCT9_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1606 ({ \ 1607 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1608 DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s8), ((b).s8), c); \ 1609 }) 1610#define DOT_PRODUCT10_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1611 ({ \ 1612 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1613 DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89), ((b).s89), c); \ 1614 }) 1615#define DOT_PRODUCT11_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1616 ({ \ 1617 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1618 DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89A), ((b).s89A), c); \ 1619 }) 1620#define DOT_PRODUCT12_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1621 ({ \ 1622 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1623 DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89AB), ((b).s89AB), c); \ 1624 }) 1625#define DOT_PRODUCT13_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1626 ({ \ 1627 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1628 DOT_PRODUCT5_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABC), ((b).s89ABC), c); \ 1629 }) 1630#define DOT_PRODUCT14_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1631 ({ \ 1632 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1633 DOT_PRODUCT6_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABCD), ((b).s89ABCD), c); \ 1634 }) 1635#define DOT_PRODUCT15_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1636 ({ \ 1637 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 1638 DOT_PRODUCT7_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABCDE), ((b).s89ABCDE), c); \ 1639 }) 1640#define DOT_PRODUCT16_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 1641 ({ \ 1642 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).lo), ((b).lo), c); \ 1643 DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).hi), ((b).hi), c); \ 1644 }) 1645 1646 1647#define REDUCE_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, c) REDUCE_INTEGER8_STR(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, c) 1648#define REDUCE_INTEGER8_STR(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, c) DOT_PRODUCT_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, K0, a, (TILE_VECTOR_TYPE##K0(B_DATA_TYPE))1, c) 1649 1650 1651#define V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y) V_LOAD_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y) 1652#define V_LOAD_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y) V_LOAD_##TENSOR_TYPE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) 1653#define V_LOAD_BUFFER(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) \ 1654 VLOAD(WIDTH) \ 1655 (0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (Y) * (STRIDE_Y))) 1656#define V_LOAD_IMAGE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) READ_IMAGE2D(DATA_TYPE, CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(WIDTH), TENSOR##_img, (X) / 4, (Y)) 1657 1658 1659#define V_STORE(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y, VALUES) V_STORE_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y, VALUES) 1660#define V_STORE_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y, VALUES) V_STORE_##TENSOR_TYPE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y, VALUES) 1661#define V_STORE_BUFFER(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y, VALUES) \ 1662 VSTORE(WIDTH) \ 1663 (VALUES, 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (Y) * (STRIDE_Y))) 1664#define V_STORE_IMAGE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y, VALUES) WRITE_IMAGE2D(DATA_TYPE, CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(WIDTH), TENSOR##_img, (X) / 4, (Y), VALUES) 1665 1666 1667#define T_LOAD(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, Y, YI_MULTIPLIER, STRIDE_Y, dst) \ 1668 ({ \ 1669 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1670 { \ 1671 dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, ((Y) + _i * (int)(YI_MULTIPLIER)), STRIDE_Y); \ 1672 }) \ 1673 }) 1674 1675 1676#define T_LOAD_INDIRECT(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, STRIDE_Y, indirect_y, dst) \ 1677 ({ \ 1678 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1679 { \ 1680 dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, (indirect_y[_i].v), STRIDE_Y); \ 1681 }) \ 1682 }) 1683 1684 1685#define T_LOAD_INDIRECT_WIDTH_SELECT(DATA_TYPE, HEIGHT, WIDTH0, WIDTH1, TENSOR_TYPE, TENSOR, X, STRIDE_Y, WIDTH1_CONDITION, dst, indirect_y) \ 1686 ({ \ 1687 if(WIDTH1_CONDITION) \ 1688 { \ 1689 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1690 { \ 1691 VLOAD_PARTIAL(WIDTH0, WIDTH1) \ 1692 (dst[HEIGHT - 1 - _i].v, 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (indirect_y[HEIGHT - 1 - _i].v) * STRIDE_Y)); \ 1693 }) \ 1694 } \ 1695 else \ 1696 { \ 1697 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1698 { \ 1699 dst[HEIGHT - 1 - _i].v = V_LOAD(DATA_TYPE, WIDTH0, TENSOR_TYPE, TENSOR, X, (indirect_y[HEIGHT - 1 - _i].v), STRIDE_Y); \ 1700 }) \ 1701 } \ 1702 }) 1703 1704#define T_LOAD_NHWC(DATA_TYPE, TILE_HEIGHT, TILE_WIDTH, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, STRIDE_Y, dst) \ 1705 ({ \ 1706 LOOP_UNROLLING(int, _yk, 0, 1, TILE_HEIGHT, \ 1707 { \ 1708 LOOP_UNROLLING(int, _xk, 0, 1, TILE_WIDTH, \ 1709 { \ 1710 int _src_y = (X) + _xk + ((Y) + _yk) * (TENSOR_WIDTH); \ 1711 _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \ 1712 int _src_valid_y = (((X) + _xk) >= 0 && ((X) + _xk) < (int)(TENSOR_WIDTH) && ((Y) + _yk) >= 0 && ((Y) + _yk) < (int)(TENSOR_HEIGHT)); \ 1713 if(_src_valid_y != 0) \ 1714 { \ 1715 dst[_xk + _yk * (TILE_WIDTH)].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 1716 } \ 1717 }) \ 1718 }) \ 1719 }) 1720 1721 1722#define T_LOAD_NHWC_WITH_DILATION(DATA_TYPE, TILE_HEIGHT, TILE_WIDTH, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, DILATION_X, DILATION_Y, BOUNDARY_CHECK, dst) \ 1723 ({ \ 1724 LOOP_UNROLLING(int, _yk, 0, 1, TILE_HEIGHT, \ 1725 { \ 1726 LOOP_UNROLLING(int, _xk, 0, 1, TILE_WIDTH, \ 1727 { \ 1728 int _src_y = (X) + _xk * (DILATION_X); \ 1729 int _src_z = ((Y) + _yk * (DILATION_Y)); \ 1730 int _src_w = (B); \ 1731 bool _src_valid_y = (((X) + _xk * (DILATION_X)) >= 0) && (((X) + _xk * (DILATION_X)) < (int)(TENSOR_WIDTH)) && (((Y) + _yk * (DILATION_Y)) >= 0) && (((Y) + _yk * (DILATION_Y)) < (int)(TENSOR_HEIGHT)); \ 1732 if(!(BOUNDARY_CHECK)) \ 1733 { \ 1734 dst[_xk + _yk * (TILE_WIDTH)].v = VLOAD(TILE_CHANNELS) \ 1735 (0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (C) * sizeof(DATA_TYPE) + (_src_y) * (TENSOR##_stride_y) + (_src_z) * (TENSOR##_stride_z) + (_src_w) * (TENSOR##_stride_w))); \ 1736 } \ 1737 else \ 1738 { \ 1739 if(_src_valid_y) \ 1740 { \ 1741 dst[_xk + _yk * (TILE_WIDTH)].v = VLOAD(TILE_CHANNELS) \ 1742 (0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (C) * sizeof(DATA_TYPE) + (_src_y) * (TENSOR##_stride_y) + (_src_z) * (TENSOR##_stride_z) + (_src_w) * (TENSOR##_stride_w))); \ 1743 } \ 1744 } \ 1745 }) \ 1746 }) \ 1747 }) 1748 1749 1750#define T_LOAD_NHWC_INDIRECT(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, STRIDE_Y, xi, yi, dst) \ 1751 ({ \ 1752 LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 1753 { \ 1754 int _src_y = (X) + xi[_i].v + ((Y) + yi[_i].v) * (TENSOR_WIDTH); \ 1755 _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \ 1756 int _src_valid_y = (((X) + xi[_i].v) >= 0 && ((X) + xi[_i].v) < (int)(TENSOR_WIDTH) && ((Y) + yi[_i].v) >= 0 && ((Y) + yi[_i].v) < (int)(TENSOR_HEIGHT)); \ 1757 if(_src_valid_y != 0) \ 1758 { \ 1759 dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 1760 } \ 1761 }) \ 1762 }) 1763 1764 1765#define T_LOAD2D_INDIRECT(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) T_LOAD2D_INDIRECT_STR(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) 1766#define T_LOAD2D_INDIRECT_STR(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) T_LOAD2D_INDIRECT_##TENSOR_TYPE(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) 1767#define T_LOAD2D_INDIRECT_BUFFER(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) \ 1768 ({ \ 1769 LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 1770 { \ 1771 if(yi[0].s[_i] >= 0) \ 1772 { \ 1773 dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, yi[0].s[_i], STRIDE_Y); \ 1774 } \ 1775 }) \ 1776 }) 1777 1778#define T_LOAD2D_INDIRECT_IMAGE(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) \ 1779 ({ \ 1780 LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 1781 { \ 1782 dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, yi[0].s[_i], STRIDE_Y); \ 1783 }) \ 1784 }) 1785 1786 1787#define T_LOAD_NDHWC_INDIRECT(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Z, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, TENSOR_DEPTH, STRIDE_Y, xi, yi, zi, dst) \ 1788 ({ \ 1789 LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 1790 { \ 1791 int _src_y = (X) + xi[_i].v + ((Y) + yi[_i].v) * (TENSOR_WIDTH) + ((Z) + zi[_i].v) * (TENSOR_WIDTH * TENSOR_HEIGHT); \ 1792 _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT) * (int)(TENSOR_DEPTH); \ 1793 int _src_valid_y = (((X) + xi[_i].v) >= 0 && ((X) + xi[_i].v) < (int)(TENSOR_WIDTH) && ((Y) + yi[_i].v) >= 0 && ((Y) + yi[_i].v) < (int)(TENSOR_HEIGHT) \ 1794 && ((Z) + zi[_i].v) >= 0 && ((Z) + zi[_i].v) < (int)(TENSOR_DEPTH)); \ 1795 if(_src_valid_y != 0) \ 1796 { \ 1797 dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 1798 } \ 1799 }) \ 1800 }) 1801 1802 1803#define T_STORE_INDIRECT_WIDTH_SELECT(DATA_TYPE, HEIGHT, WIDTH0, WIDTH1, TENSOR_TYPE, TENSOR, X, STRIDE_Y, WIDTH1_CONDITION, src, indirect_y) \ 1804 ({ \ 1805 if(WIDTH1_CONDITION) \ 1806 { \ 1807 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1808 { \ 1809 VSTORE_PARTIAL(WIDTH0, WIDTH1) \ 1810 (CONVERT(src[HEIGHT - 1 - _i].v, VEC_DATA_TYPE(DATA_TYPE, WIDTH0)), 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (indirect_y[HEIGHT - 1 - _i].v) * STRIDE_Y)); \ 1811 }) \ 1812 } \ 1813 else \ 1814 { \ 1815 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 1816 { \ 1817 VSTORE(WIDTH0) \ 1818 (CONVERT(src[HEIGHT - 1 - _i].v, VEC_DATA_TYPE(DATA_TYPE, WIDTH0)), 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (indirect_y[HEIGHT - 1 - _i].v) * STRIDE_Y)); \ 1819 }) \ 1820 } \ 1821 }) 1822 1823 1824#define T_OFFSET_CORRECTION(ACC_DATA_TYPE, M0, N0, K0, SRC_OFFSET, WEI_OFFSET, lhs, rhs, dst) \ 1825 ({ \ 1826 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1827 { \ 1828 ACC_DATA_TYPE _tm = 0; \ 1829 LOOP_UNROLLING(int, _k0, 0, 1, K0, \ 1830 { \ 1831 _tm += ((ACC_DATA_TYPE)lhs[_m0].s[_k0] * (ACC_DATA_TYPE)WEI_OFFSET); \ 1832 }) \ 1833 LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 1834 { \ 1835 dst[_m0].s[_n0] += _tm; \ 1836 LOOP_UNROLLING(int, _k0, 0, 1, K0, \ 1837 { \ 1838 dst[_m0].s[_n0] += ((ACC_DATA_TYPE)rhs[_n0].s[_k0] * (ACC_DATA_TYPE)SRC_OFFSET); \ 1839 }) \ 1840 }) \ 1841 }) \ 1842 }) 1843 1844 1845#define T_QUANTIZE8(SRC_DATA_TYPE, DST_DATA_TYPE, QUANTIZATION_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) T_QUANTIZE8_STR(SRC_DATA_TYPE, DST_DATA_TYPE, QUANTIZATION_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) 1846#define T_QUANTIZE8_STR(SRC_DATA_TYPE, DST_DATA_TYPE, QUANTIZATION_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) T_QUANTIZE8_##QUANTIZATION_TYPE(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) 1847 1848 1849#define T_QUANTIZE8_PER_TENSOR(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) \ 1850 ({ \ 1851 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1852 { \ 1853 LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 1854 { \ 1855 SRC_DATA_TYPE _tmp = 0; \ 1856 SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 1857 _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-DST_SHIFT)), ((SRC_DATA_TYPE)DST_SHIFT < (SRC_DATA_TYPE)0)); \ 1858 SRC_DATA_TYPE overflow = _src == DST_MULTIPLIER && _src == INT_MIN; \ 1859 long a_64 = (long)(_src); \ 1860 long b_64 = (long)(DST_MULTIPLIER); \ 1861 long ab_64 = a_64 * b_64; \ 1862 long mask1 = 1 << 30; \ 1863 long mask2 = 1 - (1 << 30); \ 1864 long is_positive_or_zero = ab_64 >= 0; \ 1865 long nudge = select(mask2, mask1, is_positive_or_zero); \ 1866 SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 1867 _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 1868 if(DST_SHIFT >= 0) \ 1869 { \ 1870 long mask = ((((int)1) << DST_SHIFT) - (long)1); \ 1871 long threshold = _tmp < (int)0 ? (mask >> 1) + (long)1 : (mask >> 1) + 0; \ 1872 _tmp = (_tmp & mask) > threshold ? (_tmp >> DST_SHIFT) + (int)1 : (_tmp >> DST_SHIFT); \ 1873 } \ 1874 _tmp += DST_OFFSET; \ 1875 dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 1876 }) \ 1877 }) \ 1878 }) 1879 1880 1881#define T_QUANTIZE8_PER_CHANNEL(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst_multipliers, dst_shifts, dst) \ 1882 ({ \ 1883 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1884 { \ 1885 LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 1886 { \ 1887 SRC_DATA_TYPE _tmp = 0; \ 1888 SRC_DATA_TYPE _tmp2 = 0; \ 1889 SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 1890 SRC_DATA_TYPE _dst_multiplier = dst_multipliers[0].s[_n0]; \ 1891 SRC_DATA_TYPE _dst_shift = dst_shifts[0].s[_n0]; \ 1892 _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-_dst_shift)), ((SRC_DATA_TYPE)_dst_shift < (SRC_DATA_TYPE)0)); \ 1893 SRC_DATA_TYPE overflow = _src == _dst_multiplier && _src == INT_MIN; \ 1894 long a_64 = (long)(_src); \ 1895 long b_64 = (long)(_dst_multiplier); \ 1896 long ab_64 = a_64 * b_64; \ 1897 long mask1 = 1 << 30; \ 1898 long mask2 = 1 - (1 << 30); \ 1899 long is_positive_or_zero = ab_64 >= 0; \ 1900 long nudge = select(mask2, mask1, is_positive_or_zero); \ 1901 SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 1902 _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 1903 long mask = ((((int)1) << _dst_shift) - (int)1); \ 1904 long threshold = (mask >> 1) + any(_tmp); \ 1905 _tmp2 = _tmp >> _dst_shift; \ 1906 _tmp2 += select(0, 1, (_tmp & mask) > threshold); \ 1907 _tmp = select(_tmp, _tmp2, _dst_shift >= 0); \ 1908 _tmp += DST_OFFSET; \ 1909 dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 1910 }) \ 1911 }) \ 1912 }) 1913 1914 1915#define T_QUANTIZE8_ASYMMETRIC(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst) \ 1916 ({ \ 1917 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1918 { \ 1919 LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 1920 { \ 1921 SRC_DATA_TYPE _tmp = 0; \ 1922 SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 1923 _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-DST_SHIFT)), ((SRC_DATA_TYPE)DST_SHIFT < (SRC_DATA_TYPE)0)); \ 1924 SRC_DATA_TYPE overflow = _src == DST_MULTIPLIER && _src == INT_MIN; \ 1925 long a_64 = (long)(_src); \ 1926 long b_64 = (long)(DST_MULTIPLIER); \ 1927 long ab_64 = a_64 * b_64; \ 1928 long mask1 = 1 << 30; \ 1929 long mask2 = 1 - (1 << 30); \ 1930 long is_positive_or_zero = ab_64 >= 0; \ 1931 long nudge = select(mask2, mask1, is_positive_or_zero); \ 1932 SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 1933 _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 1934 if(DST_SHIFT >= 0) \ 1935 { \ 1936 long mask = ((((int)1) << DST_SHIFT) - (int)1); \ 1937 long threshold = _tmp < (int)0 ? (mask >> 1) + (long)1 : (mask >> 1) + 0; \ 1938 _tmp = (_tmp & mask) > threshold ? (_tmp >> DST_SHIFT) + (int)1 : (_tmp >> DST_SHIFT); \ 1939 } \ 1940 _tmp += DST_OFFSET; \ 1941 dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 1942 }) \ 1943 }) \ 1944 }) 1945 1946 1947#define T_ROWSET_MASK(DATA_TYPE, M0, N0, VALUE_TO_SET, a, mask) \ 1948 ({ \ 1949 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1950 { \ 1951 LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 1952 { \ 1953 a[_m0].s[_n0] = select((DATA_TYPE)(a[_m0].s[_n0]), (DATA_TYPE)(VALUE_TO_SET), (SELECT_DATA_TYPE(DATA_TYPE))(mask[_m0].v == (DATA_TYPE)0)); \ 1954 }) \ 1955 }) \ 1956 }) 1957 1958 1959#define T_ACTIVATION(DATA_TYPE, M0, N0, ACTIVATION_TYPE, A_VAL, B_VAL, src, dst) \ 1960 ({ \ 1961 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1962 { \ 1963 dst[_m0].v = ACTIVATION(ACTIVATION_TYPE, DATA_TYPE, N0, src[_m0].v, A_VAL, B_VAL); \ 1964 }) \ 1965 }) 1966 1967 1968#define relu_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (max((DATA_TYPE)ZERO_VALUE, x)) 1969 1970#define brelu_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (min((DATA_TYPE)A_VAL, max((DATA_TYPE)ZERO_VALUE, x))) 1971 1972#define lu_brelu_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (min(max(x, (DATA_TYPE)B_VAL), (DATA_TYPE)A_VAL)) 1973 1974#define hard_swish_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (x * ((min(max((DATA_TYPE)(x + (DATA_TYPE)3.f), (DATA_TYPE)0.f), (DATA_TYPE)6.f)) * (DATA_TYPE)0.166666667f)) 1975 1976#define identity_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (x) 1977 1978#define ACT_OP_QUANTIZED(op, DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) op##_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) 1979#define ACTIVATION_QUANTIZED(op, DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) ACT_OP_QUANTIZED(op, DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) 1980 1981#define V_ADD(A_VAL, B_VAL) ((A_VAL) + (B_VAL)) 1982#define V_SUB(A_VAL, B_VAL) ((A_VAL) - (B_VAL)) 1983#define V_DIV(A_VAL, B_VAL) ((A_VAL) / (B_VAL)) 1984#define V_MUL(A_VAL, B_VAL) ((A_VAL) * (B_VAL)) 1985 1986 1987#define T_ACTIVATION_QUANTIZED(DATA_TYPE, M0, N0, ACTIVATION_TYPE, ZERO_VALUE, A_VAL, B_VAL, src, dst) \ 1988 ({ \ 1989 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1990 { \ 1991 dst[_m0].v = ACTIVATION_QUANTIZED(ACTIVATION_TYPE, DATA_TYPE, N0, ZERO_VALUE, A_VAL, B_VAL, src[_m0].v); \ 1992 }) \ 1993 }) 1994 1995 1996#define T_ADD(DATA_TYPE, M0, N0, lhs, rhs, dst) \ 1997 ({ \ 1998 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 1999 { \ 2000 dst[_m0].v = lhs[_m0].v + rhs[_m0].v; \ 2001 }) \ 2002 }) 2003 2004 2005#define T_ADD_CONSTANT(DATA_TYPE, M0, N0, lhs, rhs_constant, dst) \ 2006 ({ \ 2007 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2008 { \ 2009 dst[_m0].v = lhs[_m0].v + (DATA_TYPE)rhs_constant; \ 2010 }) \ 2011 }) 2012 2013#define T_ELTWISE_BROADCAST_ADD_X(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_X(V_ADD, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2014#define T_ELTWISE_BROADCAST_LHS_X_ADD(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_LHS_X(V_ADD, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2015#define T_ELTWISE_BROADCAST_RHS_X_ADD(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_X(V_ADD, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2016 2017#define T_ELTWISE_BROADCAST_LHS_X_SUB(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_LHS_X(V_SUB, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2018#define T_ELTWISE_BROADCAST_RHS_X_SUB(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_X(V_SUB, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2019 2020#define T_ELTWISE_BROADCAST_DIV_X(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_X(V_DIV, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2021 2022#define T_ELTWISE_BROADCAST_LHS_X_MUL(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_LHS_X(V_MUL, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2023#define T_ELTWISE_BROADCAST_RHS_X_MUL(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE_BROADCAST_X(V_MUL, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2024 2025 2026#define T_SCALE_CONSTANT(DATA_TYPE, M0, N0, lhs, rhs_constant, dst) \ 2027 ({ \ 2028 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2029 { \ 2030 dst[_m0].v = lhs[_m0].v * (DATA_TYPE)rhs_constant; \ 2031 }) \ 2032 }) 2033 2034 2035#define T_ELTWISE_BROADCAST_X(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 2036 ({ \ 2037 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2038 { \ 2039 dst[_m0].v = T_ELWISE_OP(CONVERT(lhs[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0)), CONVERT(rhs[0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0))); \ 2040 }) \ 2041 }) 2042 2043 2044#define T_ELTWISE_BROADCAST_LHS_X(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 2045 ({ \ 2046 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2047 { \ 2048 dst[_m0].v = T_ELWISE_OP(CONVERT(lhs[0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0)), CONVERT(rhs[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0))); \ 2049 }) \ 2050 }) 2051 2052#define T_ELTWISE_ADD(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_ADD, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2053#define T_ELTWISE_SUB(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_SUB, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2054#define T_ELTWISE_DIV(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_DIV, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2055#define T_ELTWISE_MUL(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_MUL, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 2056 2057 2058#define T_ELTWISE(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 2059 ({ \ 2060 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2061 { \ 2062 dst[_m0].v = T_ELWISE_OP(CONVERT(lhs[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0)), CONVERT(rhs[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0))); \ 2063 }) \ 2064 }) 2065 2066 2067#define T_FLOOR(DST_DATA_TYPE, M0, N0, src, dst) \ 2068 ({ \ 2069 LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 2070 { \ 2071 dst[_m0].v = floor(CONVERT(src[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0))); \ 2072 }) \ 2073 }) 2074 2075 2076#define T_MMUL(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, LHS_LAYOUT, RHS_LAYOUT, lhs, rhs, dst) T_MMUL_##LHS_LAYOUT##_##RHS_LAYOUT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2077#define T_MMUL_NT_T(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_##LHS_DATA_TYPE##_##RHS_DATA_TYPE##_##DST_DATA_TYPE(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2078#define T_MMUL_NT_T_float_float_float(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_FLOAT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2079#define T_MMUL_NT_T_half_half_float(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_FLOAT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2080#define T_MMUL_NT_T_half_half_half(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_FLOAT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2081#define T_MMUL_NT_T_char_char_int(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2082#define T_MMUL_NT_T_uchar_uchar_uint(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2083#define T_MMUL_NT_T_uchar_uchar_int(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) 2084#define T_MMUL_NT_T_FLOAT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \ 2085 { \ 2086 LOOP_UNROLLING(int, _m, 0, 1, M0, \ 2087 { \ 2088 LOOP_UNROLLING(int, _n, 0, 1, N0, \ 2089 { \ 2090 LOOP_UNROLLING(int, _k, 0, 1, K0, \ 2091 { \ 2092 dst[_m].s[_n] = fma((DST_DATA_TYPE)(lhs[_m].s[_k]), (DST_DATA_TYPE)(rhs[_n].s[_k]), dst[_m].s[_n]); \ 2093 }) \ 2094 }) \ 2095 }) \ 2096 } 2097 2098#define T_MMUL_NT_T_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \ 2099 ({ \ 2100 LOOP_UNROLLING(int, _m, 0, 1, M0, \ 2101 { \ 2102 LOOP_UNROLLING(int, _n, 0, 1, N0, \ 2103 { \ 2104 DOT_PRODUCT_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, K0, (lhs[_m].v), (rhs[_n].v), dst[_m].s[_n]); \ 2105 }) \ 2106 }) \ 2107 }) 2108 2109#endif 2110 2111#if defined(POOL_AVG) || defined(POOL_L2) 2112#define POOL_OP(x, y) ((x) + (y)) 2113#else 2114#define POOL_OP(x, y) (fmax((x), (y))) 2115#endif 2116 2117#define SQRT_OP(x) sqrt((x)) 2118 2119#if defined(VEC_SIZE) && defined(VEC_SIZE_LEFTOVER) && defined(SRC_WIDTH) && defined(SRC_HEIGHT) && defined(SRC_DEPTH) && defined(DST_CHANNELS) && defined(DST_HEIGHT) && defined(DST_DEPTH) && defined(DST_BATCH_SIZE) && defined(ACC_DATA_TYPE) 2120 2121#if defined(POOL_SIZE_X) && defined(POOL_SIZE_Y) && defined(POOL_SIZE_Z) 2122 2123 2124__kernel void pooling_3d_layer_MxN_ndhwc( 2125 TENSOR5D_DECLARATION(input), 2126 TENSOR5D_DECLARATION(output)) 2127{ 2128 2129 2130 int idx_out_c = GET_SPATIAL_IDX(0, VEC_SIZE, VEC_SIZE_LEFTOVER); 2131 int idx_out_w = GET_SPATIAL_IDX(1, 1, 0); 2132 2133 2134 int idx_out_h = GET_SPATIAL_IDX(2, 1, 0) % DST_HEIGHT; 2135 int idx_out_d = (GET_SPATIAL_IDX(2, 1, 0) / DST_HEIGHT) % DST_DEPTH; 2136 int idx_out_n = (GET_SPATIAL_IDX(2, 1, 0) / DST_HEIGHT) / DST_DEPTH; 2137 2138 __global unsigned char *in_base_ptr = input_ptr + input_offset_first_element_in_bytes + idx_out_c * sizeof(DATA_TYPE) + idx_out_n * input_stride_v; 2139 2140 __global unsigned char *out_base_ptr = output_ptr + output_offset_first_element_in_bytes + idx_out_c * sizeof(DATA_TYPE) + idx_out_w * output_stride_y + idx_out_h * output_stride_z + idx_out_d * 2141 output_stride_w + idx_out_n * output_stride_v; 2142 2143 VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 2144 res0 = INITIAL_VALUE; 2145 2146 int idx_in_w = idx_out_w * STRIDE_X - (int)PAD_X; 2147 int idx_in_h = idx_out_h * STRIDE_Y - (int)PAD_Y; 2148 int idx_in_d = idx_out_d * STRIDE_Z - (int)PAD_Z; 2149 2150 2151 int pool_x_s = max((int)0, -idx_in_w); 2152 2153 int pool_x_e = min((int)POOL_SIZE_X, (int)SRC_WIDTH + PAD_X - idx_in_w); 2154 int pool_y_s = max((int)0, -idx_in_h); 2155 int pool_y_e = min((int)POOL_SIZE_Y, (int)SRC_HEIGHT + PAD_Y - idx_in_h); 2156 int pool_z_s = max((int)0, -idx_in_d); 2157 int pool_z_e = min((int)POOL_SIZE_Z, (int)SRC_DEPTH + PAD_Z - idx_in_d); 2158 2159 2160 int filter_size = pool_z_e * pool_y_e * pool_x_e; 2161 2162 2163 pool_x_e = min(pool_x_e, SRC_WIDTH - idx_in_w); 2164 pool_y_e = min(pool_y_e, SRC_HEIGHT - idx_in_h); 2165 pool_z_e = min(pool_z_e, SRC_DEPTH - idx_in_d); 2166 2167#if defined(EXCLUDE_PADDING) 2168 filter_size = (pool_z_e - pool_z_s) * (pool_y_e - pool_y_s) * (pool_x_e - pool_x_s); 2169#endif 2170 2171#if POOL_SIZE_X == SRC_WIDTH && POOL_SIZE_Y == SRC_HEIGHT && POOL_SIZE_Z == SRC_DEPTH && PAD_X == 0 && PAD_Y == 0 && PAD_Z == 0 2172 2173 for(int z = 0; z < POOL_SIZE_Z; ++z) 2174 { 2175 int depth_offset_src = (z + idx_in_d) * input_stride_w; 2176 for(int y = 0; y < POOL_SIZE_Y; ++y) 2177 { 2178 int height_offset_src = (y + idx_in_h) * input_stride_z; 2179#pragma unroll 8 2180 for(int x = 0; x < POOL_SIZE_X; ++x) 2181 { 2182 int width_offset_src = (x + idx_in_w) * input_stride_y; 2183#else 2184 for(int z = pool_z_s; z < pool_z_e; ++z) 2185 { 2186 int depth_offset_src = (z + idx_in_d) * input_stride_w; 2187 for(int y = pool_y_s; y < pool_y_e; ++y) 2188 { 2189 int height_offset_src = (y + idx_in_h) * input_stride_z; 2190#pragma unroll 8 2191 for(int x = pool_x_s; x < pool_x_e; ++x) 2192 { 2193 int width_offset_src = (x + idx_in_w) * input_stride_y; 2194#endif 2195 VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 2196 data0; 2197#if defined(FP_MIXED_PRECISION) 2198 2199 data0 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + width_offset_src + height_offset_src + depth_offset_src)), 2200 VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 2201#else 2202 data0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + width_offset_src + height_offset_src + depth_offset_src)); 2203#endif 2204 2205#if defined(POOL_L2) 2206 2207 data0 *= data0; 2208#endif 2209 res0 = POOL_OP(res0, data0); 2210 } 2211 } 2212 } 2213 2214#if defined(POOL_AVG) || defined(POOL_L2) 2215 res0 /= (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))filter_size; 2216#endif 2217 2218#if defined(POOL_L2) 2219 2220 res0 = SQRT_OP(res0); 2221#endif 2222 2223 VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) 2224 out_q0 = CONVERT(res0, VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)); 2225 2226 2227 2228 2229#if defined(QUANTIZED) 2230 STORE_VECTOR_SELECT(out_q, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 2231#elif defined(FP_MIXED_PRECISION) 2232 VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) 2233 res_converted0 = CONVERT(res0, VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)); 2234 STORE_VECTOR_SELECT(res_converted, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 2235#else 2236 STORE_VECTOR_SELECT(res, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 2237#endif 2238} 2239#endif 2240#endif )"