1*c217d954SCole FaustR"( 2*c217d954SCole Faust 3*c217d954SCole Faust#ifndef ARM_COMPUTE_HELPER_H 4*c217d954SCole Faust#define ARM_COMPUTE_HELPER_H 5*c217d954SCole Faust 6*c217d954SCole Faust 7*c217d954SCole Faust 8*c217d954SCole Faust 9*c217d954SCole Faust#define STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 10*c217d954SCole Faust VSTORE(N0) \ 11*c217d954SCole Faust (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 12*c217d954SCole Faust 13*c217d954SCole Faust#define STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 14*c217d954SCole Faust STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 15*c217d954SCole Faust VSTORE(N0) \ 16*c217d954SCole Faust (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 17*c217d954SCole Faust 18*c217d954SCole Faust#define STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 19*c217d954SCole Faust STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 20*c217d954SCole Faust VSTORE(N0) \ 21*c217d954SCole Faust (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 22*c217d954SCole Faust 23*c217d954SCole Faust#define STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 24*c217d954SCole Faust STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 25*c217d954SCole Faust VSTORE(N0) \ 26*c217d954SCole Faust (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 27*c217d954SCole Faust 28*c217d954SCole Faust#define STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 29*c217d954SCole Faust STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 30*c217d954SCole Faust VSTORE(N0) \ 31*c217d954SCole Faust (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 32*c217d954SCole Faust 33*c217d954SCole Faust#define STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 34*c217d954SCole Faust STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 35*c217d954SCole Faust VSTORE(N0) \ 36*c217d954SCole Faust (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 37*c217d954SCole Faust 38*c217d954SCole Faust#define STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 39*c217d954SCole Faust STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 40*c217d954SCole Faust VSTORE(N0) \ 41*c217d954SCole Faust (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 42*c217d954SCole Faust 43*c217d954SCole Faust#define STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 44*c217d954SCole Faust STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 45*c217d954SCole Faust VSTORE(N0) \ 46*c217d954SCole Faust (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 47*c217d954SCole Faust 48*c217d954SCole Faust#define STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 49*c217d954SCole Faust STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 50*c217d954SCole Faust VSTORE(N0) \ 51*c217d954SCole Faust (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 52*c217d954SCole Faust 53*c217d954SCole Faust#define STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 54*c217d954SCole Faust STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 55*c217d954SCole Faust VSTORE(N0) \ 56*c217d954SCole Faust (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 57*c217d954SCole Faust 58*c217d954SCole Faust#define STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 59*c217d954SCole Faust STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 60*c217d954SCole Faust VSTORE(N0) \ 61*c217d954SCole Faust (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 62*c217d954SCole Faust 63*c217d954SCole Faust#define STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 64*c217d954SCole Faust STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 65*c217d954SCole Faust VSTORE(N0) \ 66*c217d954SCole Faust (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 67*c217d954SCole Faust 68*c217d954SCole Faust#define STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 69*c217d954SCole Faust STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 70*c217d954SCole Faust VSTORE(N0) \ 71*c217d954SCole Faust (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 72*c217d954SCole Faust 73*c217d954SCole Faust#define STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 74*c217d954SCole Faust STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 75*c217d954SCole Faust VSTORE(N0) \ 76*c217d954SCole Faust (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 77*c217d954SCole Faust 78*c217d954SCole Faust#define STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 79*c217d954SCole Faust STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 80*c217d954SCole Faust VSTORE(N0) \ 81*c217d954SCole Faust (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 82*c217d954SCole Faust 83*c217d954SCole Faust#define STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 84*c217d954SCole Faust STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 85*c217d954SCole Faust VSTORE(N0) \ 86*c217d954SCole Faust (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 87*c217d954SCole Faust 88*c217d954SCole Faust 89*c217d954SCole Faust 90*c217d954SCole Faust#define CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 91*c217d954SCole Faust VSTORE(N0) \ 92*c217d954SCole Faust (CONVERT_SAT((BASENAME##0), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 93*c217d954SCole Faust 94*c217d954SCole Faust#define CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 95*c217d954SCole Faust CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 96*c217d954SCole Faust VSTORE(N0) \ 97*c217d954SCole Faust (CONVERT_SAT((BASENAME##1), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 98*c217d954SCole Faust 99*c217d954SCole Faust#define CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 100*c217d954SCole Faust CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 101*c217d954SCole Faust VSTORE(N0) \ 102*c217d954SCole Faust (CONVERT_SAT((BASENAME##2), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 103*c217d954SCole Faust 104*c217d954SCole Faust#define CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 105*c217d954SCole Faust CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 106*c217d954SCole Faust VSTORE(N0) \ 107*c217d954SCole Faust (CONVERT_SAT((BASENAME##3), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 108*c217d954SCole Faust 109*c217d954SCole Faust#define CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 110*c217d954SCole Faust CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 111*c217d954SCole Faust VSTORE(N0) \ 112*c217d954SCole Faust (CONVERT_SAT((BASENAME##4), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 113*c217d954SCole Faust 114*c217d954SCole Faust#define CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 115*c217d954SCole Faust CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 116*c217d954SCole Faust VSTORE(N0) \ 117*c217d954SCole Faust (CONVERT_SAT((BASENAME##5), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 118*c217d954SCole Faust 119*c217d954SCole Faust#define CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 120*c217d954SCole Faust CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 121*c217d954SCole Faust VSTORE(N0) \ 122*c217d954SCole Faust (CONVERT_SAT((BASENAME##6), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 123*c217d954SCole Faust 124*c217d954SCole Faust#define CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 125*c217d954SCole Faust CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 126*c217d954SCole Faust VSTORE(N0) \ 127*c217d954SCole Faust (CONVERT_SAT((BASENAME##7), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 128*c217d954SCole Faust 129*c217d954SCole Faust#define CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 130*c217d954SCole Faust CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 131*c217d954SCole Faust VSTORE(N0) \ 132*c217d954SCole Faust (CONVERT_SAT((BASENAME##8), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 133*c217d954SCole Faust 134*c217d954SCole Faust#define CONVERT_STORE_ROW_10(N0, DATA, BASENAME, PTR, STRIDE_Y, Z) \ 135*c217d954SCole Faust CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 136*c217d954SCole Faust VSTORE(N0) \ 137*c217d954SCole Faust (CONVERT_SAT((BASENAME##9), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 138*c217d954SCole Faust 139*c217d954SCole Faust#define CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 140*c217d954SCole Faust CONVERT_STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 141*c217d954SCole Faust VSTORE(N0) \ 142*c217d954SCole Faust (CONVERT_SAT((BASENAME##A), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 143*c217d954SCole Faust 144*c217d954SCole Faust#define CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 145*c217d954SCole Faust CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 146*c217d954SCole Faust VSTORE(N0) \ 147*c217d954SCole Faust (CONVERT_SAT((BASENAME##B), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 148*c217d954SCole Faust 149*c217d954SCole Faust#define CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 150*c217d954SCole Faust CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 151*c217d954SCole Faust VSTORE(N0) \ 152*c217d954SCole Faust (CONVERT_SAT((BASENAME##C), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 153*c217d954SCole Faust 154*c217d954SCole Faust#define CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 155*c217d954SCole Faust CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 156*c217d954SCole Faust VSTORE(N0) \ 157*c217d954SCole Faust (CONVERT_SAT((BASENAME##D), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 158*c217d954SCole Faust 159*c217d954SCole Faust#define CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 160*c217d954SCole Faust CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 161*c217d954SCole Faust VSTORE(N0) \ 162*c217d954SCole Faust (CONVERT_SAT((BASENAME##E), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 163*c217d954SCole Faust 164*c217d954SCole Faust#define CONVERT_STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 165*c217d954SCole Faust CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 166*c217d954SCole Faust VSTORE(N0) \ 167*c217d954SCole Faust (CONVERT_SAT((BASENAME##F), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 168*c217d954SCole Faust 169*c217d954SCole Faust 170*c217d954SCole Faust 171*c217d954SCole Faust 172*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 175*c217d954SCole Faust 176*c217d954SCole Faust 177*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 180*c217d954SCole Faust 181*c217d954SCole Faust 182*c217d954SCole Faust#define STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 183*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 184*c217d954SCole Faust (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 185*c217d954SCole Faust 186*c217d954SCole Faust#define STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 187*c217d954SCole Faust STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 188*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 189*c217d954SCole Faust (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 190*c217d954SCole Faust 191*c217d954SCole Faust#define STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 192*c217d954SCole Faust STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 193*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 194*c217d954SCole Faust (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 195*c217d954SCole Faust 196*c217d954SCole Faust#define STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 197*c217d954SCole Faust STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 198*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 199*c217d954SCole Faust (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 200*c217d954SCole Faust 201*c217d954SCole Faust#define STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 202*c217d954SCole Faust STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 203*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 204*c217d954SCole Faust (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 205*c217d954SCole Faust 206*c217d954SCole Faust#define STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 207*c217d954SCole Faust STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 208*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 209*c217d954SCole Faust (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 210*c217d954SCole Faust 211*c217d954SCole Faust#define STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 212*c217d954SCole Faust STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 213*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 214*c217d954SCole Faust (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 215*c217d954SCole Faust 216*c217d954SCole Faust#define STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 217*c217d954SCole Faust STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 218*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 219*c217d954SCole Faust (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 220*c217d954SCole Faust 221*c217d954SCole Faust#define STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 222*c217d954SCole Faust STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 223*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 224*c217d954SCole Faust (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 225*c217d954SCole Faust 226*c217d954SCole Faust#define STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 227*c217d954SCole Faust STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 228*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 229*c217d954SCole Faust (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 230*c217d954SCole Faust 231*c217d954SCole Faust#define STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 232*c217d954SCole Faust STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 233*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 234*c217d954SCole Faust (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 235*c217d954SCole Faust 236*c217d954SCole Faust#define STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 237*c217d954SCole Faust STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 238*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 239*c217d954SCole Faust (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 240*c217d954SCole Faust 241*c217d954SCole Faust#define STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 242*c217d954SCole Faust STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 243*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 244*c217d954SCole Faust (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 245*c217d954SCole Faust 246*c217d954SCole Faust#define STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 247*c217d954SCole Faust STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 248*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 249*c217d954SCole Faust (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 250*c217d954SCole Faust 251*c217d954SCole Faust#define STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 252*c217d954SCole Faust STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 253*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 254*c217d954SCole Faust (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 255*c217d954SCole Faust 256*c217d954SCole Faust#define STORE_ROW_PARTIAL_16(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 257*c217d954SCole Faust STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 258*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 259*c217d954SCole Faust (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 260*c217d954SCole Faust 261*c217d954SCole Faust 262*c217d954SCole Faust 263*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 266*c217d954SCole Faust#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*c217d954SCole Faust if(!(PARTIAL_COND_X) && !(PARTIAL_COND_Y)) \ 268*c217d954SCole Faust { \ 269*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 270*c217d954SCole Faust } \ 271*c217d954SCole Faust else if((PARTIAL_COND_Y) && !(PARTIAL_COND_X)) \ 272*c217d954SCole Faust { \ 273*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 274*c217d954SCole Faust } \ 275*c217d954SCole Faust else if(!(PARTIAL_COND_Y) && (PARTIAL_COND_X)) \ 276*c217d954SCole Faust { \ 277*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 278*c217d954SCole Faust } \ 279*c217d954SCole Faust else \ 280*c217d954SCole Faust { \ 281*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 282*c217d954SCole Faust } 283*c217d954SCole Faust 284*c217d954SCole Faust#define STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) \ 285*c217d954SCole Faust if(!(PARTIAL_COND_X)) \ 286*c217d954SCole Faust { \ 287*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 288*c217d954SCole Faust } \ 289*c217d954SCole Faust else \ 290*c217d954SCole Faust { \ 291*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 292*c217d954SCole Faust } 293*c217d954SCole Faust 294*c217d954SCole Faust#define STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) \ 295*c217d954SCole Faust if(!(PARTIAL_COND_Y)) \ 296*c217d954SCole Faust { \ 297*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 298*c217d954SCole Faust } \ 299*c217d954SCole Faust else \ 300*c217d954SCole Faust { \ 301*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 302*c217d954SCole Faust } 303*c217d954SCole Faust 304*c217d954SCole Faust 305*c217d954SCole Faust#if defined(PARTIAL_STORE_M0) && defined(PARTIAL_STORE_N0) 306*c217d954SCole Faust 307*c217d954SCole Faust 308*c217d954SCole Faust#if PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 == 0 309*c217d954SCole Faust 310*c217d954SCole Faust#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*c217d954SCole Faust STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 312*c217d954SCole Faust 313*c217d954SCole Faust#elif PARTIAL_STORE_M0 > 0 && PARTIAL_STORE_N0 == 0 314*c217d954SCole Faust 315*c217d954SCole Faust#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*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) 317*c217d954SCole Faust 318*c217d954SCole Faust#elif PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 > 0 319*c217d954SCole Faust 320*c217d954SCole Faust#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*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) 322*c217d954SCole Faust 323*c217d954SCole Faust#else 324*c217d954SCole Faust 325*c217d954SCole Faust#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*c217d954SCole Faust 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*c217d954SCole Faust 328*c217d954SCole Faust#endif 329*c217d954SCole Faust 330*c217d954SCole Faust#endif 331*c217d954SCole Faust 332*c217d954SCole Faust 333*c217d954SCole Faust#if defined(PARTIAL_STORE_M0) 334*c217d954SCole Faust 335*c217d954SCole Faust#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 336*c217d954SCole Faust ((uint)(max(0, (int)(y * M0) - (int)((M0 - PARTIAL_STORE_M0) % M0)))) 337*c217d954SCole Faust#else 338*c217d954SCole Faust#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 339*c217d954SCole Faust ((uint)(y * M0)) 340*c217d954SCole Faust#endif 341*c217d954SCole Faust 342*c217d954SCole Faust 343*c217d954SCole Faust 344*c217d954SCole Faust#define STORE_VECTOR_SELECT(basename, data_type, ptr, vec_size, leftover, cond) \ 345*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_X(1, vec_size, data_type, basename, ptr, 0, 0, leftover, cond) 346*c217d954SCole Faust 347*c217d954SCole Faust 348*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 349*c217d954SCole Faust#pragma OPENCL EXTENSION cl_khr_fp16 : enable 350*c217d954SCole Faust#endif 351*c217d954SCole Faust 352*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) 353*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable 354*c217d954SCole Faust#endif 355*c217d954SCole Faust 356*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) 357*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable 358*c217d954SCole Faust#endif 359*c217d954SCole Faust 360*c217d954SCole Faust#if defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf) 361*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_printf : enable 362*c217d954SCole Faust#endif 363*c217d954SCole Faust 364*c217d954SCole Faust#define GPU_ARCH_MIDGARD 0x100 365*c217d954SCole Faust#define GPU_ARCH_BIFROST 0x200 366*c217d954SCole Faust#define GPU_ARCH_VALHALL 0x300 367*c217d954SCole Faust 368*c217d954SCole Faust 369*c217d954SCole Faust#define CONCAT(a, b) a##b 370*c217d954SCole Faust 371*c217d954SCole Faust 372*c217d954SCole Faust#define EXPAND(x) x 373*c217d954SCole Faust 374*c217d954SCole Faust 375*c217d954SCole Faust#define CLAMP(x, min_val, max_val) min(max(x, min_val), max_val) 376*c217d954SCole Faust 377*c217d954SCole Faust 378*c217d954SCole Faust#define REV1(x) ((x)) 379*c217d954SCole Faust#define REV2(x) ((x).s10) 380*c217d954SCole Faust#define REV3(x) ((x).s210) 381*c217d954SCole Faust#define REV4(x) ((x).s3210) 382*c217d954SCole Faust#define REV8(x) ((x).s76543210) 383*c217d954SCole Faust#define REV16(x) ((x).sFEDCBA9876543210) 384*c217d954SCole Faust 385*c217d954SCole Faust 386*c217d954SCole Faust 387*c217d954SCole Faust#define REVERSE_STR(x, s) REV##s((x)) 388*c217d954SCole Faust#define REVERSE(x, s) REVERSE_STR(x, s) 389*c217d954SCole Faust 390*c217d954SCole Faust 391*c217d954SCole Faust 392*c217d954SCole Faust#define ROT1_0(x) ((x)) 393*c217d954SCole Faust#define ROT1_1(x) ((x)) 394*c217d954SCole Faust 395*c217d954SCole Faust#define ROT2_0(x) ((x)) 396*c217d954SCole Faust#define ROT2_1(x) ((x).s10) 397*c217d954SCole Faust#define ROT2_2(x) ((x)) 398*c217d954SCole Faust 399*c217d954SCole Faust#define ROT3_0(x) ((x)) 400*c217d954SCole Faust#define ROT3_1(x) ((x).s201) 401*c217d954SCole Faust#define ROT3_2(x) ((x).s120) 402*c217d954SCole Faust#define ROT3_3(x) ((x)) 403*c217d954SCole Faust 404*c217d954SCole Faust#define ROT4_0(x) ((x)) 405*c217d954SCole Faust#define ROT4_1(x) ((x).s3012) 406*c217d954SCole Faust#define ROT4_2(x) ((x).s2301) 407*c217d954SCole Faust#define ROT4_3(x) ((x).s1230) 408*c217d954SCole Faust#define ROT4_4(x) ((x)) 409*c217d954SCole Faust 410*c217d954SCole Faust#define ROT8_0(x) ((x)) 411*c217d954SCole Faust#define ROT8_1(x) ((x).s70123456) 412*c217d954SCole Faust#define ROT8_2(x) ((x).s67012345) 413*c217d954SCole Faust#define ROT8_3(x) ((x).s56701234) 414*c217d954SCole Faust#define ROT8_4(x) ((x).s45670123) 415*c217d954SCole Faust#define ROT8_5(x) ((x).s34567012) 416*c217d954SCole Faust#define ROT8_6(x) ((x).s23456701) 417*c217d954SCole Faust#define ROT8_7(x) ((x).s12345670) 418*c217d954SCole Faust#define ROT8_8(x) ((x)) 419*c217d954SCole Faust 420*c217d954SCole Faust#define ROT16_0(x) ((x)) 421*c217d954SCole Faust#define ROT16_1(x) ((x).sF0123456789ABCDE) 422*c217d954SCole Faust#define ROT16_2(x) ((x).sEF0123456789ABCD) 423*c217d954SCole Faust#define ROT16_3(x) ((x).sDEF0123456789ABC) 424*c217d954SCole Faust#define ROT16_4(x) ((x).sCDEF0123456789AB) 425*c217d954SCole Faust#define ROT16_5(x) ((x).sBCDEF0123456789A) 426*c217d954SCole Faust#define ROT16_6(x) ((x).sABCDEF0123456789) 427*c217d954SCole Faust#define ROT16_7(x) ((x).s9ABCDEF012345678) 428*c217d954SCole Faust#define ROT16_8(x) ((x).s89ABCDEF01234567) 429*c217d954SCole Faust#define ROT16_9(x) ((x).s789ABCDEF0123456) 430*c217d954SCole Faust#define ROT16_10(x) ((x).s6789ABCDEF012345) 431*c217d954SCole Faust#define ROT16_11(x) ((x).s56789ABCDEF01234) 432*c217d954SCole Faust#define ROT16_12(x) ((x).s456789ABCDEF0123) 433*c217d954SCole Faust#define ROT16_13(x) ((x).s3456789ABCDEF012) 434*c217d954SCole Faust#define ROT16_14(x) ((x).s23456789ABCDEF01) 435*c217d954SCole Faust#define ROT16_15(x) ((x).s123456789ABCDEF0) 436*c217d954SCole Faust#define ROT16_16(x) ((x)) 437*c217d954SCole Faust 438*c217d954SCole Faust 439*c217d954SCole Faust 440*c217d954SCole Faust#define ROTATE_STR(x, s, n) ROT##s##_##n(x) 441*c217d954SCole Faust#define ROTATE(x, s, n) ROTATE_STR(x, s, n) 442*c217d954SCole Faust 443*c217d954SCole Faust 444*c217d954SCole Faust 445*c217d954SCole Faust#define V_OFFS1(dt) (dt##1)(0) 446*c217d954SCole Faust#define V_OFFS2(dt) (dt##2)(0, 1) 447*c217d954SCole Faust#define V_OFFS3(dt) (dt##3)(0, 1, 2) 448*c217d954SCole Faust#define V_OFFS4(dt) (dt##4)(0, 1, 2, 3) 449*c217d954SCole Faust#define V_OFFS8(dt) (dt##8)(0, 1, 2, 3, 4, 5, 6, 7) 450*c217d954SCole Faust#define V_OFFS16(dt) (dt##16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) 451*c217d954SCole Faust 452*c217d954SCole Faust 453*c217d954SCole Faust 454*c217d954SCole Faust#define VEC_OFFS_STR(dt, s) V_OFFS##s(dt) 455*c217d954SCole Faust#define VEC_OFFS(dt, s) VEC_OFFS_STR(dt, s) 456*c217d954SCole Faust 457*c217d954SCole Faust 458*c217d954SCole Faust#define VLOAD_STR(size) vload##size 459*c217d954SCole Faust#define VLOAD(size) VLOAD_STR(size) 460*c217d954SCole Faust 461*c217d954SCole Faust 462*c217d954SCole Faust#define VLOAD_PARTIAL_STR(size, load_size) vload_partial_##size##_##load_size 463*c217d954SCole Faust#define VLOAD_PARTIAL(size, load_size) VLOAD_PARTIAL_STR(size, load_size) 464*c217d954SCole Faust 465*c217d954SCole Faust#define NO_LOAD(data, offs, ptr) \ 466*c217d954SCole Faust { \ 467*c217d954SCole Faust } 468*c217d954SCole Faust 469*c217d954SCole Faust 470*c217d954SCole Faust#define vload_partial_1_0 NO_LOAD 471*c217d954SCole Faust#define vload_partial_1_1 vload1 472*c217d954SCole Faust#define vload_partial_1_2 NO_LOAD 473*c217d954SCole Faust#define vload_partial_1_3 NO_LOAD 474*c217d954SCole Faust#define vload_partial_1_4 NO_LOAD 475*c217d954SCole Faust#define vload_partial_1_5 NO_LOAD 476*c217d954SCole Faust#define vload_partial_1_6 NO_LOAD 477*c217d954SCole Faust#define vload_partial_1_7 NO_LOAD 478*c217d954SCole Faust#define vload_partial_1_8 NO_LOAD 479*c217d954SCole Faust#define vload_partial_1_9 NO_LOAD 480*c217d954SCole Faust#define vload_partial_1_10 NO_LOAD 481*c217d954SCole Faust#define vload_partial_1_11 NO_LOAD 482*c217d954SCole Faust#define vload_partial_1_12 NO_LOAD 483*c217d954SCole Faust#define vload_partial_1_13 NO_LOAD 484*c217d954SCole Faust#define vload_partial_1_14 NO_LOAD 485*c217d954SCole Faust#define vload_partial_1_15 NO_LOAD 486*c217d954SCole Faust#define vload_partial_1_16 NO_LOAD 487*c217d954SCole Faust 488*c217d954SCole Faust#define vload_partial_2_0 NO_LOAD 489*c217d954SCole Faust#define vload_partial_2_1 vload_partial_1 490*c217d954SCole Faust#define vload_partial_2_2 vload_partial_2 491*c217d954SCole Faust#define vload_partial_2_3 NO_LOAD 492*c217d954SCole Faust#define vload_partial_2_4 NO_LOAD 493*c217d954SCole Faust#define vload_partial_2_5 NO_LOAD 494*c217d954SCole Faust#define vload_partial_2_6 NO_LOAD 495*c217d954SCole Faust#define vload_partial_2_7 NO_LOAD 496*c217d954SCole Faust#define vload_partial_2_8 NO_LOAD 497*c217d954SCole Faust#define vload_partial_2_9 NO_LOAD 498*c217d954SCole Faust#define vload_partial_2_10 NO_LOAD 499*c217d954SCole Faust#define vload_partial_2_11 NO_LOAD 500*c217d954SCole Faust#define vload_partial_2_12 NO_LOAD 501*c217d954SCole Faust#define vload_partial_2_13 NO_LOAD 502*c217d954SCole Faust#define vload_partial_2_14 NO_LOAD 503*c217d954SCole Faust#define vload_partial_2_15 NO_LOAD 504*c217d954SCole Faust#define vload_partial_2_16 NO_LOAD 505*c217d954SCole Faust 506*c217d954SCole Faust#define vload_partial_3_0 NO_LOAD 507*c217d954SCole Faust#define vload_partial_3_1 vload_partial_1 508*c217d954SCole Faust#define vload_partial_3_2 vload_partial_2 509*c217d954SCole Faust#define vload_partial_3_3 vload_partial_3 510*c217d954SCole Faust#define vload_partial_3_4 NO_LOAD 511*c217d954SCole Faust#define vload_partial_3_5 NO_LOAD 512*c217d954SCole Faust#define vload_partial_3_6 NO_LOAD 513*c217d954SCole Faust#define vload_partial_3_7 NO_LOAD 514*c217d954SCole Faust#define vload_partial_3_8 NO_LOAD 515*c217d954SCole Faust#define vload_partial_3_9 NO_LOAD 516*c217d954SCole Faust#define vload_partial_3_10 NO_LOAD 517*c217d954SCole Faust#define vload_partial_3_11 NO_LOAD 518*c217d954SCole Faust#define vload_partial_3_12 NO_LOAD 519*c217d954SCole Faust#define vload_partial_3_13 NO_LOAD 520*c217d954SCole Faust#define vload_partial_3_14 NO_LOAD 521*c217d954SCole Faust#define vload_partial_3_15 NO_LOAD 522*c217d954SCole Faust#define vload_partial_3_16 NO_LOAD 523*c217d954SCole Faust 524*c217d954SCole Faust#define vload_partial_4_0 NO_LOAD 525*c217d954SCole Faust#define vload_partial_4_1 vload_partial_1 526*c217d954SCole Faust#define vload_partial_4_2 vload_partial_2 527*c217d954SCole Faust#define vload_partial_4_3 vload_partial_3 528*c217d954SCole Faust#define vload_partial_4_4 vload_partial_4 529*c217d954SCole Faust#define vload_partial_4_5 NO_LOAD 530*c217d954SCole Faust#define vload_partial_4_6 NO_LOAD 531*c217d954SCole Faust#define vload_partial_4_7 NO_LOAD 532*c217d954SCole Faust#define vload_partial_4_8 NO_LOAD 533*c217d954SCole Faust#define vload_partial_4_9 NO_LOAD 534*c217d954SCole Faust#define vload_partial_4_10 NO_LOAD 535*c217d954SCole Faust#define vload_partial_4_11 NO_LOAD 536*c217d954SCole Faust#define vload_partial_4_12 NO_LOAD 537*c217d954SCole Faust#define vload_partial_4_13 NO_LOAD 538*c217d954SCole Faust#define vload_partial_4_14 NO_LOAD 539*c217d954SCole Faust#define vload_partial_4_15 NO_LOAD 540*c217d954SCole Faust#define vload_partial_4_16 NO_LOAD 541*c217d954SCole Faust 542*c217d954SCole Faust#define vload_partial_8_0 NO_LOAD 543*c217d954SCole Faust#define vload_partial_8_1 vload_partial_1 544*c217d954SCole Faust#define vload_partial_8_2 vload_partial_2 545*c217d954SCole Faust#define vload_partial_8_3 vload_partial_3 546*c217d954SCole Faust#define vload_partial_8_4 vload_partial_4 547*c217d954SCole Faust#define vload_partial_8_5 vload_partial_5 548*c217d954SCole Faust#define vload_partial_8_6 vload_partial_6 549*c217d954SCole Faust#define vload_partial_8_7 vload_partial_7 550*c217d954SCole Faust#define vload_partial_8_8 vload_partial_8 551*c217d954SCole Faust#define vload_partial_8_9 NO_LOAD 552*c217d954SCole Faust#define vload_partial_8_10 NO_LOAD 553*c217d954SCole Faust#define vload_partial_8_11 NO_LOAD 554*c217d954SCole Faust#define vload_partial_8_12 NO_LOAD 555*c217d954SCole Faust#define vload_partial_8_13 NO_LOAD 556*c217d954SCole Faust#define vload_partial_8_14 NO_LOAD 557*c217d954SCole Faust#define vload_partial_8_15 NO_LOAD 558*c217d954SCole Faust#define vload_partial_8_16 NO_LOAD 559*c217d954SCole Faust 560*c217d954SCole Faust#define vload_partial_16_0 NO_LOAD 561*c217d954SCole Faust#define vload_partial_16_1 vload_partial_1 562*c217d954SCole Faust#define vload_partial_16_2 vload_partial_2 563*c217d954SCole Faust#define vload_partial_16_3 vload_partial_3 564*c217d954SCole Faust#define vload_partial_16_4 vload_partial_4 565*c217d954SCole Faust#define vload_partial_16_5 vload_partial_5 566*c217d954SCole Faust#define vload_partial_16_6 vload_partial_6 567*c217d954SCole Faust#define vload_partial_16_7 vload_partial_7 568*c217d954SCole Faust#define vload_partial_16_8 vload_partial_8 569*c217d954SCole Faust#define vload_partial_16_9 vload_partial_9 570*c217d954SCole Faust#define vload_partial_16_10 vload_partial_10 571*c217d954SCole Faust#define vload_partial_16_11 vload_partial_11 572*c217d954SCole Faust#define vload_partial_16_12 vload_partial_12 573*c217d954SCole Faust#define vload_partial_16_13 vload_partial_13 574*c217d954SCole Faust#define vload_partial_16_14 vload_partial_14 575*c217d954SCole Faust#define vload_partial_16_15 vload_partial_15 576*c217d954SCole Faust#define vload_partial_16_16 vload_partial_16 577*c217d954SCole Faust 578*c217d954SCole Faust 579*c217d954SCole Faust#define vload_partial_1(DATA, OFFSET, PTR) \ 580*c217d954SCole Faust DATA.s0 = vload1(OFFSET, PTR); 581*c217d954SCole Faust 582*c217d954SCole Faust#define vload_partial_2(DATA, OFFSET, PTR) \ 583*c217d954SCole Faust DATA.s01 = vload2(OFFSET, PTR); 584*c217d954SCole Faust 585*c217d954SCole Faust#define vload_partial_3(DATA, OFFSET, PTR) \ 586*c217d954SCole Faust DATA.s012 = vload3(OFFSET, PTR); 587*c217d954SCole Faust 588*c217d954SCole Faust#define vload_partial_4(DATA, OFFSET, PTR) \ 589*c217d954SCole Faust DATA.s0123 = vload4(OFFSET, PTR); 590*c217d954SCole Faust 591*c217d954SCole Faust#define vload_partial_5(DATA, OFFSET, PTR) \ 592*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 593*c217d954SCole Faust DATA.s4 = vload1(OFFSET, PTR + 4); 594*c217d954SCole Faust 595*c217d954SCole Faust#define vload_partial_6(DATA, OFFSET, PTR) \ 596*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 597*c217d954SCole Faust vload_partial_2(DATA.s45, OFFSET, PTR + 4); 598*c217d954SCole Faust 599*c217d954SCole Faust#define vload_partial_7(DATA, OFFSET, PTR) \ 600*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 601*c217d954SCole Faust vload_partial_3(DATA.s456, OFFSET, PTR + 4); 602*c217d954SCole Faust 603*c217d954SCole Faust#define vload_partial_8(DATA, OFFSET, PTR) \ 604*c217d954SCole Faust DATA.s01234567 = vload8(OFFSET, PTR); 605*c217d954SCole Faust 606*c217d954SCole Faust#define vload_partial_9(DATA, OFFSET, PTR) \ 607*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 608*c217d954SCole Faust DATA.s8 = vload1(OFFSET, PTR + 8); 609*c217d954SCole Faust 610*c217d954SCole Faust#define vload_partial_10(DATA, OFFSET, PTR) \ 611*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 612*c217d954SCole Faust vload_partial_2(DATA.s89, OFFSET, PTR + 8); 613*c217d954SCole Faust 614*c217d954SCole Faust#define vload_partial_11(DATA, OFFSET, PTR) \ 615*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 616*c217d954SCole Faust vload_partial_3(DATA.s89A, OFFSET, PTR + 8); 617*c217d954SCole Faust 618*c217d954SCole Faust#define vload_partial_12(DATA, OFFSET, PTR) \ 619*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 620*c217d954SCole Faust vload_partial_4(DATA.s89AB, OFFSET, PTR + 8); 621*c217d954SCole Faust 622*c217d954SCole Faust#define vload_partial_13(DATA, OFFSET, PTR) \ 623*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 624*c217d954SCole Faust vload_partial_5(DATA.s89ABCDEF, OFFSET, PTR + 8); 625*c217d954SCole Faust 626*c217d954SCole Faust#define vload_partial_14(DATA, OFFSET, PTR) \ 627*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 628*c217d954SCole Faust vload_partial_6(DATA.s89ABCDEF, OFFSET, PTR + 8); 629*c217d954SCole Faust 630*c217d954SCole Faust#define vload_partial_15(DATA, OFFSET, PTR) \ 631*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 632*c217d954SCole Faust vload_partial_7(DATA.s89ABCDEF, OFFSET, PTR + 8); 633*c217d954SCole Faust 634*c217d954SCole Faust#define vload_partial_16(DATA, OFFSET, PTR) \ 635*c217d954SCole Faust DATA = vload16(OFFSET, PTR); 636*c217d954SCole Faust 637*c217d954SCole Faust 638*c217d954SCole Faust 639*c217d954SCole Faust#define PIXEL_UNIT4 1 640*c217d954SCole Faust#define PIXEL_UNIT8 2 641*c217d954SCole Faust#define PIXEL_UNIT16 4 642*c217d954SCole Faust 643*c217d954SCole Faust 644*c217d954SCole Faust#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) PIXEL_UNIT##vec_size 645*c217d954SCole Faust#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(vec_size) CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) 646*c217d954SCole Faust 647*c217d954SCole Faust 648*c217d954SCole Faust#define read_image2d_floatx1(img, x_coord, y_coord) (float4)(read_imagef(img, (int2)(x_coord, y_coord))); 649*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 652*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 653*c217d954SCole Faust#define read_image2d_halfx1(img, x_coord, y_coord) (half4)(read_imageh(img, (int2)(x_coord, y_coord))); 654*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust#endif 657*c217d954SCole Faust 658*c217d954SCole Faust#define write_image2d_floatx1(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values)); 659*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 662*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 663*c217d954SCole Faust#define write_image2d_halfx1(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values)); 664*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust#endif 667*c217d954SCole Faust 668*c217d954SCole Faust 669*c217d954SCole Faust#define READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) read_image2d_##data_type##x##n0(img, x_coord, y_coord) 670*c217d954SCole Faust#define READ_IMAGE2D(data_type, n0, img, x_coord, y_coord) READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) 671*c217d954SCole Faust 672*c217d954SCole Faust 673*c217d954SCole Faust#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*c217d954SCole Faust#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*c217d954SCole Faust 676*c217d954SCole Faust#define VSTORE_STR(size) vstore##size 677*c217d954SCole Faust#define VSTORE(size) VSTORE_STR(size) 678*c217d954SCole Faust 679*c217d954SCole Faust#define float1 float 680*c217d954SCole Faust#define half1 half 681*c217d954SCole Faust#define char1 char 682*c217d954SCole Faust#define uchar1 uchar 683*c217d954SCole Faust#define short1 short 684*c217d954SCole Faust#define ushort1 ushort 685*c217d954SCole Faust#define int1 int 686*c217d954SCole Faust#define uint1 uint 687*c217d954SCole Faust#define long1 long 688*c217d954SCole Faust#define ulong1 ulong 689*c217d954SCole Faust#define double1 double 690*c217d954SCole Faust 691*c217d954SCole Faust#define vload1(OFFSET, PTR) *(OFFSET + PTR) 692*c217d954SCole Faust#define vstore1(DATA, OFFSET, PTR) *(OFFSET + PTR) = DATA 693*c217d954SCole Faust 694*c217d954SCole Faust 695*c217d954SCole Faust#define VSTORE_PARTIAL_STR(size, store_size) vstore_partial_##size##_##store_size 696*c217d954SCole Faust#define VSTORE_PARTIAL(size, store_size) VSTORE_PARTIAL_STR(size, store_size) 697*c217d954SCole Faust 698*c217d954SCole Faust#define NO_STORE(data, offs, ptr) \ 699*c217d954SCole Faust { \ 700*c217d954SCole Faust } 701*c217d954SCole Faust 702*c217d954SCole Faust 703*c217d954SCole Faust#define vstore_partial_1_0 NO_STORE 704*c217d954SCole Faust#define vstore_partial_1_1 vstore1 705*c217d954SCole Faust#define vstore_partial_1_2 NO_STORE 706*c217d954SCole Faust#define vstore_partial_1_3 NO_STORE 707*c217d954SCole Faust#define vstore_partial_1_4 NO_STORE 708*c217d954SCole Faust#define vstore_partial_1_5 NO_STORE 709*c217d954SCole Faust#define vstore_partial_1_6 NO_STORE 710*c217d954SCole Faust#define vstore_partial_1_7 NO_STORE 711*c217d954SCole Faust#define vstore_partial_1_8 NO_STORE 712*c217d954SCole Faust#define vstore_partial_1_9 NO_STORE 713*c217d954SCole Faust#define vstore_partial_1_10 NO_STORE 714*c217d954SCole Faust#define vstore_partial_1_11 NO_STORE 715*c217d954SCole Faust#define vstore_partial_1_12 NO_STORE 716*c217d954SCole Faust#define vstore_partial_1_13 NO_STORE 717*c217d954SCole Faust#define vstore_partial_1_14 NO_STORE 718*c217d954SCole Faust#define vstore_partial_1_15 NO_STORE 719*c217d954SCole Faust#define vstore_partial_1_16 NO_STORE 720*c217d954SCole Faust 721*c217d954SCole Faust#define vstore_partial_2_0 NO_STORE 722*c217d954SCole Faust#define vstore_partial_2_1 vstore_partial_1 723*c217d954SCole Faust#define vstore_partial_2_2 vstore_partial_2 724*c217d954SCole Faust#define vstore_partial_2_3 NO_STORE 725*c217d954SCole Faust#define vstore_partial_2_4 NO_STORE 726*c217d954SCole Faust#define vstore_partial_2_5 NO_STORE 727*c217d954SCole Faust#define vstore_partial_2_6 NO_STORE 728*c217d954SCole Faust#define vstore_partial_2_7 NO_STORE 729*c217d954SCole Faust#define vstore_partial_2_8 NO_STORE 730*c217d954SCole Faust#define vstore_partial_2_9 NO_STORE 731*c217d954SCole Faust#define vstore_partial_2_10 NO_STORE 732*c217d954SCole Faust#define vstore_partial_2_11 NO_STORE 733*c217d954SCole Faust#define vstore_partial_2_12 NO_STORE 734*c217d954SCole Faust#define vstore_partial_2_13 NO_STORE 735*c217d954SCole Faust#define vstore_partial_2_14 NO_STORE 736*c217d954SCole Faust#define vstore_partial_2_15 NO_STORE 737*c217d954SCole Faust#define vstore_partial_2_16 NO_STORE 738*c217d954SCole Faust 739*c217d954SCole Faust#define vstore_partial_3_0 NO_STORE 740*c217d954SCole Faust#define vstore_partial_3_1 vstore_partial_1 741*c217d954SCole Faust#define vstore_partial_3_2 vstore_partial_2 742*c217d954SCole Faust#define vstore_partial_3_3 vstore_partial_3 743*c217d954SCole Faust#define vstore_partial_3_4 NO_STORE 744*c217d954SCole Faust#define vstore_partial_3_5 NO_STORE 745*c217d954SCole Faust#define vstore_partial_3_6 NO_STORE 746*c217d954SCole Faust#define vstore_partial_3_7 NO_STORE 747*c217d954SCole Faust#define vstore_partial_3_8 NO_STORE 748*c217d954SCole Faust#define vstore_partial_3_9 NO_STORE 749*c217d954SCole Faust#define vstore_partial_3_10 NO_STORE 750*c217d954SCole Faust#define vstore_partial_3_11 NO_STORE 751*c217d954SCole Faust#define vstore_partial_3_12 NO_STORE 752*c217d954SCole Faust#define vstore_partial_3_13 NO_STORE 753*c217d954SCole Faust#define vstore_partial_3_14 NO_STORE 754*c217d954SCole Faust#define vstore_partial_3_15 NO_STORE 755*c217d954SCole Faust#define vstore_partial_3_16 NO_STORE 756*c217d954SCole Faust 757*c217d954SCole Faust#define vstore_partial_4_0 NO_STORE 758*c217d954SCole Faust#define vstore_partial_4_1 vstore_partial_1 759*c217d954SCole Faust#define vstore_partial_4_2 vstore_partial_2 760*c217d954SCole Faust#define vstore_partial_4_3 vstore_partial_3 761*c217d954SCole Faust#define vstore_partial_4_4 vstore_partial_4 762*c217d954SCole Faust#define vstore_partial_4_5 NO_STORE 763*c217d954SCole Faust#define vstore_partial_4_6 NO_STORE 764*c217d954SCole Faust#define vstore_partial_4_7 NO_STORE 765*c217d954SCole Faust#define vstore_partial_4_8 NO_STORE 766*c217d954SCole Faust#define vstore_partial_4_9 NO_STORE 767*c217d954SCole Faust#define vstore_partial_4_10 NO_STORE 768*c217d954SCole Faust#define vstore_partial_4_11 NO_STORE 769*c217d954SCole Faust#define vstore_partial_4_12 NO_STORE 770*c217d954SCole Faust#define vstore_partial_4_13 NO_STORE 771*c217d954SCole Faust#define vstore_partial_4_14 NO_STORE 772*c217d954SCole Faust#define vstore_partial_4_15 NO_STORE 773*c217d954SCole Faust#define vstore_partial_4_16 NO_STORE 774*c217d954SCole Faust 775*c217d954SCole Faust#define vstore_partial_8_0 NO_STORE 776*c217d954SCole Faust#define vstore_partial_8_1 vstore_partial_1 777*c217d954SCole Faust#define vstore_partial_8_2 vstore_partial_2 778*c217d954SCole Faust#define vstore_partial_8_3 vstore_partial_3 779*c217d954SCole Faust#define vstore_partial_8_4 vstore_partial_4 780*c217d954SCole Faust#define vstore_partial_8_5 vstore_partial_5 781*c217d954SCole Faust#define vstore_partial_8_6 vstore_partial_6 782*c217d954SCole Faust#define vstore_partial_8_7 vstore_partial_7 783*c217d954SCole Faust#define vstore_partial_8_8 vstore_partial_8 784*c217d954SCole Faust#define vstore_partial_8_9 NO_STORE 785*c217d954SCole Faust#define vstore_partial_8_10 NO_STORE 786*c217d954SCole Faust#define vstore_partial_8_11 NO_STORE 787*c217d954SCole Faust#define vstore_partial_8_12 NO_STORE 788*c217d954SCole Faust#define vstore_partial_8_13 NO_STORE 789*c217d954SCole Faust#define vstore_partial_8_14 NO_STORE 790*c217d954SCole Faust#define vstore_partial_8_15 NO_STORE 791*c217d954SCole Faust#define vstore_partial_8_16 NO_STORE 792*c217d954SCole Faust 793*c217d954SCole Faust#define vstore_partial_16_0 NO_STORE 794*c217d954SCole Faust#define vstore_partial_16_1 vstore_partial_1 795*c217d954SCole Faust#define vstore_partial_16_2 vstore_partial_2 796*c217d954SCole Faust#define vstore_partial_16_3 vstore_partial_3 797*c217d954SCole Faust#define vstore_partial_16_4 vstore_partial_4 798*c217d954SCole Faust#define vstore_partial_16_5 vstore_partial_5 799*c217d954SCole Faust#define vstore_partial_16_6 vstore_partial_6 800*c217d954SCole Faust#define vstore_partial_16_7 vstore_partial_7 801*c217d954SCole Faust#define vstore_partial_16_8 vstore_partial_8 802*c217d954SCole Faust#define vstore_partial_16_9 vstore_partial_9 803*c217d954SCole Faust#define vstore_partial_16_10 vstore_partial_10 804*c217d954SCole Faust#define vstore_partial_16_11 vstore_partial_11 805*c217d954SCole Faust#define vstore_partial_16_12 vstore_partial_12 806*c217d954SCole Faust#define vstore_partial_16_13 vstore_partial_13 807*c217d954SCole Faust#define vstore_partial_16_14 vstore_partial_14 808*c217d954SCole Faust#define vstore_partial_16_15 vstore_partial_15 809*c217d954SCole Faust#define vstore_partial_16_16 vstore_partial_16 810*c217d954SCole Faust 811*c217d954SCole Faust 812*c217d954SCole Faust#define vstore_partial_1(DATA, OFFSET, PTR) \ 813*c217d954SCole Faust vstore1(DATA.s0, OFFSET, PTR); 814*c217d954SCole Faust 815*c217d954SCole Faust#define vstore_partial_2(DATA, OFFSET, PTR) \ 816*c217d954SCole Faust vstore2(DATA.s01, OFFSET, PTR); 817*c217d954SCole Faust 818*c217d954SCole Faust#define vstore_partial_3(DATA, OFFSET, PTR) \ 819*c217d954SCole Faust vstore3(DATA.s012, OFFSET, PTR); 820*c217d954SCole Faust 821*c217d954SCole Faust#define vstore_partial_4(DATA, OFFSET, PTR) \ 822*c217d954SCole Faust vstore4(DATA.s0123, OFFSET, PTR); 823*c217d954SCole Faust 824*c217d954SCole Faust#define vstore_partial_5(DATA, OFFSET, PTR) \ 825*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 826*c217d954SCole Faust vstore1(DATA.s4, OFFSET, PTR + 4); 827*c217d954SCole Faust 828*c217d954SCole Faust#define vstore_partial_6(DATA, OFFSET, PTR) \ 829*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 830*c217d954SCole Faust vstore_partial_2(DATA.s45, OFFSET, PTR + 4); 831*c217d954SCole Faust 832*c217d954SCole Faust#define vstore_partial_7(DATA, OFFSET, PTR) \ 833*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 834*c217d954SCole Faust vstore_partial_3(DATA.s456, OFFSET, PTR + 4); 835*c217d954SCole Faust 836*c217d954SCole Faust#define vstore_partial_8(DATA, OFFSET, PTR) \ 837*c217d954SCole Faust vstore8(DATA.s01234567, OFFSET, PTR); 838*c217d954SCole Faust 839*c217d954SCole Faust#define vstore_partial_9(DATA, OFFSET, PTR) \ 840*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 841*c217d954SCole Faust vstore1(DATA.s8, OFFSET, PTR + 8); 842*c217d954SCole Faust 843*c217d954SCole Faust#define vstore_partial_10(DATA, OFFSET, PTR) \ 844*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 845*c217d954SCole Faust vstore_partial_2(DATA.s89, OFFSET, PTR + 8); 846*c217d954SCole Faust 847*c217d954SCole Faust#define vstore_partial_11(DATA, OFFSET, PTR) \ 848*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 849*c217d954SCole Faust vstore_partial_3(DATA.s89a, OFFSET, PTR + 8); 850*c217d954SCole Faust 851*c217d954SCole Faust#define vstore_partial_12(DATA, OFFSET, PTR) \ 852*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 853*c217d954SCole Faust vstore_partial_4(DATA.s89ab, OFFSET, PTR + 8); 854*c217d954SCole Faust 855*c217d954SCole Faust#define vstore_partial_13(DATA, OFFSET, PTR) \ 856*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 857*c217d954SCole Faust vstore_partial_5(DATA.s89abcdef, OFFSET, PTR + 8); 858*c217d954SCole Faust 859*c217d954SCole Faust#define vstore_partial_14(DATA, OFFSET, PTR) \ 860*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 861*c217d954SCole Faust vstore_partial_6(DATA.s89abcdef, OFFSET, PTR + 8); 862*c217d954SCole Faust 863*c217d954SCole Faust#define vstore_partial_15(DATA, OFFSET, PTR) \ 864*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 865*c217d954SCole Faust vstore_partial_7(DATA.s89abcdef, OFFSET, PTR + 8); 866*c217d954SCole Faust 867*c217d954SCole Faust#define vstore_partial_16(DATA, OFFSET, PTR) \ 868*c217d954SCole Faust vstore16(DATA, OFFSET, PTR); 869*c217d954SCole Faust 870*c217d954SCole Faust 871*c217d954SCole Faust 872*c217d954SCole Faust 873*c217d954SCole Faust 874*c217d954SCole Faust#define convert_float_sat convert_float 875*c217d954SCole Faust#define convert_float1_sat convert_float 876*c217d954SCole Faust#define convert_float2_sat convert_float2 877*c217d954SCole Faust#define convert_float3_sat convert_float3 878*c217d954SCole Faust#define convert_float4_sat convert_float4 879*c217d954SCole Faust#define convert_float8_sat convert_float8 880*c217d954SCole Faust#define convert_float16_sat convert_float16 881*c217d954SCole Faust#define convert_half_sat convert_float 882*c217d954SCole Faust#define convert_half1_sat convert_half 883*c217d954SCole Faust#define convert_half2_sat convert_half2 884*c217d954SCole Faust#define convert_half3_sat convert_half3 885*c217d954SCole Faust#define convert_half4_sat convert_half4 886*c217d954SCole Faust#define convert_half8_sat convert_half8 887*c217d954SCole Faust#define convert_half16_sat convert_half16 888*c217d954SCole Faust 889*c217d954SCole Faust#define convert_float1 convert_float 890*c217d954SCole Faust#define convert_half1 convert_half 891*c217d954SCole Faust#define convert_char1 convert_char 892*c217d954SCole Faust#define convert_uchar1 convert_uchar 893*c217d954SCole Faust#define convert_short1 convert_short 894*c217d954SCole Faust#define convert_ushort1 convert_ushort 895*c217d954SCole Faust#define convert_int1 convert_int 896*c217d954SCole Faust#define convert_uint1 convert_uint 897*c217d954SCole Faust#define convert_long1 convert_long 898*c217d954SCole Faust#define convert_ulong1 convert_ulong 899*c217d954SCole Faust#define convert_double1 convert_double 900*c217d954SCole Faust 901*c217d954SCole Faust#define convert_char1_sat convert_char_sat 902*c217d954SCole Faust#define convert_uchar1_sat convert_uchar_sat 903*c217d954SCole Faust#define convert_uchar2_sat convert_uchar2_sat 904*c217d954SCole Faust#define convert_uchar3_sat convert_uchar3_sat 905*c217d954SCole Faust#define convert_uchar4_sat convert_uchar4_sat 906*c217d954SCole Faust#define convert_uchar8_sat convert_uchar8_sat 907*c217d954SCole Faust#define convert_uchar16_sat convert_uchar16_sat 908*c217d954SCole Faust#define convert_short1_sat convert_short_sat 909*c217d954SCole Faust#define convert_ushort1_sat convert_ushort_sat 910*c217d954SCole Faust#define convert_int1_sat convert_int_sat 911*c217d954SCole Faust#define convert_uint1_sat convert_uint_sat 912*c217d954SCole Faust#define convert_long1_sat convert_long_sat 913*c217d954SCole Faust#define convert_ulong1_sat convert_ulong_sat 914*c217d954SCole Faust#define convert_double1_sat convert_double_sat 915*c217d954SCole Faust 916*c217d954SCole Faust#define VEC_DATA_TYPE_STR(type, size) type##size 917*c217d954SCole Faust#define VEC_DATA_TYPE(type, size) VEC_DATA_TYPE_STR(type, size) 918*c217d954SCole Faust 919*c217d954SCole Faust#define CONVERT_STR(x, type) (convert_##type((x))) 920*c217d954SCole Faust#define CONVERT(x, type) CONVERT_STR(x, type) 921*c217d954SCole Faust 922*c217d954SCole Faust#define CONVERT_SAT_STR(x, type) (convert_##type##_sat((x))) 923*c217d954SCole Faust#define CONVERT_SAT(x, type) CONVERT_SAT_STR(x, type) 924*c217d954SCole Faust 925*c217d954SCole Faust#define CONVERT_SAT_ROUND_STR(x, type, round) (convert_##type##_sat_##round((x))) 926*c217d954SCole Faust#define CONVERT_SAT_ROUND(x, type, round) CONVERT_SAT_ROUND_STR(x, type, round) 927*c217d954SCole Faust 928*c217d954SCole Faust#define select_vec_dt_uchar(size) uchar##size 929*c217d954SCole Faust#define select_vec_dt_char(size) char##size 930*c217d954SCole Faust#define select_vec_dt_ushort(size) ushort##size 931*c217d954SCole Faust#define select_vec_dt_short(size) short##size 932*c217d954SCole Faust#define select_vec_dt_half(size) short##size 933*c217d954SCole Faust#define select_vec_dt_uint(size) uint##size 934*c217d954SCole Faust#define select_vec_dt_int(size) int##size 935*c217d954SCole Faust#define select_vec_dt_float(size) int##size 936*c217d954SCole Faust#define select_vec_dt_ulong(size) ulong##size 937*c217d954SCole Faust#define select_vec_dt_long(size) long##size 938*c217d954SCole Faust 939*c217d954SCole Faust#define SELECT_VEC_DATA_TYPE_STR(type, size) select_vec_dt_##type(size) 940*c217d954SCole Faust#define SELECT_VEC_DATA_TYPE(type, size) SELECT_VEC_DATA_TYPE_STR(type, size) 941*c217d954SCole Faust#define SELECT_DATA_TYPE(type) SELECT_VEC_DATA_TYPE_STR(type, 1) 942*c217d954SCole Faust 943*c217d954SCole Faust#define signed_int_vec_dt_uchar(size) char##size 944*c217d954SCole Faust#define signed_int_vec_dt_char(size) char##size 945*c217d954SCole Faust#define signed_int_vec_dt_ushort(size) short##size 946*c217d954SCole Faust#define signed_int_vec_dt_short(size) short##size 947*c217d954SCole Faust#define signed_int_vec_dt_half(size) short##size 948*c217d954SCole Faust#define signed_int_vec_dt_uint(size) int##size 949*c217d954SCole Faust#define signed_int_vec_dt_int(size) int##size 950*c217d954SCole Faust#define signed_int_vec_dt_float(size) int##size 951*c217d954SCole Faust#define signed_int_vec_dt_ulong(size) long##size 952*c217d954SCole Faust#define signed_int_vec_dt_long(size) long##size 953*c217d954SCole Faust 954*c217d954SCole Faust#define SIGNED_INT_VEC_DATA_TYPE_STR(type, size) signed_int_vec_dt_##type(size) 955*c217d954SCole Faust#define SIGNED_INT_VEC_DATA_TYPE(type, size) SIGNED_INT_VEC_DATA_TYPE_STR(type, size) 956*c217d954SCole Faust#define SIGNED_INT_DATA_TYPE(type) SIGNED_INT_VEC_DATA_TYPE_STR(type, 1) 957*c217d954SCole Faust 958*c217d954SCole Faust#define sum_reduce_1(x) (x) 959*c217d954SCole Faust#define sum_reduce_2(x) ((x).s0) + ((x).s1) 960*c217d954SCole Faust#define sum_reduce_3(x) sum_reduce_2((x).s01) + ((x).s2) 961*c217d954SCole Faust#define sum_reduce_4(x) sum_reduce_2((x).s01) + sum_reduce_2((x).s23) 962*c217d954SCole Faust#define sum_reduce_8(x) sum_reduce_4((x).s0123) + sum_reduce_4((x).s4567) 963*c217d954SCole Faust#define sum_reduce_16(x) sum_reduce_8((x).s01234567) + sum_reduce_8((x).s89ABCDEF) 964*c217d954SCole Faust 965*c217d954SCole Faust#define SUM_REDUCE_STR(x, size) sum_reduce_##size(x) 966*c217d954SCole Faust#define SUM_REDUCE(x, size) SUM_REDUCE_STR(x, size) 967*c217d954SCole Faust 968*c217d954SCole Faust#define prod_reduce_1(x) (x) 969*c217d954SCole Faust#define prod_reduce_2(x) ((x).s0) * ((x).s1) 970*c217d954SCole Faust#define prod_reduce_3(x) prod_reduce_2((x).s01) * ((x).s2) 971*c217d954SCole Faust#define prod_reduce_4(x) prod_reduce_2((x).s01) * prod_reduce_2((x).s23) 972*c217d954SCole Faust#define prod_reduce_8(x) prod_reduce_4((x).s0123) * prod_reduce_4((x).s4567) 973*c217d954SCole Faust#define prod_reduce_16(x) prod_reduce_8((x).s01234567) * prod_reduce_8((x).s89ABCDEF) 974*c217d954SCole Faust 975*c217d954SCole Faust#define PROD_REDUCE_STR(x, size) prod_reduce_##size(x) 976*c217d954SCole Faust#define PROD_REDUCE(x, size) PROD_REDUCE_STR(x, size) 977*c217d954SCole Faust 978*c217d954SCole Faust#define max_reduce_1(x) (x) 979*c217d954SCole Faust#define max_reduce_2(x) max(((x).s0), ((x).s1)) 980*c217d954SCole Faust#define max_reduce_3(x) max(max_reduce_2((x).s01), ((x).s2)) 981*c217d954SCole Faust#define max_reduce_4(x) max(max_reduce_2((x).s01), max_reduce_2((x).s23)) 982*c217d954SCole Faust#define max_reduce_8(x) max(max_reduce_4((x).s0123), max_reduce_4((x).s4567)) 983*c217d954SCole Faust#define max_reduce_16(x) max(max_reduce_8((x).s01234567), max_reduce_8((x).s89ABCDEF)) 984*c217d954SCole Faust 985*c217d954SCole Faust#define MAX_REDUCE_STR(x, size) max_reduce_##size(x) 986*c217d954SCole Faust#define MAX_REDUCE(x, size) MAX_REDUCE_STR(x, size) 987*c217d954SCole Faust 988*c217d954SCole Faust#define VECTOR_DECLARATION(name) \ 989*c217d954SCole Faust __global uchar *name##_ptr, \ 990*c217d954SCole Faust uint name##_stride_x, \ 991*c217d954SCole Faust uint name##_step_x, \ 992*c217d954SCole Faust uint name##_offset_first_element_in_bytes 993*c217d954SCole Faust 994*c217d954SCole Faust#define IMAGE_DECLARATION(name) \ 995*c217d954SCole Faust __global uchar *name##_ptr, \ 996*c217d954SCole Faust uint name##_stride_x, \ 997*c217d954SCole Faust uint name##_step_x, \ 998*c217d954SCole Faust uint name##_stride_y, \ 999*c217d954SCole Faust uint name##_step_y, \ 1000*c217d954SCole Faust uint name##_offset_first_element_in_bytes 1001*c217d954SCole Faust 1002*c217d954SCole Faust#define TENSOR3D_DECLARATION(name) \ 1003*c217d954SCole Faust __global uchar *name##_ptr, \ 1004*c217d954SCole Faust uint name##_stride_x, \ 1005*c217d954SCole Faust uint name##_step_x, \ 1006*c217d954SCole Faust uint name##_stride_y, \ 1007*c217d954SCole Faust uint name##_step_y, \ 1008*c217d954SCole Faust uint name##_stride_z, \ 1009*c217d954SCole Faust uint name##_step_z, \ 1010*c217d954SCole Faust uint name##_offset_first_element_in_bytes 1011*c217d954SCole Faust 1012*c217d954SCole Faust#define TENSOR4D_DECLARATION(name) \ 1013*c217d954SCole Faust __global uchar *name##_ptr, \ 1014*c217d954SCole Faust uint name##_stride_x, \ 1015*c217d954SCole Faust uint name##_step_x, \ 1016*c217d954SCole Faust uint name##_stride_y, \ 1017*c217d954SCole Faust uint name##_step_y, \ 1018*c217d954SCole Faust uint name##_stride_z, \ 1019*c217d954SCole Faust uint name##_step_z, \ 1020*c217d954SCole Faust uint name##_stride_w, \ 1021*c217d954SCole Faust uint name##_step_w, \ 1022*c217d954SCole Faust uint name##_offset_first_element_in_bytes 1023*c217d954SCole Faust 1024*c217d954SCole Faust#define TENSOR5D_DECLARATION(name) \ 1025*c217d954SCole Faust __global uchar *name##_ptr, \ 1026*c217d954SCole Faust uint name##_stride_x, \ 1027*c217d954SCole Faust uint name##_step_x, \ 1028*c217d954SCole Faust uint name##_stride_y, \ 1029*c217d954SCole Faust uint name##_step_y, \ 1030*c217d954SCole Faust uint name##_stride_z, \ 1031*c217d954SCole Faust uint name##_step_z, \ 1032*c217d954SCole Faust uint name##_stride_w, \ 1033*c217d954SCole Faust uint name##_step_w, \ 1034*c217d954SCole Faust uint name##_stride_v, \ 1035*c217d954SCole Faust uint name##_step_v, \ 1036*c217d954SCole Faust uint name##_offset_first_element_in_bytes 1037*c217d954SCole Faust 1038*c217d954SCole Faust#define CONVERT_TO_VECTOR_STRUCT(name) \ 1039*c217d954SCole Faust update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x) 1040*c217d954SCole Faust 1041*c217d954SCole Faust#define CONVERT_TO_VECTOR_STRUCT_NO_STEP(name) \ 1042*c217d954SCole Faust update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0) 1043*c217d954SCole Faust 1044*c217d954SCole Faust#define CONVERT_TO_IMAGE_STRUCT(name) \ 1045*c217d954SCole Faust 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*c217d954SCole Faust 1047*c217d954SCole Faust#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name) \ 1048*c217d954SCole Faust update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0) 1049*c217d954SCole Faust 1050*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 1051*c217d954SCole Faust 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*c217d954SCole Faust 1053*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(name) \ 1054*c217d954SCole Faust 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*c217d954SCole Faust 1056*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 1057*c217d954SCole Faust 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*c217d954SCole Faust 1059*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT(name) \ 1060*c217d954SCole Faust 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*c217d954SCole Faust name##_stride_z, name##_step_z) 1062*c217d954SCole Faust 1063*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name) \ 1064*c217d954SCole Faust 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*c217d954SCole Faust 1066*c217d954SCole Faust#define CONVERT_TO_TENSOR4D_STRUCT(name, mod_size) \ 1067*c217d954SCole Faust 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*c217d954SCole Faust name##_stride_z, name##_step_z, name##_stride_w, name##_step_w, mod_size) 1069*c217d954SCole Faust 1070*c217d954SCole Faust#define CONVERT_TO_TENSOR4D_STRUCT_NO_STEP(name, mod_size) \ 1071*c217d954SCole Faust 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*c217d954SCole Faust 1073*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT_NO_UPDATE_PTR(name) \ 1074*c217d954SCole Faust 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*c217d954SCole Faust name##_stride_z, name##_step_z) 1076*c217d954SCole Faust 1077*c217d954SCole Faust 1078*c217d954SCole Fausttypedef struct Vector 1079*c217d954SCole Faust{ 1080*c217d954SCole Faust __global uchar *ptr; 1081*c217d954SCole Faust int offset_first_element_in_bytes; 1082*c217d954SCole Faust int stride_x; 1083*c217d954SCole Faust} Vector; 1084*c217d954SCole Faust 1085*c217d954SCole Faust 1086*c217d954SCole Fausttypedef struct Image 1087*c217d954SCole Faust{ 1088*c217d954SCole Faust __global uchar *ptr; 1089*c217d954SCole Faust int offset_first_element_in_bytes; 1090*c217d954SCole Faust int stride_x; 1091*c217d954SCole Faust int stride_y; 1092*c217d954SCole Faust} Image; 1093*c217d954SCole Faust 1094*c217d954SCole Faust 1095*c217d954SCole Fausttypedef struct Tensor3D 1096*c217d954SCole Faust{ 1097*c217d954SCole Faust __global uchar *ptr; 1098*c217d954SCole Faust int offset_first_element_in_bytes; 1099*c217d954SCole Faust int stride_x; 1100*c217d954SCole Faust int stride_y; 1101*c217d954SCole Faust int stride_z; 1102*c217d954SCole Faust} Tensor3D; 1103*c217d954SCole Faust 1104*c217d954SCole Faust 1105*c217d954SCole Fausttypedef struct Tensor4D 1106*c217d954SCole Faust{ 1107*c217d954SCole Faust __global uchar *ptr; 1108*c217d954SCole Faust int offset_first_element_in_bytes; 1109*c217d954SCole Faust int stride_x; 1110*c217d954SCole Faust int stride_y; 1111*c217d954SCole Faust int stride_z; 1112*c217d954SCole Faust int stride_w; 1113*c217d954SCole Faust} Tensor4D; 1114*c217d954SCole Faust 1115*c217d954SCole Faust 1116*c217d954SCole Faustinline Vector update_vector_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x) 1117*c217d954SCole Faust{ 1118*c217d954SCole Faust Vector vector = 1119*c217d954SCole Faust { 1120*c217d954SCole Faust .ptr = ptr, 1121*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1122*c217d954SCole Faust .stride_x = stride_x, 1123*c217d954SCole Faust }; 1124*c217d954SCole Faust vector.ptr += vector.offset_first_element_in_bytes + get_global_id(0) * step_x; 1125*c217d954SCole Faust return vector; 1126*c217d954SCole Faust} 1127*c217d954SCole Faust 1128*c217d954SCole Faust 1129*c217d954SCole Faustinline 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*c217d954SCole Faust{ 1131*c217d954SCole Faust Image img = 1132*c217d954SCole Faust { 1133*c217d954SCole Faust .ptr = ptr, 1134*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1135*c217d954SCole Faust .stride_x = stride_x, 1136*c217d954SCole Faust .stride_y = stride_y 1137*c217d954SCole Faust }; 1138*c217d954SCole Faust img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y; 1139*c217d954SCole Faust return img; 1140*c217d954SCole Faust} 1141*c217d954SCole Faust 1142*c217d954SCole Faust 1143*c217d954SCole Faustinline 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*c217d954SCole Faust{ 1145*c217d954SCole Faust Image img = 1146*c217d954SCole Faust { 1147*c217d954SCole Faust .ptr = ptr, 1148*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1149*c217d954SCole Faust .stride_x = stride_x, 1150*c217d954SCole Faust .stride_y = stride_y 1151*c217d954SCole Faust }; 1152*c217d954SCole Faust 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*c217d954SCole Faust return img; 1154*c217d954SCole Faust} 1155*c217d954SCole Faust 1156*c217d954SCole Faust 1157*c217d954SCole Faustinline 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*c217d954SCole Faust{ 1159*c217d954SCole Faust Tensor3D tensor = 1160*c217d954SCole Faust { 1161*c217d954SCole Faust .ptr = ptr, 1162*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1163*c217d954SCole Faust .stride_x = stride_x, 1164*c217d954SCole Faust .stride_y = stride_y, 1165*c217d954SCole Faust .stride_z = stride_z 1166*c217d954SCole Faust }; 1167*c217d954SCole Faust 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*c217d954SCole Faust return tensor; 1169*c217d954SCole Faust} 1170*c217d954SCole Faust 1171*c217d954SCole Faust 1172*c217d954SCole Faustinline 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*c217d954SCole Faust{ 1174*c217d954SCole Faust Tensor3D tensor = 1175*c217d954SCole Faust { 1176*c217d954SCole Faust .ptr = ptr, 1177*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1178*c217d954SCole Faust .stride_x = stride_x, 1179*c217d954SCole Faust .stride_y = stride_y, 1180*c217d954SCole Faust .stride_z = stride_z 1181*c217d954SCole Faust }; 1182*c217d954SCole Faust return tensor; 1183*c217d954SCole Faust} 1184*c217d954SCole Faust 1185*c217d954SCole Faustinline 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*c217d954SCole Faust uint step_w, 1187*c217d954SCole Faust uint mod_size) 1188*c217d954SCole Faust{ 1189*c217d954SCole Faust Tensor4D tensor = 1190*c217d954SCole Faust { 1191*c217d954SCole Faust .ptr = ptr, 1192*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 1193*c217d954SCole Faust .stride_x = stride_x, 1194*c217d954SCole Faust .stride_y = stride_y, 1195*c217d954SCole Faust .stride_z = stride_z, 1196*c217d954SCole Faust .stride_w = stride_w 1197*c217d954SCole Faust }; 1198*c217d954SCole Faust 1199*c217d954SCole Faust 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*c217d954SCole Faust return tensor; 1201*c217d954SCole Faust} 1202*c217d954SCole Faust 1203*c217d954SCole Faust 1204*c217d954SCole Faustinline __global const uchar *vector_offset(const Vector *vec, int x) 1205*c217d954SCole Faust{ 1206*c217d954SCole Faust return vec->ptr + x * vec->stride_x; 1207*c217d954SCole Faust} 1208*c217d954SCole Faust 1209*c217d954SCole Faust 1210*c217d954SCole Faustinline __global uchar *offset(const Image *img, int x, int y) 1211*c217d954SCole Faust{ 1212*c217d954SCole Faust return img->ptr + x * img->stride_x + y * img->stride_y; 1213*c217d954SCole Faust} 1214*c217d954SCole Faust 1215*c217d954SCole Faust 1216*c217d954SCole Faustinline __global const uchar *tensor3D_offset(const Tensor3D *tensor, int x, int y, int z) 1217*c217d954SCole Faust{ 1218*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z; 1219*c217d954SCole Faust} 1220*c217d954SCole Faust 1221*c217d954SCole Faust 1222*c217d954SCole Faustinline __global const uchar *tensor4D_offset(const Tensor4D *tensor, int x, int y, int z, int w) 1223*c217d954SCole Faust{ 1224*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + w * tensor->stride_w; 1225*c217d954SCole Faust} 1226*c217d954SCole Faust 1227*c217d954SCole Faust 1228*c217d954SCole Faustinline __global const uchar *tensor3D_index2ptr(const Tensor3D *tensor, uint width, uint height, uint depth, uint index) 1229*c217d954SCole Faust{ 1230*c217d954SCole Faust uint num_elements = width * height; 1231*c217d954SCole Faust 1232*c217d954SCole Faust const uint z = index / num_elements; 1233*c217d954SCole Faust 1234*c217d954SCole Faust index %= num_elements; 1235*c217d954SCole Faust 1236*c217d954SCole Faust const uint y = index / width; 1237*c217d954SCole Faust 1238*c217d954SCole Faust index %= width; 1239*c217d954SCole Faust 1240*c217d954SCole Faust const uint x = index; 1241*c217d954SCole Faust 1242*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + tensor->offset_first_element_in_bytes; 1243*c217d954SCole Faust} 1244*c217d954SCole Faust 1245*c217d954SCole Faust#endif 1246*c217d954SCole Faust 1247*c217d954SCole Faust#ifndef ARM_COMPUTE_REPEAT_H 1248*c217d954SCole Faust#define ARM_COMPUTE_REPEAT_H 1249*c217d954SCole Faust 1250*c217d954SCole Faust 1251*c217d954SCole Faust#ifndef ARM_COMPUTE_HELPER_H 1252*c217d954SCole Faust#define ARM_COMPUTE_HELPER_H 1253*c217d954SCole Faust 1254*c217d954SCole Faust 1255*c217d954SCole Faust 1256*c217d954SCole Faust 1257*c217d954SCole Faust#define STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1258*c217d954SCole Faust VSTORE(N0) \ 1259*c217d954SCole Faust (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 1260*c217d954SCole Faust 1261*c217d954SCole Faust#define STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1262*c217d954SCole Faust STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1263*c217d954SCole Faust VSTORE(N0) \ 1264*c217d954SCole Faust (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 1265*c217d954SCole Faust 1266*c217d954SCole Faust#define STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1267*c217d954SCole Faust STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1268*c217d954SCole Faust VSTORE(N0) \ 1269*c217d954SCole Faust (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 1270*c217d954SCole Faust 1271*c217d954SCole Faust#define STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1272*c217d954SCole Faust STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1273*c217d954SCole Faust VSTORE(N0) \ 1274*c217d954SCole Faust (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 1275*c217d954SCole Faust 1276*c217d954SCole Faust#define STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1277*c217d954SCole Faust STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1278*c217d954SCole Faust VSTORE(N0) \ 1279*c217d954SCole Faust (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 1280*c217d954SCole Faust 1281*c217d954SCole Faust#define STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1282*c217d954SCole Faust STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1283*c217d954SCole Faust VSTORE(N0) \ 1284*c217d954SCole Faust (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 1285*c217d954SCole Faust 1286*c217d954SCole Faust#define STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1287*c217d954SCole Faust STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1288*c217d954SCole Faust VSTORE(N0) \ 1289*c217d954SCole Faust (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 1290*c217d954SCole Faust 1291*c217d954SCole Faust#define STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1292*c217d954SCole Faust STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1293*c217d954SCole Faust VSTORE(N0) \ 1294*c217d954SCole Faust (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 1295*c217d954SCole Faust 1296*c217d954SCole Faust#define STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1297*c217d954SCole Faust STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1298*c217d954SCole Faust VSTORE(N0) \ 1299*c217d954SCole Faust (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 1300*c217d954SCole Faust 1301*c217d954SCole Faust#define STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1302*c217d954SCole Faust STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1303*c217d954SCole Faust VSTORE(N0) \ 1304*c217d954SCole Faust (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 1305*c217d954SCole Faust 1306*c217d954SCole Faust#define STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1307*c217d954SCole Faust STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1308*c217d954SCole Faust VSTORE(N0) \ 1309*c217d954SCole Faust (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 1310*c217d954SCole Faust 1311*c217d954SCole Faust#define STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1312*c217d954SCole Faust STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1313*c217d954SCole Faust VSTORE(N0) \ 1314*c217d954SCole Faust (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 1315*c217d954SCole Faust 1316*c217d954SCole Faust#define STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1317*c217d954SCole Faust STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1318*c217d954SCole Faust VSTORE(N0) \ 1319*c217d954SCole Faust (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 1320*c217d954SCole Faust 1321*c217d954SCole Faust#define STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1322*c217d954SCole Faust STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1323*c217d954SCole Faust VSTORE(N0) \ 1324*c217d954SCole Faust (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 1325*c217d954SCole Faust 1326*c217d954SCole Faust#define STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1327*c217d954SCole Faust STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1328*c217d954SCole Faust VSTORE(N0) \ 1329*c217d954SCole Faust (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 1330*c217d954SCole Faust 1331*c217d954SCole Faust#define STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1332*c217d954SCole Faust STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1333*c217d954SCole Faust VSTORE(N0) \ 1334*c217d954SCole Faust (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 1335*c217d954SCole Faust 1336*c217d954SCole Faust 1337*c217d954SCole Faust 1338*c217d954SCole Faust#define CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1339*c217d954SCole Faust VSTORE(N0) \ 1340*c217d954SCole Faust (CONVERT_SAT((BASENAME##0), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 1341*c217d954SCole Faust 1342*c217d954SCole Faust#define CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1343*c217d954SCole Faust CONVERT_STORE_ROW_1(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1344*c217d954SCole Faust VSTORE(N0) \ 1345*c217d954SCole Faust (CONVERT_SAT((BASENAME##1), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 1346*c217d954SCole Faust 1347*c217d954SCole Faust#define CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1348*c217d954SCole Faust CONVERT_STORE_ROW_2(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1349*c217d954SCole Faust VSTORE(N0) \ 1350*c217d954SCole Faust (CONVERT_SAT((BASENAME##2), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 1351*c217d954SCole Faust 1352*c217d954SCole Faust#define CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1353*c217d954SCole Faust CONVERT_STORE_ROW_3(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1354*c217d954SCole Faust VSTORE(N0) \ 1355*c217d954SCole Faust (CONVERT_SAT((BASENAME##3), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 1356*c217d954SCole Faust 1357*c217d954SCole Faust#define CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1358*c217d954SCole Faust CONVERT_STORE_ROW_4(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1359*c217d954SCole Faust VSTORE(N0) \ 1360*c217d954SCole Faust (CONVERT_SAT((BASENAME##4), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 1361*c217d954SCole Faust 1362*c217d954SCole Faust#define CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1363*c217d954SCole Faust CONVERT_STORE_ROW_5(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1364*c217d954SCole Faust VSTORE(N0) \ 1365*c217d954SCole Faust (CONVERT_SAT((BASENAME##5), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 1366*c217d954SCole Faust 1367*c217d954SCole Faust#define CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1368*c217d954SCole Faust CONVERT_STORE_ROW_6(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1369*c217d954SCole Faust VSTORE(N0) \ 1370*c217d954SCole Faust (CONVERT_SAT((BASENAME##6), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 1371*c217d954SCole Faust 1372*c217d954SCole Faust#define CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1373*c217d954SCole Faust CONVERT_STORE_ROW_7(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1374*c217d954SCole Faust VSTORE(N0) \ 1375*c217d954SCole Faust (CONVERT_SAT((BASENAME##7), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 1376*c217d954SCole Faust 1377*c217d954SCole Faust#define CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1378*c217d954SCole Faust CONVERT_STORE_ROW_8(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1379*c217d954SCole Faust VSTORE(N0) \ 1380*c217d954SCole Faust (CONVERT_SAT((BASENAME##8), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 1381*c217d954SCole Faust 1382*c217d954SCole Faust#define CONVERT_STORE_ROW_10(N0, DATA, BASENAME, PTR, STRIDE_Y, Z) \ 1383*c217d954SCole Faust CONVERT_STORE_ROW_9(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1384*c217d954SCole Faust VSTORE(N0) \ 1385*c217d954SCole Faust (CONVERT_SAT((BASENAME##9), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 1386*c217d954SCole Faust 1387*c217d954SCole Faust#define CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1388*c217d954SCole Faust CONVERT_STORE_ROW_10(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1389*c217d954SCole Faust VSTORE(N0) \ 1390*c217d954SCole Faust (CONVERT_SAT((BASENAME##A), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 1391*c217d954SCole Faust 1392*c217d954SCole Faust#define CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1393*c217d954SCole Faust CONVERT_STORE_ROW_11(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1394*c217d954SCole Faust VSTORE(N0) \ 1395*c217d954SCole Faust (CONVERT_SAT((BASENAME##B), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 1396*c217d954SCole Faust 1397*c217d954SCole Faust#define CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1398*c217d954SCole Faust CONVERT_STORE_ROW_12(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1399*c217d954SCole Faust VSTORE(N0) \ 1400*c217d954SCole Faust (CONVERT_SAT((BASENAME##C), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 1401*c217d954SCole Faust 1402*c217d954SCole Faust#define CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1403*c217d954SCole Faust CONVERT_STORE_ROW_13(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1404*c217d954SCole Faust VSTORE(N0) \ 1405*c217d954SCole Faust (CONVERT_SAT((BASENAME##D), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 1406*c217d954SCole Faust 1407*c217d954SCole Faust#define CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1408*c217d954SCole Faust CONVERT_STORE_ROW_14(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1409*c217d954SCole Faust VSTORE(N0) \ 1410*c217d954SCole Faust (CONVERT_SAT((BASENAME##E), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 1411*c217d954SCole Faust 1412*c217d954SCole Faust#define CONVERT_STORE_ROW_16(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1413*c217d954SCole Faust CONVERT_STORE_ROW_15(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1414*c217d954SCole Faust VSTORE(N0) \ 1415*c217d954SCole Faust (CONVERT_SAT((BASENAME##F), VEC_DATA_TYPE(DATA_TYPE, N0)), 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 1416*c217d954SCole Faust 1417*c217d954SCole Faust 1418*c217d954SCole Faust 1419*c217d954SCole Faust 1420*c217d954SCole Faust#define STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_ROW_##M0(N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 1421*c217d954SCole Faust#define STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) STORE_BLOCK_STR(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 1422*c217d954SCole Faust 1423*c217d954SCole Faust 1424*c217d954SCole Faust 1425*c217d954SCole Faust#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) 1426*c217d954SCole Faust#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) 1427*c217d954SCole Faust 1428*c217d954SCole Faust 1429*c217d954SCole Faust 1430*c217d954SCole Faust#define STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1431*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1432*c217d954SCole Faust (BASENAME##0, 0, (__global DATA_TYPE *)(PTR + 0 * STRIDE_Y + Z##0)); 1433*c217d954SCole Faust 1434*c217d954SCole Faust#define STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1435*c217d954SCole Faust STORE_ROW_PARTIAL_1(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1436*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1437*c217d954SCole Faust (BASENAME##1, 0, (__global DATA_TYPE *)(PTR + 1 * STRIDE_Y + Z##1)); 1438*c217d954SCole Faust 1439*c217d954SCole Faust#define STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1440*c217d954SCole Faust STORE_ROW_PARTIAL_2(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1441*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1442*c217d954SCole Faust (BASENAME##2, 0, (__global DATA_TYPE *)(PTR + 2 * STRIDE_Y + Z##2)); 1443*c217d954SCole Faust 1444*c217d954SCole Faust#define STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1445*c217d954SCole Faust STORE_ROW_PARTIAL_3(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1446*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1447*c217d954SCole Faust (BASENAME##3, 0, (__global DATA_TYPE *)(PTR + 3 * STRIDE_Y + Z##3)); 1448*c217d954SCole Faust 1449*c217d954SCole Faust#define STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1450*c217d954SCole Faust STORE_ROW_PARTIAL_4(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1451*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1452*c217d954SCole Faust (BASENAME##4, 0, (__global DATA_TYPE *)(PTR + 4 * STRIDE_Y + Z##4)); 1453*c217d954SCole Faust 1454*c217d954SCole Faust#define STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1455*c217d954SCole Faust STORE_ROW_PARTIAL_5(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1456*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1457*c217d954SCole Faust (BASENAME##5, 0, (__global DATA_TYPE *)(PTR + 5 * STRIDE_Y + Z##5)); 1458*c217d954SCole Faust 1459*c217d954SCole Faust#define STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1460*c217d954SCole Faust STORE_ROW_PARTIAL_6(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1461*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1462*c217d954SCole Faust (BASENAME##6, 0, (__global DATA_TYPE *)(PTR + 6 * STRIDE_Y + Z##6)); 1463*c217d954SCole Faust 1464*c217d954SCole Faust#define STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1465*c217d954SCole Faust STORE_ROW_PARTIAL_7(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1466*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1467*c217d954SCole Faust (BASENAME##7, 0, (__global DATA_TYPE *)(PTR + 7 * STRIDE_Y + Z##7)); 1468*c217d954SCole Faust 1469*c217d954SCole Faust#define STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1470*c217d954SCole Faust STORE_ROW_PARTIAL_8(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1471*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1472*c217d954SCole Faust (BASENAME##8, 0, (__global DATA_TYPE *)(PTR + 8 * STRIDE_Y + Z##8)); 1473*c217d954SCole Faust 1474*c217d954SCole Faust#define STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1475*c217d954SCole Faust STORE_ROW_PARTIAL_9(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1476*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1477*c217d954SCole Faust (BASENAME##9, 0, (__global DATA_TYPE *)(PTR + 9 * STRIDE_Y + Z##9)); 1478*c217d954SCole Faust 1479*c217d954SCole Faust#define STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1480*c217d954SCole Faust STORE_ROW_PARTIAL_10(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1481*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1482*c217d954SCole Faust (BASENAME##A, 0, (__global DATA_TYPE *)(PTR + 10 * STRIDE_Y + Z##A)); 1483*c217d954SCole Faust 1484*c217d954SCole Faust#define STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1485*c217d954SCole Faust STORE_ROW_PARTIAL_11(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1486*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1487*c217d954SCole Faust (BASENAME##B, 0, (__global DATA_TYPE *)(PTR + 11 * STRIDE_Y + Z##B)); 1488*c217d954SCole Faust 1489*c217d954SCole Faust#define STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1490*c217d954SCole Faust STORE_ROW_PARTIAL_12(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1491*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1492*c217d954SCole Faust (BASENAME##C, 0, (__global DATA_TYPE *)(PTR + 12 * STRIDE_Y + Z##C)); 1493*c217d954SCole Faust 1494*c217d954SCole Faust#define STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1495*c217d954SCole Faust STORE_ROW_PARTIAL_13(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1496*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1497*c217d954SCole Faust (BASENAME##D, 0, (__global DATA_TYPE *)(PTR + 13 * STRIDE_Y + Z##D)); 1498*c217d954SCole Faust 1499*c217d954SCole Faust#define STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1500*c217d954SCole Faust STORE_ROW_PARTIAL_14(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1501*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1502*c217d954SCole Faust (BASENAME##E, 0, (__global DATA_TYPE *)(PTR + 14 * STRIDE_Y + Z##E)); 1503*c217d954SCole Faust 1504*c217d954SCole Faust#define STORE_ROW_PARTIAL_16(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1505*c217d954SCole Faust STORE_ROW_PARTIAL_15(N0, STORE_N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) \ 1506*c217d954SCole Faust VSTORE_PARTIAL(N0, STORE_N0) \ 1507*c217d954SCole Faust (BASENAME##F, 0, (__global DATA_TYPE *)(PTR + 15 * STRIDE_Y + Z##F)); 1508*c217d954SCole Faust 1509*c217d954SCole Faust 1510*c217d954SCole Faust 1511*c217d954SCole Faust#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) 1512*c217d954SCole Faust#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) 1513*c217d954SCole Faust 1514*c217d954SCole Faust#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) \ 1515*c217d954SCole Faust if(!(PARTIAL_COND_X) && !(PARTIAL_COND_Y)) \ 1516*c217d954SCole Faust { \ 1517*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1518*c217d954SCole Faust } \ 1519*c217d954SCole Faust else if((PARTIAL_COND_Y) && !(PARTIAL_COND_X)) \ 1520*c217d954SCole Faust { \ 1521*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1522*c217d954SCole Faust } \ 1523*c217d954SCole Faust else if(!(PARTIAL_COND_Y) && (PARTIAL_COND_X)) \ 1524*c217d954SCole Faust { \ 1525*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1526*c217d954SCole Faust } \ 1527*c217d954SCole Faust else \ 1528*c217d954SCole Faust { \ 1529*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1530*c217d954SCole Faust } 1531*c217d954SCole Faust 1532*c217d954SCole Faust#define STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) \ 1533*c217d954SCole Faust if(!(PARTIAL_COND_X)) \ 1534*c217d954SCole Faust { \ 1535*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1536*c217d954SCole Faust } \ 1537*c217d954SCole Faust else \ 1538*c217d954SCole Faust { \ 1539*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, PARTIAL_STORE_N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1540*c217d954SCole Faust } 1541*c217d954SCole Faust 1542*c217d954SCole Faust#define STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) \ 1543*c217d954SCole Faust if(!(PARTIAL_COND_Y)) \ 1544*c217d954SCole Faust { \ 1545*c217d954SCole Faust STORE_BLOCK_PARTIAL(M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1546*c217d954SCole Faust } \ 1547*c217d954SCole Faust else \ 1548*c217d954SCole Faust { \ 1549*c217d954SCole Faust STORE_BLOCK_PARTIAL(PARTIAL_STORE_M0, N0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z); \ 1550*c217d954SCole Faust } 1551*c217d954SCole Faust 1552*c217d954SCole Faust 1553*c217d954SCole Faust#if defined(PARTIAL_STORE_M0) && defined(PARTIAL_STORE_N0) 1554*c217d954SCole Faust 1555*c217d954SCole Faust 1556*c217d954SCole Faust#if PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 == 0 1557*c217d954SCole Faust 1558*c217d954SCole Faust#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) \ 1559*c217d954SCole Faust STORE_BLOCK(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z) 1560*c217d954SCole Faust 1561*c217d954SCole Faust#elif PARTIAL_STORE_M0 > 0 && PARTIAL_STORE_N0 == 0 1562*c217d954SCole Faust 1563*c217d954SCole Faust#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) \ 1564*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_Y(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_M0, PARTIAL_COND_Y) 1565*c217d954SCole Faust 1566*c217d954SCole Faust#elif PARTIAL_STORE_M0 == 0 && PARTIAL_STORE_N0 > 0 1567*c217d954SCole Faust 1568*c217d954SCole Faust#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) \ 1569*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_X(M0, N0, DATA_TYPE, BASENAME, PTR, STRIDE_Y, Z, PARTIAL_STORE_N0, PARTIAL_COND_X) 1570*c217d954SCole Faust 1571*c217d954SCole Faust#else 1572*c217d954SCole Faust 1573*c217d954SCole Faust#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) \ 1574*c217d954SCole Faust 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) 1575*c217d954SCole Faust 1576*c217d954SCole Faust#endif 1577*c217d954SCole Faust 1578*c217d954SCole Faust#endif 1579*c217d954SCole Faust 1580*c217d954SCole Faust 1581*c217d954SCole Faust#if defined(PARTIAL_STORE_M0) 1582*c217d954SCole Faust 1583*c217d954SCole Faust#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 1584*c217d954SCole Faust ((uint)(max(0, (int)(y * M0) - (int)((M0 - PARTIAL_STORE_M0) % M0)))) 1585*c217d954SCole Faust#else 1586*c217d954SCole Faust#define COMPUTE_M0_START_ROW(y, M0, PARTIAL_STORE_M0) \ 1587*c217d954SCole Faust ((uint)(y * M0)) 1588*c217d954SCole Faust#endif 1589*c217d954SCole Faust 1590*c217d954SCole Faust 1591*c217d954SCole Faust 1592*c217d954SCole Faust#define STORE_VECTOR_SELECT(basename, data_type, ptr, vec_size, leftover, cond) \ 1593*c217d954SCole Faust STORE_BLOCK_PARTIAL_IN_X(1, vec_size, data_type, basename, ptr, 0, 0, leftover, cond) 1594*c217d954SCole Faust 1595*c217d954SCole Faust 1596*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 1597*c217d954SCole Faust#pragma OPENCL EXTENSION cl_khr_fp16 : enable 1598*c217d954SCole Faust#endif 1599*c217d954SCole Faust 1600*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) 1601*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable 1602*c217d954SCole Faust#endif 1603*c217d954SCole Faust 1604*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) 1605*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable 1606*c217d954SCole Faust#endif 1607*c217d954SCole Faust 1608*c217d954SCole Faust#if defined(ARM_COMPUTE_DEBUG_ENABLED) && defined(cl_arm_printf) 1609*c217d954SCole Faust#pragma OPENCL EXTENSION cl_arm_printf : enable 1610*c217d954SCole Faust#endif 1611*c217d954SCole Faust 1612*c217d954SCole Faust#define GPU_ARCH_MIDGARD 0x100 1613*c217d954SCole Faust#define GPU_ARCH_BIFROST 0x200 1614*c217d954SCole Faust#define GPU_ARCH_VALHALL 0x300 1615*c217d954SCole Faust 1616*c217d954SCole Faust 1617*c217d954SCole Faust#define CONCAT(a, b) a##b 1618*c217d954SCole Faust 1619*c217d954SCole Faust 1620*c217d954SCole Faust#define EXPAND(x) x 1621*c217d954SCole Faust 1622*c217d954SCole Faust 1623*c217d954SCole Faust#define CLAMP(x, min_val, max_val) min(max(x, min_val), max_val) 1624*c217d954SCole Faust 1625*c217d954SCole Faust 1626*c217d954SCole Faust#define REV1(x) ((x)) 1627*c217d954SCole Faust#define REV2(x) ((x).s10) 1628*c217d954SCole Faust#define REV3(x) ((x).s210) 1629*c217d954SCole Faust#define REV4(x) ((x).s3210) 1630*c217d954SCole Faust#define REV8(x) ((x).s76543210) 1631*c217d954SCole Faust#define REV16(x) ((x).sFEDCBA9876543210) 1632*c217d954SCole Faust 1633*c217d954SCole Faust 1634*c217d954SCole Faust 1635*c217d954SCole Faust#define REVERSE_STR(x, s) REV##s((x)) 1636*c217d954SCole Faust#define REVERSE(x, s) REVERSE_STR(x, s) 1637*c217d954SCole Faust 1638*c217d954SCole Faust 1639*c217d954SCole Faust 1640*c217d954SCole Faust#define ROT1_0(x) ((x)) 1641*c217d954SCole Faust#define ROT1_1(x) ((x)) 1642*c217d954SCole Faust 1643*c217d954SCole Faust#define ROT2_0(x) ((x)) 1644*c217d954SCole Faust#define ROT2_1(x) ((x).s10) 1645*c217d954SCole Faust#define ROT2_2(x) ((x)) 1646*c217d954SCole Faust 1647*c217d954SCole Faust#define ROT3_0(x) ((x)) 1648*c217d954SCole Faust#define ROT3_1(x) ((x).s201) 1649*c217d954SCole Faust#define ROT3_2(x) ((x).s120) 1650*c217d954SCole Faust#define ROT3_3(x) ((x)) 1651*c217d954SCole Faust 1652*c217d954SCole Faust#define ROT4_0(x) ((x)) 1653*c217d954SCole Faust#define ROT4_1(x) ((x).s3012) 1654*c217d954SCole Faust#define ROT4_2(x) ((x).s2301) 1655*c217d954SCole Faust#define ROT4_3(x) ((x).s1230) 1656*c217d954SCole Faust#define ROT4_4(x) ((x)) 1657*c217d954SCole Faust 1658*c217d954SCole Faust#define ROT8_0(x) ((x)) 1659*c217d954SCole Faust#define ROT8_1(x) ((x).s70123456) 1660*c217d954SCole Faust#define ROT8_2(x) ((x).s67012345) 1661*c217d954SCole Faust#define ROT8_3(x) ((x).s56701234) 1662*c217d954SCole Faust#define ROT8_4(x) ((x).s45670123) 1663*c217d954SCole Faust#define ROT8_5(x) ((x).s34567012) 1664*c217d954SCole Faust#define ROT8_6(x) ((x).s23456701) 1665*c217d954SCole Faust#define ROT8_7(x) ((x).s12345670) 1666*c217d954SCole Faust#define ROT8_8(x) ((x)) 1667*c217d954SCole Faust 1668*c217d954SCole Faust#define ROT16_0(x) ((x)) 1669*c217d954SCole Faust#define ROT16_1(x) ((x).sF0123456789ABCDE) 1670*c217d954SCole Faust#define ROT16_2(x) ((x).sEF0123456789ABCD) 1671*c217d954SCole Faust#define ROT16_3(x) ((x).sDEF0123456789ABC) 1672*c217d954SCole Faust#define ROT16_4(x) ((x).sCDEF0123456789AB) 1673*c217d954SCole Faust#define ROT16_5(x) ((x).sBCDEF0123456789A) 1674*c217d954SCole Faust#define ROT16_6(x) ((x).sABCDEF0123456789) 1675*c217d954SCole Faust#define ROT16_7(x) ((x).s9ABCDEF012345678) 1676*c217d954SCole Faust#define ROT16_8(x) ((x).s89ABCDEF01234567) 1677*c217d954SCole Faust#define ROT16_9(x) ((x).s789ABCDEF0123456) 1678*c217d954SCole Faust#define ROT16_10(x) ((x).s6789ABCDEF012345) 1679*c217d954SCole Faust#define ROT16_11(x) ((x).s56789ABCDEF01234) 1680*c217d954SCole Faust#define ROT16_12(x) ((x).s456789ABCDEF0123) 1681*c217d954SCole Faust#define ROT16_13(x) ((x).s3456789ABCDEF012) 1682*c217d954SCole Faust#define ROT16_14(x) ((x).s23456789ABCDEF01) 1683*c217d954SCole Faust#define ROT16_15(x) ((x).s123456789ABCDEF0) 1684*c217d954SCole Faust#define ROT16_16(x) ((x)) 1685*c217d954SCole Faust 1686*c217d954SCole Faust 1687*c217d954SCole Faust 1688*c217d954SCole Faust#define ROTATE_STR(x, s, n) ROT##s##_##n(x) 1689*c217d954SCole Faust#define ROTATE(x, s, n) ROTATE_STR(x, s, n) 1690*c217d954SCole Faust 1691*c217d954SCole Faust 1692*c217d954SCole Faust 1693*c217d954SCole Faust#define V_OFFS1(dt) (dt##1)(0) 1694*c217d954SCole Faust#define V_OFFS2(dt) (dt##2)(0, 1) 1695*c217d954SCole Faust#define V_OFFS3(dt) (dt##3)(0, 1, 2) 1696*c217d954SCole Faust#define V_OFFS4(dt) (dt##4)(0, 1, 2, 3) 1697*c217d954SCole Faust#define V_OFFS8(dt) (dt##8)(0, 1, 2, 3, 4, 5, 6, 7) 1698*c217d954SCole Faust#define V_OFFS16(dt) (dt##16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) 1699*c217d954SCole Faust 1700*c217d954SCole Faust 1701*c217d954SCole Faust 1702*c217d954SCole Faust#define VEC_OFFS_STR(dt, s) V_OFFS##s(dt) 1703*c217d954SCole Faust#define VEC_OFFS(dt, s) VEC_OFFS_STR(dt, s) 1704*c217d954SCole Faust 1705*c217d954SCole Faust 1706*c217d954SCole Faust#define VLOAD_STR(size) vload##size 1707*c217d954SCole Faust#define VLOAD(size) VLOAD_STR(size) 1708*c217d954SCole Faust 1709*c217d954SCole Faust 1710*c217d954SCole Faust#define VLOAD_PARTIAL_STR(size, load_size) vload_partial_##size##_##load_size 1711*c217d954SCole Faust#define VLOAD_PARTIAL(size, load_size) VLOAD_PARTIAL_STR(size, load_size) 1712*c217d954SCole Faust 1713*c217d954SCole Faust#define NO_LOAD(data, offs, ptr) \ 1714*c217d954SCole Faust { \ 1715*c217d954SCole Faust } 1716*c217d954SCole Faust 1717*c217d954SCole Faust 1718*c217d954SCole Faust#define vload_partial_1_0 NO_LOAD 1719*c217d954SCole Faust#define vload_partial_1_1 vload1 1720*c217d954SCole Faust#define vload_partial_1_2 NO_LOAD 1721*c217d954SCole Faust#define vload_partial_1_3 NO_LOAD 1722*c217d954SCole Faust#define vload_partial_1_4 NO_LOAD 1723*c217d954SCole Faust#define vload_partial_1_5 NO_LOAD 1724*c217d954SCole Faust#define vload_partial_1_6 NO_LOAD 1725*c217d954SCole Faust#define vload_partial_1_7 NO_LOAD 1726*c217d954SCole Faust#define vload_partial_1_8 NO_LOAD 1727*c217d954SCole Faust#define vload_partial_1_9 NO_LOAD 1728*c217d954SCole Faust#define vload_partial_1_10 NO_LOAD 1729*c217d954SCole Faust#define vload_partial_1_11 NO_LOAD 1730*c217d954SCole Faust#define vload_partial_1_12 NO_LOAD 1731*c217d954SCole Faust#define vload_partial_1_13 NO_LOAD 1732*c217d954SCole Faust#define vload_partial_1_14 NO_LOAD 1733*c217d954SCole Faust#define vload_partial_1_15 NO_LOAD 1734*c217d954SCole Faust#define vload_partial_1_16 NO_LOAD 1735*c217d954SCole Faust 1736*c217d954SCole Faust#define vload_partial_2_0 NO_LOAD 1737*c217d954SCole Faust#define vload_partial_2_1 vload_partial_1 1738*c217d954SCole Faust#define vload_partial_2_2 vload_partial_2 1739*c217d954SCole Faust#define vload_partial_2_3 NO_LOAD 1740*c217d954SCole Faust#define vload_partial_2_4 NO_LOAD 1741*c217d954SCole Faust#define vload_partial_2_5 NO_LOAD 1742*c217d954SCole Faust#define vload_partial_2_6 NO_LOAD 1743*c217d954SCole Faust#define vload_partial_2_7 NO_LOAD 1744*c217d954SCole Faust#define vload_partial_2_8 NO_LOAD 1745*c217d954SCole Faust#define vload_partial_2_9 NO_LOAD 1746*c217d954SCole Faust#define vload_partial_2_10 NO_LOAD 1747*c217d954SCole Faust#define vload_partial_2_11 NO_LOAD 1748*c217d954SCole Faust#define vload_partial_2_12 NO_LOAD 1749*c217d954SCole Faust#define vload_partial_2_13 NO_LOAD 1750*c217d954SCole Faust#define vload_partial_2_14 NO_LOAD 1751*c217d954SCole Faust#define vload_partial_2_15 NO_LOAD 1752*c217d954SCole Faust#define vload_partial_2_16 NO_LOAD 1753*c217d954SCole Faust 1754*c217d954SCole Faust#define vload_partial_3_0 NO_LOAD 1755*c217d954SCole Faust#define vload_partial_3_1 vload_partial_1 1756*c217d954SCole Faust#define vload_partial_3_2 vload_partial_2 1757*c217d954SCole Faust#define vload_partial_3_3 vload_partial_3 1758*c217d954SCole Faust#define vload_partial_3_4 NO_LOAD 1759*c217d954SCole Faust#define vload_partial_3_5 NO_LOAD 1760*c217d954SCole Faust#define vload_partial_3_6 NO_LOAD 1761*c217d954SCole Faust#define vload_partial_3_7 NO_LOAD 1762*c217d954SCole Faust#define vload_partial_3_8 NO_LOAD 1763*c217d954SCole Faust#define vload_partial_3_9 NO_LOAD 1764*c217d954SCole Faust#define vload_partial_3_10 NO_LOAD 1765*c217d954SCole Faust#define vload_partial_3_11 NO_LOAD 1766*c217d954SCole Faust#define vload_partial_3_12 NO_LOAD 1767*c217d954SCole Faust#define vload_partial_3_13 NO_LOAD 1768*c217d954SCole Faust#define vload_partial_3_14 NO_LOAD 1769*c217d954SCole Faust#define vload_partial_3_15 NO_LOAD 1770*c217d954SCole Faust#define vload_partial_3_16 NO_LOAD 1771*c217d954SCole Faust 1772*c217d954SCole Faust#define vload_partial_4_0 NO_LOAD 1773*c217d954SCole Faust#define vload_partial_4_1 vload_partial_1 1774*c217d954SCole Faust#define vload_partial_4_2 vload_partial_2 1775*c217d954SCole Faust#define vload_partial_4_3 vload_partial_3 1776*c217d954SCole Faust#define vload_partial_4_4 vload_partial_4 1777*c217d954SCole Faust#define vload_partial_4_5 NO_LOAD 1778*c217d954SCole Faust#define vload_partial_4_6 NO_LOAD 1779*c217d954SCole Faust#define vload_partial_4_7 NO_LOAD 1780*c217d954SCole Faust#define vload_partial_4_8 NO_LOAD 1781*c217d954SCole Faust#define vload_partial_4_9 NO_LOAD 1782*c217d954SCole Faust#define vload_partial_4_10 NO_LOAD 1783*c217d954SCole Faust#define vload_partial_4_11 NO_LOAD 1784*c217d954SCole Faust#define vload_partial_4_12 NO_LOAD 1785*c217d954SCole Faust#define vload_partial_4_13 NO_LOAD 1786*c217d954SCole Faust#define vload_partial_4_14 NO_LOAD 1787*c217d954SCole Faust#define vload_partial_4_15 NO_LOAD 1788*c217d954SCole Faust#define vload_partial_4_16 NO_LOAD 1789*c217d954SCole Faust 1790*c217d954SCole Faust#define vload_partial_8_0 NO_LOAD 1791*c217d954SCole Faust#define vload_partial_8_1 vload_partial_1 1792*c217d954SCole Faust#define vload_partial_8_2 vload_partial_2 1793*c217d954SCole Faust#define vload_partial_8_3 vload_partial_3 1794*c217d954SCole Faust#define vload_partial_8_4 vload_partial_4 1795*c217d954SCole Faust#define vload_partial_8_5 vload_partial_5 1796*c217d954SCole Faust#define vload_partial_8_6 vload_partial_6 1797*c217d954SCole Faust#define vload_partial_8_7 vload_partial_7 1798*c217d954SCole Faust#define vload_partial_8_8 vload_partial_8 1799*c217d954SCole Faust#define vload_partial_8_9 NO_LOAD 1800*c217d954SCole Faust#define vload_partial_8_10 NO_LOAD 1801*c217d954SCole Faust#define vload_partial_8_11 NO_LOAD 1802*c217d954SCole Faust#define vload_partial_8_12 NO_LOAD 1803*c217d954SCole Faust#define vload_partial_8_13 NO_LOAD 1804*c217d954SCole Faust#define vload_partial_8_14 NO_LOAD 1805*c217d954SCole Faust#define vload_partial_8_15 NO_LOAD 1806*c217d954SCole Faust#define vload_partial_8_16 NO_LOAD 1807*c217d954SCole Faust 1808*c217d954SCole Faust#define vload_partial_16_0 NO_LOAD 1809*c217d954SCole Faust#define vload_partial_16_1 vload_partial_1 1810*c217d954SCole Faust#define vload_partial_16_2 vload_partial_2 1811*c217d954SCole Faust#define vload_partial_16_3 vload_partial_3 1812*c217d954SCole Faust#define vload_partial_16_4 vload_partial_4 1813*c217d954SCole Faust#define vload_partial_16_5 vload_partial_5 1814*c217d954SCole Faust#define vload_partial_16_6 vload_partial_6 1815*c217d954SCole Faust#define vload_partial_16_7 vload_partial_7 1816*c217d954SCole Faust#define vload_partial_16_8 vload_partial_8 1817*c217d954SCole Faust#define vload_partial_16_9 vload_partial_9 1818*c217d954SCole Faust#define vload_partial_16_10 vload_partial_10 1819*c217d954SCole Faust#define vload_partial_16_11 vload_partial_11 1820*c217d954SCole Faust#define vload_partial_16_12 vload_partial_12 1821*c217d954SCole Faust#define vload_partial_16_13 vload_partial_13 1822*c217d954SCole Faust#define vload_partial_16_14 vload_partial_14 1823*c217d954SCole Faust#define vload_partial_16_15 vload_partial_15 1824*c217d954SCole Faust#define vload_partial_16_16 vload_partial_16 1825*c217d954SCole Faust 1826*c217d954SCole Faust 1827*c217d954SCole Faust#define vload_partial_1(DATA, OFFSET, PTR) \ 1828*c217d954SCole Faust DATA.s0 = vload1(OFFSET, PTR); 1829*c217d954SCole Faust 1830*c217d954SCole Faust#define vload_partial_2(DATA, OFFSET, PTR) \ 1831*c217d954SCole Faust DATA.s01 = vload2(OFFSET, PTR); 1832*c217d954SCole Faust 1833*c217d954SCole Faust#define vload_partial_3(DATA, OFFSET, PTR) \ 1834*c217d954SCole Faust DATA.s012 = vload3(OFFSET, PTR); 1835*c217d954SCole Faust 1836*c217d954SCole Faust#define vload_partial_4(DATA, OFFSET, PTR) \ 1837*c217d954SCole Faust DATA.s0123 = vload4(OFFSET, PTR); 1838*c217d954SCole Faust 1839*c217d954SCole Faust#define vload_partial_5(DATA, OFFSET, PTR) \ 1840*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 1841*c217d954SCole Faust DATA.s4 = vload1(OFFSET, PTR + 4); 1842*c217d954SCole Faust 1843*c217d954SCole Faust#define vload_partial_6(DATA, OFFSET, PTR) \ 1844*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 1845*c217d954SCole Faust vload_partial_2(DATA.s45, OFFSET, PTR + 4); 1846*c217d954SCole Faust 1847*c217d954SCole Faust#define vload_partial_7(DATA, OFFSET, PTR) \ 1848*c217d954SCole Faust vload_partial_4(DATA.s0123, OFFSET, PTR); \ 1849*c217d954SCole Faust vload_partial_3(DATA.s456, OFFSET, PTR + 4); 1850*c217d954SCole Faust 1851*c217d954SCole Faust#define vload_partial_8(DATA, OFFSET, PTR) \ 1852*c217d954SCole Faust DATA.s01234567 = vload8(OFFSET, PTR); 1853*c217d954SCole Faust 1854*c217d954SCole Faust#define vload_partial_9(DATA, OFFSET, PTR) \ 1855*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1856*c217d954SCole Faust DATA.s8 = vload1(OFFSET, PTR + 8); 1857*c217d954SCole Faust 1858*c217d954SCole Faust#define vload_partial_10(DATA, OFFSET, PTR) \ 1859*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1860*c217d954SCole Faust vload_partial_2(DATA.s89, OFFSET, PTR + 8); 1861*c217d954SCole Faust 1862*c217d954SCole Faust#define vload_partial_11(DATA, OFFSET, PTR) \ 1863*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1864*c217d954SCole Faust vload_partial_3(DATA.s89A, OFFSET, PTR + 8); 1865*c217d954SCole Faust 1866*c217d954SCole Faust#define vload_partial_12(DATA, OFFSET, PTR) \ 1867*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1868*c217d954SCole Faust vload_partial_4(DATA.s89AB, OFFSET, PTR + 8); 1869*c217d954SCole Faust 1870*c217d954SCole Faust#define vload_partial_13(DATA, OFFSET, PTR) \ 1871*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1872*c217d954SCole Faust vload_partial_5(DATA.s89ABCDEF, OFFSET, PTR + 8); 1873*c217d954SCole Faust 1874*c217d954SCole Faust#define vload_partial_14(DATA, OFFSET, PTR) \ 1875*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1876*c217d954SCole Faust vload_partial_6(DATA.s89ABCDEF, OFFSET, PTR + 8); 1877*c217d954SCole Faust 1878*c217d954SCole Faust#define vload_partial_15(DATA, OFFSET, PTR) \ 1879*c217d954SCole Faust vload_partial_8(DATA.s01234567, OFFSET, PTR); \ 1880*c217d954SCole Faust vload_partial_7(DATA.s89ABCDEF, OFFSET, PTR + 8); 1881*c217d954SCole Faust 1882*c217d954SCole Faust#define vload_partial_16(DATA, OFFSET, PTR) \ 1883*c217d954SCole Faust DATA = vload16(OFFSET, PTR); 1884*c217d954SCole Faust 1885*c217d954SCole Faust 1886*c217d954SCole Faust 1887*c217d954SCole Faust#define PIXEL_UNIT4 1 1888*c217d954SCole Faust#define PIXEL_UNIT8 2 1889*c217d954SCole Faust#define PIXEL_UNIT16 4 1890*c217d954SCole Faust 1891*c217d954SCole Faust 1892*c217d954SCole Faust#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) PIXEL_UNIT##vec_size 1893*c217d954SCole Faust#define CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(vec_size) CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT_STR(vec_size) 1894*c217d954SCole Faust 1895*c217d954SCole Faust 1896*c217d954SCole Faust#define read_image2d_floatx1(img, x_coord, y_coord) (float4)(read_imagef(img, (int2)(x_coord, y_coord))); 1897*c217d954SCole Faust#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))); 1898*c217d954SCole Faust#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))); 1899*c217d954SCole Faust 1900*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 1901*c217d954SCole Faust#define read_image2d_halfx1(img, x_coord, y_coord) (half4)(read_imageh(img, (int2)(x_coord, y_coord))); 1902*c217d954SCole Faust#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))); 1903*c217d954SCole Faust#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))); 1904*c217d954SCole Faust#endif 1905*c217d954SCole Faust 1906*c217d954SCole Faust#define write_image2d_floatx1(img, x_coord, y_coord, values) (write_imagef(img, (int2)(x_coord, y_coord), values)); 1907*c217d954SCole Faust#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)); 1908*c217d954SCole Faust#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)); 1909*c217d954SCole Faust 1910*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) && defined(cl_khr_fp16) 1911*c217d954SCole Faust#define write_image2d_halfx1(img, x_coord, y_coord, values) (write_imageh(img, (int2)(x_coord, y_coord), values)); 1912*c217d954SCole Faust#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)); 1913*c217d954SCole Faust#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)); 1914*c217d954SCole Faust#endif 1915*c217d954SCole Faust 1916*c217d954SCole Faust 1917*c217d954SCole Faust#define READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) read_image2d_##data_type##x##n0(img, x_coord, y_coord) 1918*c217d954SCole Faust#define READ_IMAGE2D(data_type, n0, img, x_coord, y_coord) READ_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord) 1919*c217d954SCole Faust 1920*c217d954SCole Faust 1921*c217d954SCole Faust#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) 1922*c217d954SCole Faust#define WRITE_IMAGE2D(data_type, n0, img, x_coord, y_coord, values) WRITE_IMAGE2D_STR(data_type, n0, img, x_coord, y_coord, values) 1923*c217d954SCole Faust 1924*c217d954SCole Faust#define VSTORE_STR(size) vstore##size 1925*c217d954SCole Faust#define VSTORE(size) VSTORE_STR(size) 1926*c217d954SCole Faust 1927*c217d954SCole Faust#define float1 float 1928*c217d954SCole Faust#define half1 half 1929*c217d954SCole Faust#define char1 char 1930*c217d954SCole Faust#define uchar1 uchar 1931*c217d954SCole Faust#define short1 short 1932*c217d954SCole Faust#define ushort1 ushort 1933*c217d954SCole Faust#define int1 int 1934*c217d954SCole Faust#define uint1 uint 1935*c217d954SCole Faust#define long1 long 1936*c217d954SCole Faust#define ulong1 ulong 1937*c217d954SCole Faust#define double1 double 1938*c217d954SCole Faust 1939*c217d954SCole Faust#define vload1(OFFSET, PTR) *(OFFSET + PTR) 1940*c217d954SCole Faust#define vstore1(DATA, OFFSET, PTR) *(OFFSET + PTR) = DATA 1941*c217d954SCole Faust 1942*c217d954SCole Faust 1943*c217d954SCole Faust#define VSTORE_PARTIAL_STR(size, store_size) vstore_partial_##size##_##store_size 1944*c217d954SCole Faust#define VSTORE_PARTIAL(size, store_size) VSTORE_PARTIAL_STR(size, store_size) 1945*c217d954SCole Faust 1946*c217d954SCole Faust#define NO_STORE(data, offs, ptr) \ 1947*c217d954SCole Faust { \ 1948*c217d954SCole Faust } 1949*c217d954SCole Faust 1950*c217d954SCole Faust 1951*c217d954SCole Faust#define vstore_partial_1_0 NO_STORE 1952*c217d954SCole Faust#define vstore_partial_1_1 vstore1 1953*c217d954SCole Faust#define vstore_partial_1_2 NO_STORE 1954*c217d954SCole Faust#define vstore_partial_1_3 NO_STORE 1955*c217d954SCole Faust#define vstore_partial_1_4 NO_STORE 1956*c217d954SCole Faust#define vstore_partial_1_5 NO_STORE 1957*c217d954SCole Faust#define vstore_partial_1_6 NO_STORE 1958*c217d954SCole Faust#define vstore_partial_1_7 NO_STORE 1959*c217d954SCole Faust#define vstore_partial_1_8 NO_STORE 1960*c217d954SCole Faust#define vstore_partial_1_9 NO_STORE 1961*c217d954SCole Faust#define vstore_partial_1_10 NO_STORE 1962*c217d954SCole Faust#define vstore_partial_1_11 NO_STORE 1963*c217d954SCole Faust#define vstore_partial_1_12 NO_STORE 1964*c217d954SCole Faust#define vstore_partial_1_13 NO_STORE 1965*c217d954SCole Faust#define vstore_partial_1_14 NO_STORE 1966*c217d954SCole Faust#define vstore_partial_1_15 NO_STORE 1967*c217d954SCole Faust#define vstore_partial_1_16 NO_STORE 1968*c217d954SCole Faust 1969*c217d954SCole Faust#define vstore_partial_2_0 NO_STORE 1970*c217d954SCole Faust#define vstore_partial_2_1 vstore_partial_1 1971*c217d954SCole Faust#define vstore_partial_2_2 vstore_partial_2 1972*c217d954SCole Faust#define vstore_partial_2_3 NO_STORE 1973*c217d954SCole Faust#define vstore_partial_2_4 NO_STORE 1974*c217d954SCole Faust#define vstore_partial_2_5 NO_STORE 1975*c217d954SCole Faust#define vstore_partial_2_6 NO_STORE 1976*c217d954SCole Faust#define vstore_partial_2_7 NO_STORE 1977*c217d954SCole Faust#define vstore_partial_2_8 NO_STORE 1978*c217d954SCole Faust#define vstore_partial_2_9 NO_STORE 1979*c217d954SCole Faust#define vstore_partial_2_10 NO_STORE 1980*c217d954SCole Faust#define vstore_partial_2_11 NO_STORE 1981*c217d954SCole Faust#define vstore_partial_2_12 NO_STORE 1982*c217d954SCole Faust#define vstore_partial_2_13 NO_STORE 1983*c217d954SCole Faust#define vstore_partial_2_14 NO_STORE 1984*c217d954SCole Faust#define vstore_partial_2_15 NO_STORE 1985*c217d954SCole Faust#define vstore_partial_2_16 NO_STORE 1986*c217d954SCole Faust 1987*c217d954SCole Faust#define vstore_partial_3_0 NO_STORE 1988*c217d954SCole Faust#define vstore_partial_3_1 vstore_partial_1 1989*c217d954SCole Faust#define vstore_partial_3_2 vstore_partial_2 1990*c217d954SCole Faust#define vstore_partial_3_3 vstore_partial_3 1991*c217d954SCole Faust#define vstore_partial_3_4 NO_STORE 1992*c217d954SCole Faust#define vstore_partial_3_5 NO_STORE 1993*c217d954SCole Faust#define vstore_partial_3_6 NO_STORE 1994*c217d954SCole Faust#define vstore_partial_3_7 NO_STORE 1995*c217d954SCole Faust#define vstore_partial_3_8 NO_STORE 1996*c217d954SCole Faust#define vstore_partial_3_9 NO_STORE 1997*c217d954SCole Faust#define vstore_partial_3_10 NO_STORE 1998*c217d954SCole Faust#define vstore_partial_3_11 NO_STORE 1999*c217d954SCole Faust#define vstore_partial_3_12 NO_STORE 2000*c217d954SCole Faust#define vstore_partial_3_13 NO_STORE 2001*c217d954SCole Faust#define vstore_partial_3_14 NO_STORE 2002*c217d954SCole Faust#define vstore_partial_3_15 NO_STORE 2003*c217d954SCole Faust#define vstore_partial_3_16 NO_STORE 2004*c217d954SCole Faust 2005*c217d954SCole Faust#define vstore_partial_4_0 NO_STORE 2006*c217d954SCole Faust#define vstore_partial_4_1 vstore_partial_1 2007*c217d954SCole Faust#define vstore_partial_4_2 vstore_partial_2 2008*c217d954SCole Faust#define vstore_partial_4_3 vstore_partial_3 2009*c217d954SCole Faust#define vstore_partial_4_4 vstore_partial_4 2010*c217d954SCole Faust#define vstore_partial_4_5 NO_STORE 2011*c217d954SCole Faust#define vstore_partial_4_6 NO_STORE 2012*c217d954SCole Faust#define vstore_partial_4_7 NO_STORE 2013*c217d954SCole Faust#define vstore_partial_4_8 NO_STORE 2014*c217d954SCole Faust#define vstore_partial_4_9 NO_STORE 2015*c217d954SCole Faust#define vstore_partial_4_10 NO_STORE 2016*c217d954SCole Faust#define vstore_partial_4_11 NO_STORE 2017*c217d954SCole Faust#define vstore_partial_4_12 NO_STORE 2018*c217d954SCole Faust#define vstore_partial_4_13 NO_STORE 2019*c217d954SCole Faust#define vstore_partial_4_14 NO_STORE 2020*c217d954SCole Faust#define vstore_partial_4_15 NO_STORE 2021*c217d954SCole Faust#define vstore_partial_4_16 NO_STORE 2022*c217d954SCole Faust 2023*c217d954SCole Faust#define vstore_partial_8_0 NO_STORE 2024*c217d954SCole Faust#define vstore_partial_8_1 vstore_partial_1 2025*c217d954SCole Faust#define vstore_partial_8_2 vstore_partial_2 2026*c217d954SCole Faust#define vstore_partial_8_3 vstore_partial_3 2027*c217d954SCole Faust#define vstore_partial_8_4 vstore_partial_4 2028*c217d954SCole Faust#define vstore_partial_8_5 vstore_partial_5 2029*c217d954SCole Faust#define vstore_partial_8_6 vstore_partial_6 2030*c217d954SCole Faust#define vstore_partial_8_7 vstore_partial_7 2031*c217d954SCole Faust#define vstore_partial_8_8 vstore_partial_8 2032*c217d954SCole Faust#define vstore_partial_8_9 NO_STORE 2033*c217d954SCole Faust#define vstore_partial_8_10 NO_STORE 2034*c217d954SCole Faust#define vstore_partial_8_11 NO_STORE 2035*c217d954SCole Faust#define vstore_partial_8_12 NO_STORE 2036*c217d954SCole Faust#define vstore_partial_8_13 NO_STORE 2037*c217d954SCole Faust#define vstore_partial_8_14 NO_STORE 2038*c217d954SCole Faust#define vstore_partial_8_15 NO_STORE 2039*c217d954SCole Faust#define vstore_partial_8_16 NO_STORE 2040*c217d954SCole Faust 2041*c217d954SCole Faust#define vstore_partial_16_0 NO_STORE 2042*c217d954SCole Faust#define vstore_partial_16_1 vstore_partial_1 2043*c217d954SCole Faust#define vstore_partial_16_2 vstore_partial_2 2044*c217d954SCole Faust#define vstore_partial_16_3 vstore_partial_3 2045*c217d954SCole Faust#define vstore_partial_16_4 vstore_partial_4 2046*c217d954SCole Faust#define vstore_partial_16_5 vstore_partial_5 2047*c217d954SCole Faust#define vstore_partial_16_6 vstore_partial_6 2048*c217d954SCole Faust#define vstore_partial_16_7 vstore_partial_7 2049*c217d954SCole Faust#define vstore_partial_16_8 vstore_partial_8 2050*c217d954SCole Faust#define vstore_partial_16_9 vstore_partial_9 2051*c217d954SCole Faust#define vstore_partial_16_10 vstore_partial_10 2052*c217d954SCole Faust#define vstore_partial_16_11 vstore_partial_11 2053*c217d954SCole Faust#define vstore_partial_16_12 vstore_partial_12 2054*c217d954SCole Faust#define vstore_partial_16_13 vstore_partial_13 2055*c217d954SCole Faust#define vstore_partial_16_14 vstore_partial_14 2056*c217d954SCole Faust#define vstore_partial_16_15 vstore_partial_15 2057*c217d954SCole Faust#define vstore_partial_16_16 vstore_partial_16 2058*c217d954SCole Faust 2059*c217d954SCole Faust 2060*c217d954SCole Faust#define vstore_partial_1(DATA, OFFSET, PTR) \ 2061*c217d954SCole Faust vstore1(DATA.s0, OFFSET, PTR); 2062*c217d954SCole Faust 2063*c217d954SCole Faust#define vstore_partial_2(DATA, OFFSET, PTR) \ 2064*c217d954SCole Faust vstore2(DATA.s01, OFFSET, PTR); 2065*c217d954SCole Faust 2066*c217d954SCole Faust#define vstore_partial_3(DATA, OFFSET, PTR) \ 2067*c217d954SCole Faust vstore3(DATA.s012, OFFSET, PTR); 2068*c217d954SCole Faust 2069*c217d954SCole Faust#define vstore_partial_4(DATA, OFFSET, PTR) \ 2070*c217d954SCole Faust vstore4(DATA.s0123, OFFSET, PTR); 2071*c217d954SCole Faust 2072*c217d954SCole Faust#define vstore_partial_5(DATA, OFFSET, PTR) \ 2073*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 2074*c217d954SCole Faust vstore1(DATA.s4, OFFSET, PTR + 4); 2075*c217d954SCole Faust 2076*c217d954SCole Faust#define vstore_partial_6(DATA, OFFSET, PTR) \ 2077*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 2078*c217d954SCole Faust vstore_partial_2(DATA.s45, OFFSET, PTR + 4); 2079*c217d954SCole Faust 2080*c217d954SCole Faust#define vstore_partial_7(DATA, OFFSET, PTR) \ 2081*c217d954SCole Faust vstore_partial_4(DATA.s0123, OFFSET, PTR); \ 2082*c217d954SCole Faust vstore_partial_3(DATA.s456, OFFSET, PTR + 4); 2083*c217d954SCole Faust 2084*c217d954SCole Faust#define vstore_partial_8(DATA, OFFSET, PTR) \ 2085*c217d954SCole Faust vstore8(DATA.s01234567, OFFSET, PTR); 2086*c217d954SCole Faust 2087*c217d954SCole Faust#define vstore_partial_9(DATA, OFFSET, PTR) \ 2088*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2089*c217d954SCole Faust vstore1(DATA.s8, OFFSET, PTR + 8); 2090*c217d954SCole Faust 2091*c217d954SCole Faust#define vstore_partial_10(DATA, OFFSET, PTR) \ 2092*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2093*c217d954SCole Faust vstore_partial_2(DATA.s89, OFFSET, PTR + 8); 2094*c217d954SCole Faust 2095*c217d954SCole Faust#define vstore_partial_11(DATA, OFFSET, PTR) \ 2096*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2097*c217d954SCole Faust vstore_partial_3(DATA.s89a, OFFSET, PTR + 8); 2098*c217d954SCole Faust 2099*c217d954SCole Faust#define vstore_partial_12(DATA, OFFSET, PTR) \ 2100*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2101*c217d954SCole Faust vstore_partial_4(DATA.s89ab, OFFSET, PTR + 8); 2102*c217d954SCole Faust 2103*c217d954SCole Faust#define vstore_partial_13(DATA, OFFSET, PTR) \ 2104*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2105*c217d954SCole Faust vstore_partial_5(DATA.s89abcdef, OFFSET, PTR + 8); 2106*c217d954SCole Faust 2107*c217d954SCole Faust#define vstore_partial_14(DATA, OFFSET, PTR) \ 2108*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2109*c217d954SCole Faust vstore_partial_6(DATA.s89abcdef, OFFSET, PTR + 8); 2110*c217d954SCole Faust 2111*c217d954SCole Faust#define vstore_partial_15(DATA, OFFSET, PTR) \ 2112*c217d954SCole Faust vstore_partial_8(DATA.s01234567, OFFSET, PTR); \ 2113*c217d954SCole Faust vstore_partial_7(DATA.s89abcdef, OFFSET, PTR + 8); 2114*c217d954SCole Faust 2115*c217d954SCole Faust#define vstore_partial_16(DATA, OFFSET, PTR) \ 2116*c217d954SCole Faust vstore16(DATA, OFFSET, PTR); 2117*c217d954SCole Faust 2118*c217d954SCole Faust 2119*c217d954SCole Faust 2120*c217d954SCole Faust 2121*c217d954SCole Faust 2122*c217d954SCole Faust#define convert_float_sat convert_float 2123*c217d954SCole Faust#define convert_float1_sat convert_float 2124*c217d954SCole Faust#define convert_float2_sat convert_float2 2125*c217d954SCole Faust#define convert_float3_sat convert_float3 2126*c217d954SCole Faust#define convert_float4_sat convert_float4 2127*c217d954SCole Faust#define convert_float8_sat convert_float8 2128*c217d954SCole Faust#define convert_float16_sat convert_float16 2129*c217d954SCole Faust#define convert_half_sat convert_float 2130*c217d954SCole Faust#define convert_half1_sat convert_half 2131*c217d954SCole Faust#define convert_half2_sat convert_half2 2132*c217d954SCole Faust#define convert_half3_sat convert_half3 2133*c217d954SCole Faust#define convert_half4_sat convert_half4 2134*c217d954SCole Faust#define convert_half8_sat convert_half8 2135*c217d954SCole Faust#define convert_half16_sat convert_half16 2136*c217d954SCole Faust 2137*c217d954SCole Faust#define convert_float1 convert_float 2138*c217d954SCole Faust#define convert_half1 convert_half 2139*c217d954SCole Faust#define convert_char1 convert_char 2140*c217d954SCole Faust#define convert_uchar1 convert_uchar 2141*c217d954SCole Faust#define convert_short1 convert_short 2142*c217d954SCole Faust#define convert_ushort1 convert_ushort 2143*c217d954SCole Faust#define convert_int1 convert_int 2144*c217d954SCole Faust#define convert_uint1 convert_uint 2145*c217d954SCole Faust#define convert_long1 convert_long 2146*c217d954SCole Faust#define convert_ulong1 convert_ulong 2147*c217d954SCole Faust#define convert_double1 convert_double 2148*c217d954SCole Faust 2149*c217d954SCole Faust#define convert_char1_sat convert_char_sat 2150*c217d954SCole Faust#define convert_uchar1_sat convert_uchar_sat 2151*c217d954SCole Faust#define convert_uchar2_sat convert_uchar2_sat 2152*c217d954SCole Faust#define convert_uchar3_sat convert_uchar3_sat 2153*c217d954SCole Faust#define convert_uchar4_sat convert_uchar4_sat 2154*c217d954SCole Faust#define convert_uchar8_sat convert_uchar8_sat 2155*c217d954SCole Faust#define convert_uchar16_sat convert_uchar16_sat 2156*c217d954SCole Faust#define convert_short1_sat convert_short_sat 2157*c217d954SCole Faust#define convert_ushort1_sat convert_ushort_sat 2158*c217d954SCole Faust#define convert_int1_sat convert_int_sat 2159*c217d954SCole Faust#define convert_uint1_sat convert_uint_sat 2160*c217d954SCole Faust#define convert_long1_sat convert_long_sat 2161*c217d954SCole Faust#define convert_ulong1_sat convert_ulong_sat 2162*c217d954SCole Faust#define convert_double1_sat convert_double_sat 2163*c217d954SCole Faust 2164*c217d954SCole Faust#define VEC_DATA_TYPE_STR(type, size) type##size 2165*c217d954SCole Faust#define VEC_DATA_TYPE(type, size) VEC_DATA_TYPE_STR(type, size) 2166*c217d954SCole Faust 2167*c217d954SCole Faust#define CONVERT_STR(x, type) (convert_##type((x))) 2168*c217d954SCole Faust#define CONVERT(x, type) CONVERT_STR(x, type) 2169*c217d954SCole Faust 2170*c217d954SCole Faust#define CONVERT_SAT_STR(x, type) (convert_##type##_sat((x))) 2171*c217d954SCole Faust#define CONVERT_SAT(x, type) CONVERT_SAT_STR(x, type) 2172*c217d954SCole Faust 2173*c217d954SCole Faust#define CONVERT_SAT_ROUND_STR(x, type, round) (convert_##type##_sat_##round((x))) 2174*c217d954SCole Faust#define CONVERT_SAT_ROUND(x, type, round) CONVERT_SAT_ROUND_STR(x, type, round) 2175*c217d954SCole Faust 2176*c217d954SCole Faust#define select_vec_dt_uchar(size) uchar##size 2177*c217d954SCole Faust#define select_vec_dt_char(size) char##size 2178*c217d954SCole Faust#define select_vec_dt_ushort(size) ushort##size 2179*c217d954SCole Faust#define select_vec_dt_short(size) short##size 2180*c217d954SCole Faust#define select_vec_dt_half(size) short##size 2181*c217d954SCole Faust#define select_vec_dt_uint(size) uint##size 2182*c217d954SCole Faust#define select_vec_dt_int(size) int##size 2183*c217d954SCole Faust#define select_vec_dt_float(size) int##size 2184*c217d954SCole Faust#define select_vec_dt_ulong(size) ulong##size 2185*c217d954SCole Faust#define select_vec_dt_long(size) long##size 2186*c217d954SCole Faust 2187*c217d954SCole Faust#define SELECT_VEC_DATA_TYPE_STR(type, size) select_vec_dt_##type(size) 2188*c217d954SCole Faust#define SELECT_VEC_DATA_TYPE(type, size) SELECT_VEC_DATA_TYPE_STR(type, size) 2189*c217d954SCole Faust#define SELECT_DATA_TYPE(type) SELECT_VEC_DATA_TYPE_STR(type, 1) 2190*c217d954SCole Faust 2191*c217d954SCole Faust#define signed_int_vec_dt_uchar(size) char##size 2192*c217d954SCole Faust#define signed_int_vec_dt_char(size) char##size 2193*c217d954SCole Faust#define signed_int_vec_dt_ushort(size) short##size 2194*c217d954SCole Faust#define signed_int_vec_dt_short(size) short##size 2195*c217d954SCole Faust#define signed_int_vec_dt_half(size) short##size 2196*c217d954SCole Faust#define signed_int_vec_dt_uint(size) int##size 2197*c217d954SCole Faust#define signed_int_vec_dt_int(size) int##size 2198*c217d954SCole Faust#define signed_int_vec_dt_float(size) int##size 2199*c217d954SCole Faust#define signed_int_vec_dt_ulong(size) long##size 2200*c217d954SCole Faust#define signed_int_vec_dt_long(size) long##size 2201*c217d954SCole Faust 2202*c217d954SCole Faust#define SIGNED_INT_VEC_DATA_TYPE_STR(type, size) signed_int_vec_dt_##type(size) 2203*c217d954SCole Faust#define SIGNED_INT_VEC_DATA_TYPE(type, size) SIGNED_INT_VEC_DATA_TYPE_STR(type, size) 2204*c217d954SCole Faust#define SIGNED_INT_DATA_TYPE(type) SIGNED_INT_VEC_DATA_TYPE_STR(type, 1) 2205*c217d954SCole Faust 2206*c217d954SCole Faust#define sum_reduce_1(x) (x) 2207*c217d954SCole Faust#define sum_reduce_2(x) ((x).s0) + ((x).s1) 2208*c217d954SCole Faust#define sum_reduce_3(x) sum_reduce_2((x).s01) + ((x).s2) 2209*c217d954SCole Faust#define sum_reduce_4(x) sum_reduce_2((x).s01) + sum_reduce_2((x).s23) 2210*c217d954SCole Faust#define sum_reduce_8(x) sum_reduce_4((x).s0123) + sum_reduce_4((x).s4567) 2211*c217d954SCole Faust#define sum_reduce_16(x) sum_reduce_8((x).s01234567) + sum_reduce_8((x).s89ABCDEF) 2212*c217d954SCole Faust 2213*c217d954SCole Faust#define SUM_REDUCE_STR(x, size) sum_reduce_##size(x) 2214*c217d954SCole Faust#define SUM_REDUCE(x, size) SUM_REDUCE_STR(x, size) 2215*c217d954SCole Faust 2216*c217d954SCole Faust#define prod_reduce_1(x) (x) 2217*c217d954SCole Faust#define prod_reduce_2(x) ((x).s0) * ((x).s1) 2218*c217d954SCole Faust#define prod_reduce_3(x) prod_reduce_2((x).s01) * ((x).s2) 2219*c217d954SCole Faust#define prod_reduce_4(x) prod_reduce_2((x).s01) * prod_reduce_2((x).s23) 2220*c217d954SCole Faust#define prod_reduce_8(x) prod_reduce_4((x).s0123) * prod_reduce_4((x).s4567) 2221*c217d954SCole Faust#define prod_reduce_16(x) prod_reduce_8((x).s01234567) * prod_reduce_8((x).s89ABCDEF) 2222*c217d954SCole Faust 2223*c217d954SCole Faust#define PROD_REDUCE_STR(x, size) prod_reduce_##size(x) 2224*c217d954SCole Faust#define PROD_REDUCE(x, size) PROD_REDUCE_STR(x, size) 2225*c217d954SCole Faust 2226*c217d954SCole Faust#define max_reduce_1(x) (x) 2227*c217d954SCole Faust#define max_reduce_2(x) max(((x).s0), ((x).s1)) 2228*c217d954SCole Faust#define max_reduce_3(x) max(max_reduce_2((x).s01), ((x).s2)) 2229*c217d954SCole Faust#define max_reduce_4(x) max(max_reduce_2((x).s01), max_reduce_2((x).s23)) 2230*c217d954SCole Faust#define max_reduce_8(x) max(max_reduce_4((x).s0123), max_reduce_4((x).s4567)) 2231*c217d954SCole Faust#define max_reduce_16(x) max(max_reduce_8((x).s01234567), max_reduce_8((x).s89ABCDEF)) 2232*c217d954SCole Faust 2233*c217d954SCole Faust#define MAX_REDUCE_STR(x, size) max_reduce_##size(x) 2234*c217d954SCole Faust#define MAX_REDUCE(x, size) MAX_REDUCE_STR(x, size) 2235*c217d954SCole Faust 2236*c217d954SCole Faust#define VECTOR_DECLARATION(name) \ 2237*c217d954SCole Faust __global uchar *name##_ptr, \ 2238*c217d954SCole Faust uint name##_stride_x, \ 2239*c217d954SCole Faust uint name##_step_x, \ 2240*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2241*c217d954SCole Faust 2242*c217d954SCole Faust#define IMAGE_DECLARATION(name) \ 2243*c217d954SCole Faust __global uchar *name##_ptr, \ 2244*c217d954SCole Faust uint name##_stride_x, \ 2245*c217d954SCole Faust uint name##_step_x, \ 2246*c217d954SCole Faust uint name##_stride_y, \ 2247*c217d954SCole Faust uint name##_step_y, \ 2248*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2249*c217d954SCole Faust 2250*c217d954SCole Faust#define TENSOR3D_DECLARATION(name) \ 2251*c217d954SCole Faust __global uchar *name##_ptr, \ 2252*c217d954SCole Faust uint name##_stride_x, \ 2253*c217d954SCole Faust uint name##_step_x, \ 2254*c217d954SCole Faust uint name##_stride_y, \ 2255*c217d954SCole Faust uint name##_step_y, \ 2256*c217d954SCole Faust uint name##_stride_z, \ 2257*c217d954SCole Faust uint name##_step_z, \ 2258*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2259*c217d954SCole Faust 2260*c217d954SCole Faust#define TENSOR4D_DECLARATION(name) \ 2261*c217d954SCole Faust __global uchar *name##_ptr, \ 2262*c217d954SCole Faust uint name##_stride_x, \ 2263*c217d954SCole Faust uint name##_step_x, \ 2264*c217d954SCole Faust uint name##_stride_y, \ 2265*c217d954SCole Faust uint name##_step_y, \ 2266*c217d954SCole Faust uint name##_stride_z, \ 2267*c217d954SCole Faust uint name##_step_z, \ 2268*c217d954SCole Faust uint name##_stride_w, \ 2269*c217d954SCole Faust uint name##_step_w, \ 2270*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2271*c217d954SCole Faust 2272*c217d954SCole Faust#define TENSOR5D_DECLARATION(name) \ 2273*c217d954SCole Faust __global uchar *name##_ptr, \ 2274*c217d954SCole Faust uint name##_stride_x, \ 2275*c217d954SCole Faust uint name##_step_x, \ 2276*c217d954SCole Faust uint name##_stride_y, \ 2277*c217d954SCole Faust uint name##_step_y, \ 2278*c217d954SCole Faust uint name##_stride_z, \ 2279*c217d954SCole Faust uint name##_step_z, \ 2280*c217d954SCole Faust uint name##_stride_w, \ 2281*c217d954SCole Faust uint name##_step_w, \ 2282*c217d954SCole Faust uint name##_stride_v, \ 2283*c217d954SCole Faust uint name##_step_v, \ 2284*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2285*c217d954SCole Faust 2286*c217d954SCole Faust#define CONVERT_TO_VECTOR_STRUCT(name) \ 2287*c217d954SCole Faust update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x) 2288*c217d954SCole Faust 2289*c217d954SCole Faust#define CONVERT_TO_VECTOR_STRUCT_NO_STEP(name) \ 2290*c217d954SCole Faust update_vector_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0) 2291*c217d954SCole Faust 2292*c217d954SCole Faust#define CONVERT_TO_IMAGE_STRUCT(name) \ 2293*c217d954SCole Faust update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y) 2294*c217d954SCole Faust 2295*c217d954SCole Faust#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name) \ 2296*c217d954SCole Faust update_image_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0) 2297*c217d954SCole Faust 2298*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 2299*c217d954SCole Faust 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) 2300*c217d954SCole Faust 2301*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(name) \ 2302*c217d954SCole Faust 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) 2303*c217d954SCole Faust 2304*c217d954SCole Faust#define CONVERT_TENSOR3D_TO_IMAGE_STRUCT(name) \ 2305*c217d954SCole Faust 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) 2306*c217d954SCole Faust 2307*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT(name) \ 2308*c217d954SCole Faust update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 2309*c217d954SCole Faust name##_stride_z, name##_step_z) 2310*c217d954SCole Faust 2311*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(name) \ 2312*c217d954SCole Faust update_tensor3D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, 0, name##_stride_y, 0, name##_stride_z, 0) 2313*c217d954SCole Faust 2314*c217d954SCole Faust#define CONVERT_TO_TENSOR4D_STRUCT(name, mod_size) \ 2315*c217d954SCole Faust update_tensor4D_workitem_ptr(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 2316*c217d954SCole Faust name##_stride_z, name##_step_z, name##_stride_w, name##_step_w, mod_size) 2317*c217d954SCole Faust 2318*c217d954SCole Faust#define CONVERT_TO_TENSOR4D_STRUCT_NO_STEP(name, mod_size) \ 2319*c217d954SCole Faust 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) 2320*c217d954SCole Faust 2321*c217d954SCole Faust#define CONVERT_TO_TENSOR3D_STRUCT_NO_UPDATE_PTR(name) \ 2322*c217d954SCole Faust tensor3D_ptr_no_update(name##_ptr, name##_offset_first_element_in_bytes, name##_stride_x, name##_step_x, name##_stride_y, name##_step_y, \ 2323*c217d954SCole Faust name##_stride_z, name##_step_z) 2324*c217d954SCole Faust 2325*c217d954SCole Faust 2326*c217d954SCole Fausttypedef struct Vector 2327*c217d954SCole Faust{ 2328*c217d954SCole Faust __global uchar *ptr; 2329*c217d954SCole Faust int offset_first_element_in_bytes; 2330*c217d954SCole Faust int stride_x; 2331*c217d954SCole Faust} Vector; 2332*c217d954SCole Faust 2333*c217d954SCole Faust 2334*c217d954SCole Fausttypedef struct Image 2335*c217d954SCole Faust{ 2336*c217d954SCole Faust __global uchar *ptr; 2337*c217d954SCole Faust int offset_first_element_in_bytes; 2338*c217d954SCole Faust int stride_x; 2339*c217d954SCole Faust int stride_y; 2340*c217d954SCole Faust} Image; 2341*c217d954SCole Faust 2342*c217d954SCole Faust 2343*c217d954SCole Fausttypedef struct Tensor3D 2344*c217d954SCole Faust{ 2345*c217d954SCole Faust __global uchar *ptr; 2346*c217d954SCole Faust int offset_first_element_in_bytes; 2347*c217d954SCole Faust int stride_x; 2348*c217d954SCole Faust int stride_y; 2349*c217d954SCole Faust int stride_z; 2350*c217d954SCole Faust} Tensor3D; 2351*c217d954SCole Faust 2352*c217d954SCole Faust 2353*c217d954SCole Fausttypedef struct Tensor4D 2354*c217d954SCole Faust{ 2355*c217d954SCole Faust __global uchar *ptr; 2356*c217d954SCole Faust int offset_first_element_in_bytes; 2357*c217d954SCole Faust int stride_x; 2358*c217d954SCole Faust int stride_y; 2359*c217d954SCole Faust int stride_z; 2360*c217d954SCole Faust int stride_w; 2361*c217d954SCole Faust} Tensor4D; 2362*c217d954SCole Faust 2363*c217d954SCole Faust 2364*c217d954SCole Faustinline Vector update_vector_workitem_ptr(__global uchar *ptr, uint offset_first_element_in_bytes, uint stride_x, uint step_x) 2365*c217d954SCole Faust{ 2366*c217d954SCole Faust Vector vector = 2367*c217d954SCole Faust { 2368*c217d954SCole Faust .ptr = ptr, 2369*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2370*c217d954SCole Faust .stride_x = stride_x, 2371*c217d954SCole Faust }; 2372*c217d954SCole Faust vector.ptr += vector.offset_first_element_in_bytes + get_global_id(0) * step_x; 2373*c217d954SCole Faust return vector; 2374*c217d954SCole Faust} 2375*c217d954SCole Faust 2376*c217d954SCole Faust 2377*c217d954SCole Faustinline 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) 2378*c217d954SCole Faust{ 2379*c217d954SCole Faust Image img = 2380*c217d954SCole Faust { 2381*c217d954SCole Faust .ptr = ptr, 2382*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2383*c217d954SCole Faust .stride_x = stride_x, 2384*c217d954SCole Faust .stride_y = stride_y 2385*c217d954SCole Faust }; 2386*c217d954SCole Faust img.ptr += img.offset_first_element_in_bytes + get_global_id(0) * step_x + get_global_id(1) * step_y; 2387*c217d954SCole Faust return img; 2388*c217d954SCole Faust} 2389*c217d954SCole Faust 2390*c217d954SCole Faust 2391*c217d954SCole Faustinline 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) 2392*c217d954SCole Faust{ 2393*c217d954SCole Faust Image img = 2394*c217d954SCole Faust { 2395*c217d954SCole Faust .ptr = ptr, 2396*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2397*c217d954SCole Faust .stride_x = stride_x, 2398*c217d954SCole Faust .stride_y = stride_y 2399*c217d954SCole Faust }; 2400*c217d954SCole Faust 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; 2401*c217d954SCole Faust return img; 2402*c217d954SCole Faust} 2403*c217d954SCole Faust 2404*c217d954SCole Faust 2405*c217d954SCole Faustinline 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) 2406*c217d954SCole Faust{ 2407*c217d954SCole Faust Tensor3D tensor = 2408*c217d954SCole Faust { 2409*c217d954SCole Faust .ptr = ptr, 2410*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2411*c217d954SCole Faust .stride_x = stride_x, 2412*c217d954SCole Faust .stride_y = stride_y, 2413*c217d954SCole Faust .stride_z = stride_z 2414*c217d954SCole Faust }; 2415*c217d954SCole Faust 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; 2416*c217d954SCole Faust return tensor; 2417*c217d954SCole Faust} 2418*c217d954SCole Faust 2419*c217d954SCole Faust 2420*c217d954SCole Faustinline 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) 2421*c217d954SCole Faust{ 2422*c217d954SCole Faust Tensor3D tensor = 2423*c217d954SCole Faust { 2424*c217d954SCole Faust .ptr = ptr, 2425*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2426*c217d954SCole Faust .stride_x = stride_x, 2427*c217d954SCole Faust .stride_y = stride_y, 2428*c217d954SCole Faust .stride_z = stride_z 2429*c217d954SCole Faust }; 2430*c217d954SCole Faust return tensor; 2431*c217d954SCole Faust} 2432*c217d954SCole Faust 2433*c217d954SCole Faustinline 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, 2434*c217d954SCole Faust uint step_w, 2435*c217d954SCole Faust uint mod_size) 2436*c217d954SCole Faust{ 2437*c217d954SCole Faust Tensor4D tensor = 2438*c217d954SCole Faust { 2439*c217d954SCole Faust .ptr = ptr, 2440*c217d954SCole Faust .offset_first_element_in_bytes = offset_first_element_in_bytes, 2441*c217d954SCole Faust .stride_x = stride_x, 2442*c217d954SCole Faust .stride_y = stride_y, 2443*c217d954SCole Faust .stride_z = stride_z, 2444*c217d954SCole Faust .stride_w = stride_w 2445*c217d954SCole Faust }; 2446*c217d954SCole Faust 2447*c217d954SCole Faust 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; 2448*c217d954SCole Faust return tensor; 2449*c217d954SCole Faust} 2450*c217d954SCole Faust 2451*c217d954SCole Faust 2452*c217d954SCole Faustinline __global const uchar *vector_offset(const Vector *vec, int x) 2453*c217d954SCole Faust{ 2454*c217d954SCole Faust return vec->ptr + x * vec->stride_x; 2455*c217d954SCole Faust} 2456*c217d954SCole Faust 2457*c217d954SCole Faust 2458*c217d954SCole Faustinline __global uchar *offset(const Image *img, int x, int y) 2459*c217d954SCole Faust{ 2460*c217d954SCole Faust return img->ptr + x * img->stride_x + y * img->stride_y; 2461*c217d954SCole Faust} 2462*c217d954SCole Faust 2463*c217d954SCole Faust 2464*c217d954SCole Faustinline __global const uchar *tensor3D_offset(const Tensor3D *tensor, int x, int y, int z) 2465*c217d954SCole Faust{ 2466*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z; 2467*c217d954SCole Faust} 2468*c217d954SCole Faust 2469*c217d954SCole Faust 2470*c217d954SCole Faustinline __global const uchar *tensor4D_offset(const Tensor4D *tensor, int x, int y, int z, int w) 2471*c217d954SCole Faust{ 2472*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + w * tensor->stride_w; 2473*c217d954SCole Faust} 2474*c217d954SCole Faust 2475*c217d954SCole Faust 2476*c217d954SCole Faustinline __global const uchar *tensor3D_index2ptr(const Tensor3D *tensor, uint width, uint height, uint depth, uint index) 2477*c217d954SCole Faust{ 2478*c217d954SCole Faust uint num_elements = width * height; 2479*c217d954SCole Faust 2480*c217d954SCole Faust const uint z = index / num_elements; 2481*c217d954SCole Faust 2482*c217d954SCole Faust index %= num_elements; 2483*c217d954SCole Faust 2484*c217d954SCole Faust const uint y = index / width; 2485*c217d954SCole Faust 2486*c217d954SCole Faust index %= width; 2487*c217d954SCole Faust 2488*c217d954SCole Faust const uint x = index; 2489*c217d954SCole Faust 2490*c217d954SCole Faust return tensor->ptr + x * tensor->stride_x + y * tensor->stride_y + z * tensor->stride_z + tensor->offset_first_element_in_bytes; 2491*c217d954SCole Faust} 2492*c217d954SCole Faust 2493*c217d954SCole Faust#endif 2494*c217d954SCole Faust 2495*c217d954SCole Faust 2496*c217d954SCole Faust 2497*c217d954SCole Faust#define REPEAT_3_1(P_X, P_A, P_B, P_C) P_X##_DEF(0, P_A, P_B, P_C) 2498*c217d954SCole Faust#define REPEAT_3_2(P_X, P_A, P_B, P_C) \ 2499*c217d954SCole Faust P_X##_DEF(1, P_A, P_B, P_C); \ 2500*c217d954SCole Faust REPEAT_3_1(P_X, P_A, P_B, P_C) 2501*c217d954SCole Faust#define REPEAT_3_3(P_X, P_A, P_B, P_C) \ 2502*c217d954SCole Faust P_X##_DEF(2, P_A, P_B, P_C); \ 2503*c217d954SCole Faust REPEAT_3_2(P_X, P_A, P_B, P_C) 2504*c217d954SCole Faust#define REPEAT_3_4(P_X, P_A, P_B, P_C) \ 2505*c217d954SCole Faust P_X##_DEF(3, P_A, P_B, P_C); \ 2506*c217d954SCole Faust REPEAT_3_3(P_X, P_A, P_B, P_C) 2507*c217d954SCole Faust#define REPEAT_3_5(P_X, P_A, P_B, P_C) \ 2508*c217d954SCole Faust P_X##_DEF(4, P_A, P_B, P_C); \ 2509*c217d954SCole Faust REPEAT_3_4(P_X, P_A, P_B, P_C) 2510*c217d954SCole Faust#define REPEAT_3_6(P_X, P_A, P_B, P_C) \ 2511*c217d954SCole Faust P_X##_DEF(5, P_A, P_B, P_C); \ 2512*c217d954SCole Faust REPEAT_3_5(P_X, P_A, P_B, P_C) 2513*c217d954SCole Faust#define REPEAT_3_7(P_X, P_A, P_B, P_C) \ 2514*c217d954SCole Faust P_X##_DEF(6, P_A, P_B, P_C); \ 2515*c217d954SCole Faust REPEAT_3_6(P_X, P_A, P_B, P_C) 2516*c217d954SCole Faust#define REPEAT_3_8(P_X, P_A, P_B, P_C) \ 2517*c217d954SCole Faust P_X##_DEF(7, P_A, P_B, P_C); \ 2518*c217d954SCole Faust REPEAT_3_7(P_X, P_A, P_B, P_C) 2519*c217d954SCole Faust#define REPEAT_3_9(P_X, P_A, P_B, P_C) \ 2520*c217d954SCole Faust P_X##_DEF(8, P_A, P_B, P_C); \ 2521*c217d954SCole Faust REPEAT_3_8(P_X, P_A, P_B, P_C) 2522*c217d954SCole Faust#define REPEAT_3_10(P_X, P_A, P_B, P_C) \ 2523*c217d954SCole Faust P_X##_DEF(9, P_A, P_B, P_C); \ 2524*c217d954SCole Faust REPEAT_3_9(P_X, P_A, P_B, P_C) 2525*c217d954SCole Faust#define REPEAT_3_11(P_X, P_A, P_B, P_C) \ 2526*c217d954SCole Faust P_X##_DEF(A, P_A, P_B, P_C); \ 2527*c217d954SCole Faust REPEAT_3_10(P_X, P_A, P_B, P_C) 2528*c217d954SCole Faust#define REPEAT_3_12(P_X, P_A, P_B, P_C) \ 2529*c217d954SCole Faust P_X##_DEF(B, P_A, P_B, P_C); \ 2530*c217d954SCole Faust REPEAT_3_11(P_X, P_A, P_B, P_C) 2531*c217d954SCole Faust#define REPEAT_3_13(P_X, P_A, P_B, P_C) \ 2532*c217d954SCole Faust P_X##_DEF(C, P_A, P_B, P_C); \ 2533*c217d954SCole Faust REPEAT_3_12(P_X, P_A, P_B, P_C) 2534*c217d954SCole Faust#define REPEAT_3_14(P_X, P_A, P_B, P_C) \ 2535*c217d954SCole Faust P_X##_DEF(D, P_A, P_B, P_C); \ 2536*c217d954SCole Faust REPEAT_3_13(P_X, P_A, P_B, P_C) 2537*c217d954SCole Faust#define REPEAT_3_15(P_X, P_A, P_B, P_C) \ 2538*c217d954SCole Faust P_X##_DEF(E, P_A, P_B, P_C); \ 2539*c217d954SCole Faust REPEAT_3_14(P_X, P_A, P_B, P_C) 2540*c217d954SCole Faust#define REPEAT_3_16(P_X, P_A, P_B, P_C) \ 2541*c217d954SCole Faust P_X##_DEF(F, P_A, P_B, P_C); \ 2542*c217d954SCole Faust REPEAT_3_15(P_X, P_A, P_B, P_C) 2543*c217d954SCole Faust 2544*c217d954SCole Faust#define REPEAT_DEF_3_N(P_NUM, P_OP, P_A, P_B, P_C) REPEAT_3_##P_NUM(P_OP, P_A, P_B, P_C) 2545*c217d954SCole Faust#define REPEAT_3_N(P_NUM, P_OP, P_A, P_B, P_C) REPEAT_DEF_3_N(P_NUM, P_OP, P_A, P_B, P_C) 2546*c217d954SCole Faust 2547*c217d954SCole Faust 2548*c217d954SCole Faust#define REPEAT_4_1(P_X, P_A, P_B, P_C, P_D) P_X##_DEF(0, P_A, P_B, P_C, P_D) 2549*c217d954SCole Faust#define REPEAT_4_2(P_X, P_A, P_B, P_C, P_D) \ 2550*c217d954SCole Faust P_X##_DEF(1, P_A, P_B, P_C, P_D); \ 2551*c217d954SCole Faust REPEAT_4_1(P_X, P_A, P_B, P_C, P_D) 2552*c217d954SCole Faust#define REPEAT_4_3(P_X, P_A, P_B, P_C, P_D) \ 2553*c217d954SCole Faust P_X##_DEF(2, P_A, P_B, P_C, P_D); \ 2554*c217d954SCole Faust REPEAT_4_2(P_X, P_A, P_B, P_C, P_D) 2555*c217d954SCole Faust#define REPEAT_4_4(P_X, P_A, P_B, P_C, P_D) \ 2556*c217d954SCole Faust P_X##_DEF(3, P_A, P_B, P_C, P_D); \ 2557*c217d954SCole Faust REPEAT_4_3(P_X, P_A, P_B, P_C, P_D) 2558*c217d954SCole Faust#define REPEAT_4_5(P_X, P_A, P_B, P_C, P_D) \ 2559*c217d954SCole Faust P_X##_DEF(4, P_A, P_B, P_C, P_D); \ 2560*c217d954SCole Faust REPEAT_4_4(P_X, P_A, P_B, P_C, P_D) 2561*c217d954SCole Faust#define REPEAT_4_6(P_X, P_A, P_B, P_C, P_D) \ 2562*c217d954SCole Faust P_X##_DEF(5, P_A, P_B, P_C, P_D); \ 2563*c217d954SCole Faust REPEAT_4_5(P_X, P_A, P_B, P_C, P_D) 2564*c217d954SCole Faust#define REPEAT_4_7(P_X, P_A, P_B, P_C, P_D) \ 2565*c217d954SCole Faust P_X##_DEF(6, P_A, P_B, P_C, P_D); \ 2566*c217d954SCole Faust REPEAT_4_6(P_X, P_A, P_B, P_C, P_D) 2567*c217d954SCole Faust#define REPEAT_4_8(P_X, P_A, P_B, P_C, P_D) \ 2568*c217d954SCole Faust P_X##_DEF(7, P_A, P_B, P_C, P_D); \ 2569*c217d954SCole Faust REPEAT_4_7(P_X, P_A, P_B, P_C, P_D) 2570*c217d954SCole Faust#define REPEAT_4_9(P_X, P_A, P_B, P_C, P_D) \ 2571*c217d954SCole Faust P_X##_DEF(8, P_A, P_B, P_C, P_D); \ 2572*c217d954SCole Faust REPEAT_4_8(P_X, P_A, P_B, P_C, P_D) 2573*c217d954SCole Faust#define REPEAT_4_10(P_X, P_A, P_B, P_C, P_D) \ 2574*c217d954SCole Faust P_X##_DEF(9, P_A, P_B, P_C, P_D); \ 2575*c217d954SCole Faust REPEAT_4_9(P_X, P_A, P_B, P_C, P_D) 2576*c217d954SCole Faust#define REPEAT_4_11(P_X, P_A, P_B, P_C, P_D) \ 2577*c217d954SCole Faust P_X##_DEF(A, P_A, P_B, P_C, P_D); \ 2578*c217d954SCole Faust REPEAT_4_10(P_X, P_A, P_B, P_C, P_D) 2579*c217d954SCole Faust#define REPEAT_4_12(P_X, P_A, P_B, P_C, P_D) \ 2580*c217d954SCole Faust P_X##_DEF(B, P_A, P_B, P_C, P_D); \ 2581*c217d954SCole Faust REPEAT_4_11(P_X, P_A, P_B, P_C, P_D) 2582*c217d954SCole Faust#define REPEAT_4_13(P_X, P_A, P_B, P_C, P_D) \ 2583*c217d954SCole Faust P_X##_DEF(C, P_A, P_B, P_C, P_D); \ 2584*c217d954SCole Faust REPEAT_4_12(P_X, P_A, P_B, P_C, P_D) 2585*c217d954SCole Faust#define REPEAT_4_14(P_X, P_A, P_B, P_C, P_D) \ 2586*c217d954SCole Faust P_X##_DEF(D, P_A, P_B, P_C, P_D); \ 2587*c217d954SCole Faust REPEAT_4_13(P_X, P_A, P_B, P_C, P_D) 2588*c217d954SCole Faust#define REPEAT_4_15(P_X, P_A, P_B, P_C, P_D) \ 2589*c217d954SCole Faust P_X##_DEF(E, P_A, P_B, P_C, P_D); \ 2590*c217d954SCole Faust REPEAT_4_14(P_X, P_A, P_B, P_C, P_D) 2591*c217d954SCole Faust#define REPEAT_4_16(P_X, P_A, P_B, P_C, P_D) \ 2592*c217d954SCole Faust P_X##_DEF(F, P_A, P_B, P_C, P_D); \ 2593*c217d954SCole Faust REPEAT_4_15(P_X, P_A, P_B, P_C, P_D) 2594*c217d954SCole Faust 2595*c217d954SCole Faust#define REPEAT_DEF_4_N(P_NUM, P_OP, P_A, P_B, P_C, P_D) REPEAT_4_##P_NUM(P_OP, P_A, P_B, P_C, P_D) 2596*c217d954SCole Faust#define REPEAT_4_N(P_NUM, P_OP, P_A, P_B, P_C, P_D) REPEAT_DEF_4_N(P_NUM, P_OP, P_A, P_B, P_C, P_D) 2597*c217d954SCole Faust 2598*c217d954SCole Faust 2599*c217d954SCole Faust#define VAR_INIT_TO_CONST_DEF(ID, TYPE, VAR, VAL) TYPE VAR##ID = VAL 2600*c217d954SCole Faust#define REPEAT_VAR_INIT_TO_CONST(N, TYPE, VAR, VAL) REPEAT_3_N(N, VAR_INIT_TO_CONST, TYPE, VAR, VAL) 2601*c217d954SCole Faust 2602*c217d954SCole Faust 2603*c217d954SCole Faust#define VAR_INIT_CONVERT_DEF(ID, TYPE_OUT, VAR_IN, VAR_OUT) TYPE_OUT VAR_OUT##ID = CONVERT(VAR_IN##ID, TYPE_OUT) 2604*c217d954SCole Faust#define REPEAT_VAR_INIT_CONVERT(N, TYPE_OUT, VAR_IN, VAR_OUT) REPEAT_3_N(N, VAR_INIT_CONVERT, TYPE_OUT, VAR_IN, VAR_OUT) 2605*c217d954SCole Faust 2606*c217d954SCole Faust 2607*c217d954SCole Faust#define VAR_INIT_CONVERT_SAT_DEF(ID, TYPE_OUT, VAR_IN, VAR_OUT) TYPE_OUT VAR_OUT##ID = CONVERT_SAT(VAR_IN##ID, TYPE_OUT) 2608*c217d954SCole Faust#define REPEAT_VAR_INIT_CONVERT_SAT(N, TYPE_OUT, VAR_IN, VAR_OUT) REPEAT_3_N(N, VAR_INIT_CONVERT_SAT, TYPE_OUT, VAR_IN, VAR_OUT) 2609*c217d954SCole Faust 2610*c217d954SCole Faust 2611*c217d954SCole Faust#define ADD_CONST_TO_VAR_DEF(ID, TYPE, VAR, VAL) VAR##ID += (TYPE)VAL 2612*c217d954SCole Faust#define REPEAT_ADD_CONST_TO_VAR(N, TYPE, VAR, VAL) REPEAT_3_N(N, ADD_CONST_TO_VAR, TYPE, VAR, VAL) 2613*c217d954SCole Faust 2614*c217d954SCole Faust 2615*c217d954SCole Faust#define MLA_VAR_WITH_CONST_VEC_DEF(ID, VAR_A, VAR_B, VAL) VAR_A##ID += VAR_B##ID * VAL 2616*c217d954SCole Faust#define REPEAT_MLA_VAR_WITH_CONST_VEC(N, VAR_A, VAR_B, VAL) REPEAT_3_N(N, MLA_VAR_WITH_CONST_VEC, VAR_A, VAR_B, VAL) 2617*c217d954SCole Faust 2618*c217d954SCole Faust 2619*c217d954SCole Faust#define ADD_VECTOR_TO_VAR_DEF(ID, TYPE, VAR, VEC) VAR##ID += VEC 2620*c217d954SCole Faust#define REPEAT_ADD_VECTOR_TO_VAR(N, VAR, VEC) REPEAT_3_N(N, ADD_VECTOR_TO_VAR, "", VAR, VEC) 2621*c217d954SCole Faust 2622*c217d954SCole Faust 2623*c217d954SCole Faust#define ADD_TWO_VARS_DEF(ID, TYPE, VAR_A, VAR_B) VAR_A##ID += VAR_B##ID 2624*c217d954SCole Faust#define REPEAT_ADD_TWO_VARS(N, VAR_A, VAR_B) REPEAT_3_N(N, ADD_TWO_VARS, "", VAR_A, VAR_B) 2625*c217d954SCole Faust 2626*c217d954SCole Faust 2627*c217d954SCole Faust#define MAX_CONST_VAR_DEF(ID, TYPE, VAR, VAL) VAR##ID = max(VAR##ID, (TYPE)VAL) 2628*c217d954SCole Faust#define REPEAT_MAX_CONST_VAR(N, TYPE, VAR, VAL) REPEAT_3_N(N, MAX_CONST_VAR, TYPE, VAR, VAL) 2629*c217d954SCole Faust 2630*c217d954SCole Faust 2631*c217d954SCole Faust#define MIN_CONST_VAR_DEF(ID, TYPE, VAR, VAL) VAR##ID = min(VAR##ID, (TYPE)VAL) 2632*c217d954SCole Faust#define REPEAT_MIN_CONST_VAR(N, TYPE, VAR, VAL) REPEAT_3_N(N, MIN_CONST_VAR, TYPE, VAR, VAL) 2633*c217d954SCole Faust 2634*c217d954SCole Faust 2635*c217d954SCole Faust#define ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE_DEF(ID, SIZE, VAR, RES_MUL, RES_SHIFT) VAR##ID = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(VAR##ID, RES_MUL, RES_SHIFT, SIZE) 2636*c217d954SCole Faust#define REPEAT_ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(N, SIZE, VAR, RES_MUL, RES_SHIFT) REPEAT_4_N(N, ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE, SIZE, VAR, RES_MUL, RES_SHIFT) 2637*c217d954SCole Faust 2638*c217d954SCole Faust 2639*c217d954SCole Faust#define ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE_DEF(ID, SIZE, VAR, RES_MUL, RES_SHIFT) VAR##ID = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(VAR##ID, RES_MUL, RES_SHIFT, SIZE) 2640*c217d954SCole Faust#define REPEAT_ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(N, SIZE, VAR, RES_MUL, RES_SHIFT) REPEAT_4_N(N, ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE, SIZE, VAR, RES_MUL, RES_SHIFT) 2641*c217d954SCole Faust 2642*c217d954SCole Faust 2643*c217d954SCole Faust#define ASYMM_MULT_BY_QUANT_MULTIPLIER_PER_CHANNEL_DEF(ID, SIZE, VAR, RES_MUL, RES_SHIFT) \ 2644*c217d954SCole Faust ({ \ 2645*c217d954SCole Faust VEC_DATA_TYPE(int, N0) \ 2646*c217d954SCole Faust VAR##ID_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(VAR##ID, RES_MUL, RES_SHIFT, N0); \ 2647*c217d954SCole Faust VEC_DATA_TYPE(int, N0) \ 2648*c217d954SCole Faust VAR##ID_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(VAR##ID, RES_MUL, RES_SHIFT, N0); \ 2649*c217d954SCole Faust VAR##ID = select(VAR##ID_shift_lt0, VAR##ID_shift_gt0, RES_SHIFT >= 0); \ 2650*c217d954SCole Faust }) 2651*c217d954SCole Faust#define REPEAT_ASYMM_MULT_BY_QUANT_MULTIPLIER_PER_CHANNEL(N, SIZE, VAR, RES_MUL, RES_SHIFT) REPEAT_4_N(N, ASYMM_MULT_BY_QUANT_MULTIPLIER_PER_CHANNEL, SIZE, VAR, RES_MUL, RES_SHIFT) 2652*c217d954SCole Faust 2653*c217d954SCole Faust#endif 2654*c217d954SCole Faust 2655*c217d954SCole Faust#ifndef SRC_CORE_CL_CL_KERNELS_TILE_HELPERS 2656*c217d954SCole Faust#define SRC_CORE_CL_CL_KERNELS_TILE_HELPERS 2657*c217d954SCole Faust 2658*c217d954SCole Faust 2659*c217d954SCole Faust 2660*c217d954SCole Faust 2661*c217d954SCole Faust#define TILE_VECTOR_SIZE1 1 2662*c217d954SCole Faust#define TILE_VECTOR_SIZE2 2 2663*c217d954SCole Faust#define TILE_VECTOR_SIZE3 3 2664*c217d954SCole Faust#define TILE_VECTOR_SIZE4 4 2665*c217d954SCole Faust#define TILE_VECTOR_SIZE5 8 2666*c217d954SCole Faust#define TILE_VECTOR_SIZE6 8 2667*c217d954SCole Faust#define TILE_VECTOR_SIZE7 8 2668*c217d954SCole Faust#define TILE_VECTOR_SIZE8 8 2669*c217d954SCole Faust#define TILE_VECTOR_SIZE9 16 2670*c217d954SCole Faust#define TILE_VECTOR_SIZE10 16 2671*c217d954SCole Faust#define TILE_VECTOR_SIZE11 16 2672*c217d954SCole Faust#define TILE_VECTOR_SIZE12 16 2673*c217d954SCole Faust#define TILE_VECTOR_SIZE13 16 2674*c217d954SCole Faust#define TILE_VECTOR_SIZE14 16 2675*c217d954SCole Faust#define TILE_VECTOR_SIZE15 16 2676*c217d954SCole Faust#define TILE_VECTOR_SIZE16 16 2677*c217d954SCole Faust 2678*c217d954SCole Faust#define TILE_VECTOR_TYPE1(DATA_TYPE) DATA_TYPE##1 2679*c217d954SCole Faust#define TILE_VECTOR_TYPE2(DATA_TYPE) DATA_TYPE##2 2680*c217d954SCole Faust#define TILE_VECTOR_TYPE3(DATA_TYPE) DATA_TYPE##3 2681*c217d954SCole Faust#define TILE_VECTOR_TYPE4(DATA_TYPE) DATA_TYPE##4 2682*c217d954SCole Faust#define TILE_VECTOR_TYPE5(DATA_TYPE) DATA_TYPE##8 2683*c217d954SCole Faust#define TILE_VECTOR_TYPE6(DATA_TYPE) DATA_TYPE##8 2684*c217d954SCole Faust#define TILE_VECTOR_TYPE7(DATA_TYPE) DATA_TYPE##8 2685*c217d954SCole Faust#define TILE_VECTOR_TYPE8(DATA_TYPE) DATA_TYPE##8 2686*c217d954SCole Faust#define TILE_VECTOR_TYPE9(DATA_TYPE) DATA_TYPE##16 2687*c217d954SCole Faust#define TILE_VECTOR_TYPE10(DATA_TYPE) DATA_TYPE##16 2688*c217d954SCole Faust#define TILE_VECTOR_TYPE11(DATA_TYPE) DATA_TYPE##16 2689*c217d954SCole Faust#define TILE_VECTOR_TYPE12(DATA_TYPE) DATA_TYPE##16 2690*c217d954SCole Faust#define TILE_VECTOR_TYPE13(DATA_TYPE) DATA_TYPE##16 2691*c217d954SCole Faust#define TILE_VECTOR_TYPE14(DATA_TYPE) DATA_TYPE##16 2692*c217d954SCole Faust#define TILE_VECTOR_TYPE15(DATA_TYPE) DATA_TYPE##16 2693*c217d954SCole Faust#define TILE_VECTOR_TYPE16(DATA_TYPE) DATA_TYPE##16 2694*c217d954SCole Faust 2695*c217d954SCole Faust 2696*c217d954SCole Faust#define TILE(DATA_TYPE, H, W, BASENAME) TILE_STR(DATA_TYPE, H, W, BASENAME) 2697*c217d954SCole Faust#define TILE_STR(DATA_TYPE, H, W, BASENAME) \ 2698*c217d954SCole Faust union { \ 2699*c217d954SCole Faust DATA_TYPE s[TILE_VECTOR_SIZE##W]; \ 2700*c217d954SCole Faust TILE_VECTOR_TYPE##W(DATA_TYPE) v; \ 2701*c217d954SCole Faust } BASENAME[H] 2702*c217d954SCole Faust 2703*c217d954SCole Faust#define TENSOR4D_IMAGE(name) \ 2704*c217d954SCole Faust __read_only image2d_t name##_img, \ 2705*c217d954SCole Faust __global uchar *name##_ptr, \ 2706*c217d954SCole Faust uint name##_stride_x, \ 2707*c217d954SCole Faust uint name##_step_x, \ 2708*c217d954SCole Faust uint name##_stride_y, \ 2709*c217d954SCole Faust uint name##_step_y, \ 2710*c217d954SCole Faust uint name##_stride_z, \ 2711*c217d954SCole Faust uint name##_step_z, \ 2712*c217d954SCole Faust uint name##_stride_w, \ 2713*c217d954SCole Faust uint name##_step_w, \ 2714*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2715*c217d954SCole Faust 2716*c217d954SCole Faust#define TENSOR4D_BUFFER(name) \ 2717*c217d954SCole Faust __global uchar *name##_ptr, \ 2718*c217d954SCole Faust uint name##_stride_x, \ 2719*c217d954SCole Faust uint name##_step_x, \ 2720*c217d954SCole Faust uint name##_stride_y, \ 2721*c217d954SCole Faust uint name##_step_y, \ 2722*c217d954SCole Faust uint name##_stride_z, \ 2723*c217d954SCole Faust uint name##_step_z, \ 2724*c217d954SCole Faust uint name##_stride_w, \ 2725*c217d954SCole Faust uint name##_step_w, \ 2726*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2727*c217d954SCole Faust 2728*c217d954SCole Faust#define TENSOR4D_STR(name, type) TENSOR4D_##type(name) 2729*c217d954SCole Faust#define TENSOR4D(name, type) TENSOR4D_STR(name, type) 2730*c217d954SCole Faust 2731*c217d954SCole Faust#define TENSOR4D_T_IMAGE(name) \ 2732*c217d954SCole Faust __read_only image2d_t name##_img, \ 2733*c217d954SCole Faust __global uchar *name##_ptr, \ 2734*c217d954SCole Faust uint name##_stride_y, \ 2735*c217d954SCole Faust uint name##_stride_z, \ 2736*c217d954SCole Faust uint name##_stride_w, \ 2737*c217d954SCole Faust uint name##_c, \ 2738*c217d954SCole Faust uint name##_w, \ 2739*c217d954SCole Faust uint name##_h, \ 2740*c217d954SCole Faust uint name##_n, \ 2741*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2742*c217d954SCole Faust 2743*c217d954SCole Faust#define TENSOR4D_T_BUFFER(name) \ 2744*c217d954SCole Faust __global uchar *name##_ptr, \ 2745*c217d954SCole Faust uint name##_stride_y, \ 2746*c217d954SCole Faust uint name##_stride_z, \ 2747*c217d954SCole Faust uint name##_stride_w, \ 2748*c217d954SCole Faust uint name##_c, \ 2749*c217d954SCole Faust uint name##_w, \ 2750*c217d954SCole Faust uint name##_h, \ 2751*c217d954SCole Faust uint name##_n, \ 2752*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2753*c217d954SCole Faust 2754*c217d954SCole Faust#define TENSOR4D_T_STR(name, type) TENSOR4D_T_##type(name) 2755*c217d954SCole Faust 2756*c217d954SCole Faust 2757*c217d954SCole Faust#define TENSOR4D_T(name, type) TENSOR4D_T_STR(name, type) 2758*c217d954SCole Faust 2759*c217d954SCole Faust#define TENSOR4D_RO_T_IMAGE(name) \ 2760*c217d954SCole Faust __read_only image2d_t name##_img, \ 2761*c217d954SCole Faust TENSOR4D_T_BUFFER(name) 2762*c217d954SCole Faust 2763*c217d954SCole Faust#define TENSOR4D_RO_T_BUFFER(name) TENSOR4D_T_BUFFER(name) 2764*c217d954SCole Faust 2765*c217d954SCole Faust#define TENSOR4D_RO_T_STR(name, type) TENSOR4D_RO_T_##type(name) 2766*c217d954SCole Faust 2767*c217d954SCole Faust 2768*c217d954SCole Faust#define TENSOR4D_RO_T(name, type) TENSOR4D_RO_T_STR(name, type) 2769*c217d954SCole Faust 2770*c217d954SCole Faust#define TENSOR4D_WO_T_IMAGE(name) \ 2771*c217d954SCole Faust __write_only image2d_t name##_img, \ 2772*c217d954SCole Faust TENSOR4D_T_BUFFER(name) 2773*c217d954SCole Faust 2774*c217d954SCole Faust#define TENSOR4D_WO_T_BUFFER(name) TENSOR4D_T_BUFFER(name) 2775*c217d954SCole Faust 2776*c217d954SCole Faust#define TENSOR4D_WO_T_STR(name, type) TENSOR4D_WO_T_##type(name) 2777*c217d954SCole Faust 2778*c217d954SCole Faust 2779*c217d954SCole Faust#define TENSOR4D_WO_T(name, type) TENSOR4D_WO_T_STR(name, type) 2780*c217d954SCole Faust 2781*c217d954SCole Faust#define TENSOR3D_T_IMAGE(name) \ 2782*c217d954SCole Faust __read_only image2d_t name##_img, \ 2783*c217d954SCole Faust __global uchar *name##_ptr, \ 2784*c217d954SCole Faust uint name##_stride_y, \ 2785*c217d954SCole Faust uint name##_stride_z, \ 2786*c217d954SCole Faust uint name##_w, \ 2787*c217d954SCole Faust uint name##_h, \ 2788*c217d954SCole Faust uint name##_n, \ 2789*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2790*c217d954SCole Faust 2791*c217d954SCole Faust#define TENSOR3D_T_BUFFER(name) \ 2792*c217d954SCole Faust __global uchar *name##_ptr, \ 2793*c217d954SCole Faust uint name##_stride_y, \ 2794*c217d954SCole Faust uint name##_stride_z, \ 2795*c217d954SCole Faust uint name##_w, \ 2796*c217d954SCole Faust uint name##_h, \ 2797*c217d954SCole Faust uint name##_n, \ 2798*c217d954SCole Faust uint name##_offset_first_element_in_bytes 2799*c217d954SCole Faust 2800*c217d954SCole Faust#define TENSOR3D_T_STR(name, type) TENSOR3D_T_##type(name) 2801*c217d954SCole Faust#define TENSOR3D_T(name, type) TENSOR3D_T_STR(name, type) 2802*c217d954SCole Faust 2803*c217d954SCole Faust#if !defined(UNROLL_WITH_PRAGMA) 2804*c217d954SCole Faust#define UNROLL_INCR(idx, step, macro) idx += (step); (macro) 2805*c217d954SCole Faust 2806*c217d954SCole Faust#define LOOP_UNROLLING_1(idx, step, macro) (macro) 2807*c217d954SCole Faust#define LOOP_UNROLLING_2(idx, step, macro) LOOP_UNROLLING_1(idx, step, macro); UNROLL_INCR(idx, step, macro) 2808*c217d954SCole Faust#define LOOP_UNROLLING_3(idx, step, macro) LOOP_UNROLLING_2(idx, step, macro); UNROLL_INCR(idx, step, macro) 2809*c217d954SCole Faust#define LOOP_UNROLLING_4(idx, step, macro) LOOP_UNROLLING_3(idx, step, macro); UNROLL_INCR(idx, step, macro) 2810*c217d954SCole Faust#define LOOP_UNROLLING_5(idx, step, macro) LOOP_UNROLLING_4(idx, step, macro); UNROLL_INCR(idx, step, macro) 2811*c217d954SCole Faust#define LOOP_UNROLLING_6(idx, step, macro) LOOP_UNROLLING_5(idx, step, macro); UNROLL_INCR(idx, step, macro) 2812*c217d954SCole Faust#define LOOP_UNROLLING_7(idx, step, macro) LOOP_UNROLLING_6(idx, step, macro); UNROLL_INCR(idx, step, macro) 2813*c217d954SCole Faust#define LOOP_UNROLLING_8(idx, step, macro) LOOP_UNROLLING_7(idx, step, macro); UNROLL_INCR(idx, step, macro) 2814*c217d954SCole Faust#define LOOP_UNROLLING_9(idx, step, macro) LOOP_UNROLLING_8(idx, step, macro); UNROLL_INCR(idx, step, macro) 2815*c217d954SCole Faust#define LOOP_UNROLLING_10(idx, step, macro) LOOP_UNROLLING_9(idx, step, macro); UNROLL_INCR(idx, step, macro) 2816*c217d954SCole Faust#define LOOP_UNROLLING_11(idx, step, macro) LOOP_UNROLLING_10(idx, step, macro); UNROLL_INCR(idx, step, macro) 2817*c217d954SCole Faust#define LOOP_UNROLLING_12(idx, step, macro) LOOP_UNROLLING_11(idx, step, macro); UNROLL_INCR(idx, step, macro) 2818*c217d954SCole Faust#define LOOP_UNROLLING_13(idx, step, macro) LOOP_UNROLLING_12(idx, step, macro); UNROLL_INCR(idx, step, macro) 2819*c217d954SCole Faust#define LOOP_UNROLLING_14(idx, step, macro) LOOP_UNROLLING_13(idx, step, macro); UNROLL_INCR(idx, step, macro) 2820*c217d954SCole Faust#define LOOP_UNROLLING_15(idx, step, macro) LOOP_UNROLLING_14(idx, step, macro); UNROLL_INCR(idx, step, macro) 2821*c217d954SCole Faust#define LOOP_UNROLLING_16(idx, step, macro) LOOP_UNROLLING_15(idx, step, macro); UNROLL_INCR(idx, step, macro) 2822*c217d954SCole Faust#define LOOP_UNROLLING_17(idx, step, macro) LOOP_UNROLLING_16(idx, step, macro); UNROLL_INCR(idx, step, macro) 2823*c217d954SCole Faust#define LOOP_UNROLLING_18(idx, step, macro) LOOP_UNROLLING_17(idx, step, macro); UNROLL_INCR(idx, step, macro) 2824*c217d954SCole Faust#define LOOP_UNROLLING_19(idx, step, macro) LOOP_UNROLLING_18(idx, step, macro); UNROLL_INCR(idx, step, macro) 2825*c217d954SCole Faust#define LOOP_UNROLLING_20(idx, step, macro) LOOP_UNROLLING_19(idx, step, macro); UNROLL_INCR(idx, step, macro) 2826*c217d954SCole Faust#define LOOP_UNROLLING_21(idx, step, macro) LOOP_UNROLLING_20(idx, step, macro); UNROLL_INCR(idx, step, macro) 2827*c217d954SCole Faust#define LOOP_UNROLLING_22(idx, step, macro) LOOP_UNROLLING_21(idx, step, macro); UNROLL_INCR(idx, step, macro) 2828*c217d954SCole Faust#define LOOP_UNROLLING_23(idx, step, macro) LOOP_UNROLLING_22(idx, step, macro); UNROLL_INCR(idx, step, macro) 2829*c217d954SCole Faust#define LOOP_UNROLLING_24(idx, step, macro) LOOP_UNROLLING_23(idx, step, macro); UNROLL_INCR(idx, step, macro) 2830*c217d954SCole Faust#define LOOP_UNROLLING_25(idx, step, macro) LOOP_UNROLLING_24(idx, step, macro); UNROLL_INCR(idx, step, macro) 2831*c217d954SCole Faust#define LOOP_UNROLLING_26(idx, step, macro) LOOP_UNROLLING_25(idx, step, macro); UNROLL_INCR(idx, step, macro) 2832*c217d954SCole Faust#define LOOP_UNROLLING_27(idx, step, macro) LOOP_UNROLLING_26(idx, step, macro); UNROLL_INCR(idx, step, macro) 2833*c217d954SCole Faust#define LOOP_UNROLLING_28(idx, step, macro) LOOP_UNROLLING_27(idx, step, macro); UNROLL_INCR(idx, step, macro) 2834*c217d954SCole Faust#define LOOP_UNROLLING_29(idx, step, macro) LOOP_UNROLLING_28(idx, step, macro); UNROLL_INCR(idx, step, macro) 2835*c217d954SCole Faust#define LOOP_UNROLLING_30(idx, step, macro) LOOP_UNROLLING_29(idx, step, macro); UNROLL_INCR(idx, step, macro) 2836*c217d954SCole Faust#define LOOP_UNROLLING_31(idx, step, macro) LOOP_UNROLLING_30(idx, step, macro); UNROLL_INCR(idx, step, macro) 2837*c217d954SCole Faust#define LOOP_UNROLLING_32(idx, step, macro) LOOP_UNROLLING_31(idx, step, macro); UNROLL_INCR(idx, step, macro) 2838*c217d954SCole Faust#define LOOP_UNROLLING_33(idx, step, macro) LOOP_UNROLLING_32(idx, step, macro); UNROLL_INCR(idx, step, macro) 2839*c217d954SCole Faust#define LOOP_UNROLLING_34(idx, step, macro) LOOP_UNROLLING_33(idx, step, macro); UNROLL_INCR(idx, step, macro) 2840*c217d954SCole Faust#define LOOP_UNROLLING_35(idx, step, macro) LOOP_UNROLLING_34(idx, step, macro); UNROLL_INCR(idx, step, macro) 2841*c217d954SCole Faust#define LOOP_UNROLLING_36(idx, step, macro) LOOP_UNROLLING_35(idx, step, macro); UNROLL_INCR(idx, step, macro) 2842*c217d954SCole Faust#define LOOP_UNROLLING_37(idx, step, macro) LOOP_UNROLLING_36(idx, step, macro); UNROLL_INCR(idx, step, macro) 2843*c217d954SCole Faust#define LOOP_UNROLLING_38(idx, step, macro) LOOP_UNROLLING_37(idx, step, macro); UNROLL_INCR(idx, step, macro) 2844*c217d954SCole Faust#define LOOP_UNROLLING_39(idx, step, macro) LOOP_UNROLLING_38(idx, step, macro); UNROLL_INCR(idx, step, macro) 2845*c217d954SCole Faust#define LOOP_UNROLLING_40(idx, step, macro) LOOP_UNROLLING_39(idx, step, macro); UNROLL_INCR(idx, step, macro) 2846*c217d954SCole Faust#define LOOP_UNROLLING_41(idx, step, macro) LOOP_UNROLLING_40(idx, step, macro); UNROLL_INCR(idx, step, macro) 2847*c217d954SCole Faust#define LOOP_UNROLLING_42(idx, step, macro) LOOP_UNROLLING_41(idx, step, macro); UNROLL_INCR(idx, step, macro) 2848*c217d954SCole Faust#define LOOP_UNROLLING_43(idx, step, macro) LOOP_UNROLLING_42(idx, step, macro); UNROLL_INCR(idx, step, macro) 2849*c217d954SCole Faust#define LOOP_UNROLLING_44(idx, step, macro) LOOP_UNROLLING_43(idx, step, macro); UNROLL_INCR(idx, step, macro) 2850*c217d954SCole Faust#define LOOP_UNROLLING_45(idx, step, macro) LOOP_UNROLLING_44(idx, step, macro); UNROLL_INCR(idx, step, macro) 2851*c217d954SCole Faust#define LOOP_UNROLLING_46(idx, step, macro) LOOP_UNROLLING_45(idx, step, macro); UNROLL_INCR(idx, step, macro) 2852*c217d954SCole Faust#define LOOP_UNROLLING_47(idx, step, macro) LOOP_UNROLLING_46(idx, step, macro); UNROLL_INCR(idx, step, macro) 2853*c217d954SCole Faust#define LOOP_UNROLLING_48(idx, step, macro) LOOP_UNROLLING_47(idx, step, macro); UNROLL_INCR(idx, step, macro) 2854*c217d954SCole Faust#define LOOP_UNROLLING_49(idx, step, macro) LOOP_UNROLLING_48(idx, step, macro); UNROLL_INCR(idx, step, macro) 2855*c217d954SCole Faust#define LOOP_UNROLLING_50(idx, step, macro) LOOP_UNROLLING_49(idx, step, macro); UNROLL_INCR(idx, step, macro) 2856*c217d954SCole Faust#define LOOP_UNROLLING_51(idx, step, macro) LOOP_UNROLLING_50(idx, step, macro); UNROLL_INCR(idx, step, macro) 2857*c217d954SCole Faust#define LOOP_UNROLLING_52(idx, step, macro) LOOP_UNROLLING_51(idx, step, macro); UNROLL_INCR(idx, step, macro) 2858*c217d954SCole Faust#define LOOP_UNROLLING_53(idx, step, macro) LOOP_UNROLLING_52(idx, step, macro); UNROLL_INCR(idx, step, macro) 2859*c217d954SCole Faust#define LOOP_UNROLLING_54(idx, step, macro) LOOP_UNROLLING_53(idx, step, macro); UNROLL_INCR(idx, step, macro) 2860*c217d954SCole Faust#define LOOP_UNROLLING_55(idx, step, macro) LOOP_UNROLLING_54(idx, step, macro); UNROLL_INCR(idx, step, macro) 2861*c217d954SCole Faust#define LOOP_UNROLLING_56(idx, step, macro) LOOP_UNROLLING_55(idx, step, macro); UNROLL_INCR(idx, step, macro) 2862*c217d954SCole Faust#define LOOP_UNROLLING_57(idx, step, macro) LOOP_UNROLLING_56(idx, step, macro); UNROLL_INCR(idx, step, macro) 2863*c217d954SCole Faust#define LOOP_UNROLLING_58(idx, step, macro) LOOP_UNROLLING_57(idx, step, macro); UNROLL_INCR(idx, step, macro) 2864*c217d954SCole Faust#define LOOP_UNROLLING_59(idx, step, macro) LOOP_UNROLLING_58(idx, step, macro); UNROLL_INCR(idx, step, macro) 2865*c217d954SCole Faust#define LOOP_UNROLLING_60(idx, step, macro) LOOP_UNROLLING_59(idx, step, macro); UNROLL_INCR(idx, step, macro) 2866*c217d954SCole Faust#define LOOP_UNROLLING_61(idx, step, macro) LOOP_UNROLLING_60(idx, step, macro); UNROLL_INCR(idx, step, macro) 2867*c217d954SCole Faust#define LOOP_UNROLLING_62(idx, step, macro) LOOP_UNROLLING_61(idx, step, macro); UNROLL_INCR(idx, step, macro) 2868*c217d954SCole Faust#define LOOP_UNROLLING_63(idx, step, macro) LOOP_UNROLLING_62(idx, step, macro); UNROLL_INCR(idx, step, macro) 2869*c217d954SCole Faust#define LOOP_UNROLLING_64(idx, step, macro) LOOP_UNROLLING_63(idx, step, macro); UNROLL_INCR(idx, step, macro) 2870*c217d954SCole Faust#define LOOP_UNROLLING_65(idx, step, macro) LOOP_UNROLLING_64(idx, step, macro); UNROLL_INCR(idx, step, macro) 2871*c217d954SCole Faust#define LOOP_UNROLLING_66(idx, step, macro) LOOP_UNROLLING_65(idx, step, macro); UNROLL_INCR(idx, step, macro) 2872*c217d954SCole Faust#define LOOP_UNROLLING_67(idx, step, macro) LOOP_UNROLLING_66(idx, step, macro); UNROLL_INCR(idx, step, macro) 2873*c217d954SCole Faust#define LOOP_UNROLLING_68(idx, step, macro) LOOP_UNROLLING_67(idx, step, macro); UNROLL_INCR(idx, step, macro) 2874*c217d954SCole Faust#define LOOP_UNROLLING_69(idx, step, macro) LOOP_UNROLLING_68(idx, step, macro); UNROLL_INCR(idx, step, macro) 2875*c217d954SCole Faust#define LOOP_UNROLLING_70(idx, step, macro) LOOP_UNROLLING_69(idx, step, macro); UNROLL_INCR(idx, step, macro) 2876*c217d954SCole Faust#define LOOP_UNROLLING_71(idx, step, macro) LOOP_UNROLLING_70(idx, step, macro); UNROLL_INCR(idx, step, macro) 2877*c217d954SCole Faust#define LOOP_UNROLLING_72(idx, step, macro) LOOP_UNROLLING_71(idx, step, macro); UNROLL_INCR(idx, step, macro) 2878*c217d954SCole Faust#define LOOP_UNROLLING_73(idx, step, macro) LOOP_UNROLLING_72(idx, step, macro); UNROLL_INCR(idx, step, macro) 2879*c217d954SCole Faust#define LOOP_UNROLLING_74(idx, step, macro) LOOP_UNROLLING_73(idx, step, macro); UNROLL_INCR(idx, step, macro) 2880*c217d954SCole Faust#define LOOP_UNROLLING_75(idx, step, macro) LOOP_UNROLLING_74(idx, step, macro); UNROLL_INCR(idx, step, macro) 2881*c217d954SCole Faust#define LOOP_UNROLLING_76(idx, step, macro) LOOP_UNROLLING_75(idx, step, macro); UNROLL_INCR(idx, step, macro) 2882*c217d954SCole Faust#define LOOP_UNROLLING_77(idx, step, macro) LOOP_UNROLLING_76(idx, step, macro); UNROLL_INCR(idx, step, macro) 2883*c217d954SCole Faust#define LOOP_UNROLLING_78(idx, step, macro) LOOP_UNROLLING_77(idx, step, macro); UNROLL_INCR(idx, step, macro) 2884*c217d954SCole Faust#define LOOP_UNROLLING_79(idx, step, macro) LOOP_UNROLLING_78(idx, step, macro); UNROLL_INCR(idx, step, macro) 2885*c217d954SCole Faust#define LOOP_UNROLLING_80(idx, step, macro) LOOP_UNROLLING_79(idx, step, macro); UNROLL_INCR(idx, step, macro) 2886*c217d954SCole Faust#define LOOP_UNROLLING_81(idx, step, macro) LOOP_UNROLLING_80(idx, step, macro); UNROLL_INCR(idx, step, macro) 2887*c217d954SCole Faust#define LOOP_UNROLLING_82(idx, step, macro) LOOP_UNROLLING_81(idx, step, macro); UNROLL_INCR(idx, step, macro) 2888*c217d954SCole Faust#define LOOP_UNROLLING_83(idx, step, macro) LOOP_UNROLLING_82(idx, step, macro); UNROLL_INCR(idx, step, macro) 2889*c217d954SCole Faust#define LOOP_UNROLLING_84(idx, step, macro) LOOP_UNROLLING_83(idx, step, macro); UNROLL_INCR(idx, step, macro) 2890*c217d954SCole Faust#define LOOP_UNROLLING_85(idx, step, macro) LOOP_UNROLLING_84(idx, step, macro); UNROLL_INCR(idx, step, macro) 2891*c217d954SCole Faust#define LOOP_UNROLLING_86(idx, step, macro) LOOP_UNROLLING_85(idx, step, macro); UNROLL_INCR(idx, step, macro) 2892*c217d954SCole Faust#define LOOP_UNROLLING_87(idx, step, macro) LOOP_UNROLLING_86(idx, step, macro); UNROLL_INCR(idx, step, macro) 2893*c217d954SCole Faust#define LOOP_UNROLLING_88(idx, step, macro) LOOP_UNROLLING_87(idx, step, macro); UNROLL_INCR(idx, step, macro) 2894*c217d954SCole Faust#define LOOP_UNROLLING_89(idx, step, macro) LOOP_UNROLLING_88(idx, step, macro); UNROLL_INCR(idx, step, macro) 2895*c217d954SCole Faust#define LOOP_UNROLLING_90(idx, step, macro) LOOP_UNROLLING_89(idx, step, macro); UNROLL_INCR(idx, step, macro) 2896*c217d954SCole Faust#define LOOP_UNROLLING_91(idx, step, macro) LOOP_UNROLLING_90(idx, step, macro); UNROLL_INCR(idx, step, macro) 2897*c217d954SCole Faust#define LOOP_UNROLLING_92(idx, step, macro) LOOP_UNROLLING_91(idx, step, macro); UNROLL_INCR(idx, step, macro) 2898*c217d954SCole Faust#define LOOP_UNROLLING_93(idx, step, macro) LOOP_UNROLLING_92(idx, step, macro); UNROLL_INCR(idx, step, macro) 2899*c217d954SCole Faust#define LOOP_UNROLLING_94(idx, step, macro) LOOP_UNROLLING_93(idx, step, macro); UNROLL_INCR(idx, step, macro) 2900*c217d954SCole Faust#define LOOP_UNROLLING_95(idx, step, macro) LOOP_UNROLLING_94(idx, step, macro); UNROLL_INCR(idx, step, macro) 2901*c217d954SCole Faust#define LOOP_UNROLLING_96(idx, step, macro) LOOP_UNROLLING_95(idx, step, macro); UNROLL_INCR(idx, step, macro) 2902*c217d954SCole Faust#define LOOP_UNROLLING_97(idx, step, macro) LOOP_UNROLLING_96(idx, step, macro); UNROLL_INCR(idx, step, macro) 2903*c217d954SCole Faust#define LOOP_UNROLLING_98(idx, step, macro) LOOP_UNROLLING_97(idx, step, macro); UNROLL_INCR(idx, step, macro) 2904*c217d954SCole Faust#define LOOP_UNROLLING_99(idx, step, macro) LOOP_UNROLLING_98(idx, step, macro); UNROLL_INCR(idx, step, macro) 2905*c217d954SCole Faust#define LOOP_UNROLLING_100(idx, step, macro) LOOP_UNROLLING_99(idx, step, macro); UNROLL_INCR(idx, step, macro) 2906*c217d954SCole Faust#define LOOP_UNROLLING_101(idx, step, macro) LOOP_UNROLLING_100(idx, step, macro); UNROLL_INCR(idx, step, macro) 2907*c217d954SCole Faust#define LOOP_UNROLLING_102(idx, step, macro) LOOP_UNROLLING_101(idx, step, macro); UNROLL_INCR(idx, step, macro) 2908*c217d954SCole Faust#define LOOP_UNROLLING_103(idx, step, macro) LOOP_UNROLLING_102(idx, step, macro); UNROLL_INCR(idx, step, macro) 2909*c217d954SCole Faust#define LOOP_UNROLLING_104(idx, step, macro) LOOP_UNROLLING_103(idx, step, macro); UNROLL_INCR(idx, step, macro) 2910*c217d954SCole Faust#define LOOP_UNROLLING_105(idx, step, macro) LOOP_UNROLLING_104(idx, step, macro); UNROLL_INCR(idx, step, macro) 2911*c217d954SCole Faust#define LOOP_UNROLLING_106(idx, step, macro) LOOP_UNROLLING_105(idx, step, macro); UNROLL_INCR(idx, step, macro) 2912*c217d954SCole Faust#define LOOP_UNROLLING_107(idx, step, macro) LOOP_UNROLLING_106(idx, step, macro); UNROLL_INCR(idx, step, macro) 2913*c217d954SCole Faust#define LOOP_UNROLLING_108(idx, step, macro) LOOP_UNROLLING_107(idx, step, macro); UNROLL_INCR(idx, step, macro) 2914*c217d954SCole Faust#define LOOP_UNROLLING_109(idx, step, macro) LOOP_UNROLLING_108(idx, step, macro); UNROLL_INCR(idx, step, macro) 2915*c217d954SCole Faust#define LOOP_UNROLLING_110(idx, step, macro) LOOP_UNROLLING_109(idx, step, macro); UNROLL_INCR(idx, step, macro) 2916*c217d954SCole Faust#define LOOP_UNROLLING_111(idx, step, macro) LOOP_UNROLLING_110(idx, step, macro); UNROLL_INCR(idx, step, macro) 2917*c217d954SCole Faust#define LOOP_UNROLLING_112(idx, step, macro) LOOP_UNROLLING_111(idx, step, macro); UNROLL_INCR(idx, step, macro) 2918*c217d954SCole Faust#define LOOP_UNROLLING_113(idx, step, macro) LOOP_UNROLLING_112(idx, step, macro); UNROLL_INCR(idx, step, macro) 2919*c217d954SCole Faust#define LOOP_UNROLLING_114(idx, step, macro) LOOP_UNROLLING_113(idx, step, macro); UNROLL_INCR(idx, step, macro) 2920*c217d954SCole Faust#define LOOP_UNROLLING_115(idx, step, macro) LOOP_UNROLLING_114(idx, step, macro); UNROLL_INCR(idx, step, macro) 2921*c217d954SCole Faust#define LOOP_UNROLLING_116(idx, step, macro) LOOP_UNROLLING_115(idx, step, macro); UNROLL_INCR(idx, step, macro) 2922*c217d954SCole Faust#define LOOP_UNROLLING_117(idx, step, macro) LOOP_UNROLLING_116(idx, step, macro); UNROLL_INCR(idx, step, macro) 2923*c217d954SCole Faust#define LOOP_UNROLLING_118(idx, step, macro) LOOP_UNROLLING_117(idx, step, macro); UNROLL_INCR(idx, step, macro) 2924*c217d954SCole Faust#define LOOP_UNROLLING_119(idx, step, macro) LOOP_UNROLLING_118(idx, step, macro); UNROLL_INCR(idx, step, macro) 2925*c217d954SCole Faust#define LOOP_UNROLLING_120(idx, step, macro) LOOP_UNROLLING_119(idx, step, macro); UNROLL_INCR(idx, step, macro) 2926*c217d954SCole Faust#define LOOP_UNROLLING_121(idx, step, macro) LOOP_UNROLLING_120(idx, step, macro); UNROLL_INCR(idx, step, macro) 2927*c217d954SCole Faust#define LOOP_UNROLLING_122(idx, step, macro) LOOP_UNROLLING_121(idx, step, macro); UNROLL_INCR(idx, step, macro) 2928*c217d954SCole Faust#define LOOP_UNROLLING_123(idx, step, macro) LOOP_UNROLLING_122(idx, step, macro); UNROLL_INCR(idx, step, macro) 2929*c217d954SCole Faust#define LOOP_UNROLLING_124(idx, step, macro) LOOP_UNROLLING_123(idx, step, macro); UNROLL_INCR(idx, step, macro) 2930*c217d954SCole Faust#define LOOP_UNROLLING_125(idx, step, macro) LOOP_UNROLLING_124(idx, step, macro); UNROLL_INCR(idx, step, macro) 2931*c217d954SCole Faust#define LOOP_UNROLLING_126(idx, step, macro) LOOP_UNROLLING_125(idx, step, macro); UNROLL_INCR(idx, step, macro) 2932*c217d954SCole Faust#define LOOP_UNROLLING_127(idx, step, macro) LOOP_UNROLLING_126(idx, step, macro); UNROLL_INCR(idx, step, macro) 2933*c217d954SCole Faust#define LOOP_UNROLLING_128(idx, step, macro) LOOP_UNROLLING_127(idx, step, macro); UNROLL_INCR(idx, step, macro) 2934*c217d954SCole Faust 2935*c217d954SCole Faust#define LOOP_UNROLLING_STR(type, idx, start, step, num, macro) \ 2936*c217d954SCole Faust { \ 2937*c217d954SCole Faust type idx = start; \ 2938*c217d954SCole Faust LOOP_UNROLLING_##num(idx, step, macro); \ 2939*c217d954SCole Faust } 2940*c217d954SCole Faust#else 2941*c217d954SCole Faust#define LOOP_UNROLLING_STR(type, idx, start, step, num, macro) \ 2942*c217d954SCole Faust { \ 2943*c217d954SCole Faust _Pragma("unroll") \ 2944*c217d954SCole Faust for(type idx = start; idx < (num * step); idx += step) \ 2945*c217d954SCole Faust { \ 2946*c217d954SCole Faust (macro); \ 2947*c217d954SCole Faust } \ 2948*c217d954SCole Faust } 2949*c217d954SCole Faust#endif 2950*c217d954SCole Faust#define LOOP_UNROLLING(type, idx, start, step, num, macro) LOOP_UNROLLING_STR(type, idx, start, step, num, macro) 2951*c217d954SCole Faust 2952*c217d954SCole Faust 2953*c217d954SCole Faust#define GET_SPATIAL_IDX(IDX, N0, PARTIAL_N0) (max((int)(get_global_id(IDX) * N0 - (N0 - PARTIAL_N0) % N0), 0)) 2954*c217d954SCole Faust 2955*c217d954SCole Faust 2956*c217d954SCole Faust#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) 2957*c217d954SCole Faust#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) 2958*c217d954SCole Faust#define DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 2959*c217d954SCole Faust ({ \ 2960*c217d954SCole Faust c += (C_DATA_TYPE)(a) * (C_DATA_TYPE)(b); \ 2961*c217d954SCole Faust }) 2962*c217d954SCole Faust#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_khr_integer_dot_product) 2963*c217d954SCole Faust#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))); 2964*c217d954SCole Faust#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)); 2965*c217d954SCole Faust#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += dot((a), (b)); 2966*c217d954SCole Faust#elif defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) 2967*c217d954SCole Faust#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)); 2968*c217d954SCole Faust#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)); 2969*c217d954SCole Faust#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c = arm_dot_acc((a), (b), (c)); 2970*c217d954SCole Faust#elif defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) 2971*c217d954SCole Faust#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))); 2972*c217d954SCole Faust#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)); 2973*c217d954SCole Faust#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) c += arm_dot((a), (b)); 2974*c217d954SCole Faust#else 2975*c217d954SCole Faust#define DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 2976*c217d954SCole Faust ({ \ 2977*c217d954SCole Faust c += (C_DATA_TYPE)(a).s0 * (C_DATA_TYPE)(b).s0; \ 2978*c217d954SCole Faust c += (C_DATA_TYPE)(a).s1 * (C_DATA_TYPE)(b).s1; \ 2979*c217d954SCole Faust }) 2980*c217d954SCole Faust#define DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 2981*c217d954SCole Faust ({ \ 2982*c217d954SCole Faust DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c); \ 2983*c217d954SCole Faust c += (C_DATA_TYPE)(a).s2 * (C_DATA_TYPE)(b).s2; \ 2984*c217d954SCole Faust }) 2985*c217d954SCole Faust#define DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, x, y, val) \ 2986*c217d954SCole Faust ({ \ 2987*c217d954SCole Faust val += (C_DATA_TYPE)(x).s0 * (C_DATA_TYPE)(y).s0; \ 2988*c217d954SCole Faust val += (C_DATA_TYPE)(x).s1 * (C_DATA_TYPE)(y).s1; \ 2989*c217d954SCole Faust val += (C_DATA_TYPE)(x).s2 * (C_DATA_TYPE)(y).s2; \ 2990*c217d954SCole Faust val += (C_DATA_TYPE)(x).s3 * (C_DATA_TYPE)(y).s3; \ 2991*c217d954SCole Faust }) 2992*c217d954SCole Faust#endif 2993*c217d954SCole Faust#define DOT_PRODUCT5_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 2994*c217d954SCole Faust ({ \ 2995*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 2996*c217d954SCole Faust DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s4), ((b).s4), c); \ 2997*c217d954SCole Faust }) 2998*c217d954SCole Faust#define DOT_PRODUCT6_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 2999*c217d954SCole Faust ({ \ 3000*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 3001*c217d954SCole Faust DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s45), ((b).s45), c); \ 3002*c217d954SCole Faust }) 3003*c217d954SCole Faust#define DOT_PRODUCT7_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3004*c217d954SCole Faust ({ \ 3005*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s0123), ((b).s0123), c); \ 3006*c217d954SCole Faust DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s456), ((b).s456), c); \ 3007*c217d954SCole Faust }) 3008*c217d954SCole Faust#define DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3009*c217d954SCole Faust ({ \ 3010*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).lo), ((b).lo), c); \ 3011*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).hi), ((b).hi), c); \ 3012*c217d954SCole Faust }) 3013*c217d954SCole Faust#define DOT_PRODUCT9_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3014*c217d954SCole Faust ({ \ 3015*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3016*c217d954SCole Faust DOT_PRODUCT1_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s8), ((b).s8), c); \ 3017*c217d954SCole Faust }) 3018*c217d954SCole Faust#define DOT_PRODUCT10_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3019*c217d954SCole Faust ({ \ 3020*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3021*c217d954SCole Faust DOT_PRODUCT2_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89), ((b).s89), c); \ 3022*c217d954SCole Faust }) 3023*c217d954SCole Faust#define DOT_PRODUCT11_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3024*c217d954SCole Faust ({ \ 3025*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3026*c217d954SCole Faust DOT_PRODUCT3_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89A), ((b).s89A), c); \ 3027*c217d954SCole Faust }) 3028*c217d954SCole Faust#define DOT_PRODUCT12_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3029*c217d954SCole Faust ({ \ 3030*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3031*c217d954SCole Faust DOT_PRODUCT4_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89AB), ((b).s89AB), c); \ 3032*c217d954SCole Faust }) 3033*c217d954SCole Faust#define DOT_PRODUCT13_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3034*c217d954SCole Faust ({ \ 3035*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3036*c217d954SCole Faust DOT_PRODUCT5_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABC), ((b).s89ABC), c); \ 3037*c217d954SCole Faust }) 3038*c217d954SCole Faust#define DOT_PRODUCT14_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3039*c217d954SCole Faust ({ \ 3040*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3041*c217d954SCole Faust DOT_PRODUCT6_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABCD), ((b).s89ABCD), c); \ 3042*c217d954SCole Faust }) 3043*c217d954SCole Faust#define DOT_PRODUCT15_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3044*c217d954SCole Faust ({ \ 3045*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s01234567), ((b).s01234567), c); \ 3046*c217d954SCole Faust DOT_PRODUCT7_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).s89ABCDE), ((b).s89ABCDE), c); \ 3047*c217d954SCole Faust }) 3048*c217d954SCole Faust#define DOT_PRODUCT16_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, a, b, c) \ 3049*c217d954SCole Faust ({ \ 3050*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).lo), ((b).lo), c); \ 3051*c217d954SCole Faust DOT_PRODUCT8_INTEGER8(A_DATA_TYPE, B_DATA_TYPE, C_DATA_TYPE, ((a).hi), ((b).hi), c); \ 3052*c217d954SCole Faust }) 3053*c217d954SCole Faust 3054*c217d954SCole Faust 3055*c217d954SCole Faust#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) 3056*c217d954SCole Faust#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) 3057*c217d954SCole Faust 3058*c217d954SCole Faust 3059*c217d954SCole Faust#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) 3060*c217d954SCole Faust#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) 3061*c217d954SCole Faust#define V_LOAD_BUFFER(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) \ 3062*c217d954SCole Faust VLOAD(WIDTH) \ 3063*c217d954SCole Faust (0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (Y) * (STRIDE_Y))) 3064*c217d954SCole Faust#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)) 3065*c217d954SCole Faust 3066*c217d954SCole Faust 3067*c217d954SCole Faust#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) 3068*c217d954SCole Faust#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) 3069*c217d954SCole Faust#define V_STORE_BUFFER(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y, VALUES) \ 3070*c217d954SCole Faust VSTORE(WIDTH) \ 3071*c217d954SCole Faust (VALUES, 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (Y) * (STRIDE_Y))) 3072*c217d954SCole Faust#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) 3073*c217d954SCole Faust 3074*c217d954SCole Faust 3075*c217d954SCole Faust#define T_LOAD(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, Y, YI_MULTIPLIER, STRIDE_Y, dst) \ 3076*c217d954SCole Faust ({ \ 3077*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3078*c217d954SCole Faust { \ 3079*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, ((Y) + _i * (int)(YI_MULTIPLIER)), STRIDE_Y); \ 3080*c217d954SCole Faust }) \ 3081*c217d954SCole Faust }) 3082*c217d954SCole Faust 3083*c217d954SCole Faust 3084*c217d954SCole Faust#define T_LOAD_INDIRECT(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, STRIDE_Y, indirect_y, dst) \ 3085*c217d954SCole Faust ({ \ 3086*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3087*c217d954SCole Faust { \ 3088*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, (indirect_y[_i].v), STRIDE_Y); \ 3089*c217d954SCole Faust }) \ 3090*c217d954SCole Faust }) 3091*c217d954SCole Faust 3092*c217d954SCole Faust 3093*c217d954SCole Faust#define T_LOAD_INDIRECT_WIDTH_SELECT(DATA_TYPE, HEIGHT, WIDTH0, WIDTH1, TENSOR_TYPE, TENSOR, X, STRIDE_Y, WIDTH1_CONDITION, dst, indirect_y) \ 3094*c217d954SCole Faust ({ \ 3095*c217d954SCole Faust if(WIDTH1_CONDITION) \ 3096*c217d954SCole Faust { \ 3097*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3098*c217d954SCole Faust { \ 3099*c217d954SCole Faust VLOAD_PARTIAL(WIDTH0, WIDTH1) \ 3100*c217d954SCole Faust (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)); \ 3101*c217d954SCole Faust }) \ 3102*c217d954SCole Faust } \ 3103*c217d954SCole Faust else \ 3104*c217d954SCole Faust { \ 3105*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3106*c217d954SCole Faust { \ 3107*c217d954SCole Faust dst[HEIGHT - 1 - _i].v = V_LOAD(DATA_TYPE, WIDTH0, TENSOR_TYPE, TENSOR, X, (indirect_y[HEIGHT - 1 - _i].v), STRIDE_Y); \ 3108*c217d954SCole Faust }) \ 3109*c217d954SCole Faust } \ 3110*c217d954SCole Faust }) 3111*c217d954SCole Faust 3112*c217d954SCole Faust#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) \ 3113*c217d954SCole Faust ({ \ 3114*c217d954SCole Faust LOOP_UNROLLING(int, _yk, 0, 1, TILE_HEIGHT, \ 3115*c217d954SCole Faust { \ 3116*c217d954SCole Faust LOOP_UNROLLING(int, _xk, 0, 1, TILE_WIDTH, \ 3117*c217d954SCole Faust { \ 3118*c217d954SCole Faust int _src_y = (X) + _xk + ((Y) + _yk) * (TENSOR_WIDTH); \ 3119*c217d954SCole Faust _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \ 3120*c217d954SCole Faust int _src_valid_y = (((X) + _xk) >= 0 && ((X) + _xk) < (int)(TENSOR_WIDTH) && ((Y) + _yk) >= 0 && ((Y) + _yk) < (int)(TENSOR_HEIGHT)); \ 3121*c217d954SCole Faust if(_src_valid_y != 0) \ 3122*c217d954SCole Faust { \ 3123*c217d954SCole Faust dst[_xk + _yk * (TILE_WIDTH)].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 3124*c217d954SCole Faust } \ 3125*c217d954SCole Faust }) \ 3126*c217d954SCole Faust }) \ 3127*c217d954SCole Faust }) 3128*c217d954SCole Faust 3129*c217d954SCole Faust 3130*c217d954SCole Faust#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) \ 3131*c217d954SCole Faust ({ \ 3132*c217d954SCole Faust LOOP_UNROLLING(int, _yk, 0, 1, TILE_HEIGHT, \ 3133*c217d954SCole Faust { \ 3134*c217d954SCole Faust LOOP_UNROLLING(int, _xk, 0, 1, TILE_WIDTH, \ 3135*c217d954SCole Faust { \ 3136*c217d954SCole Faust int _src_y = (X) + _xk * (DILATION_X); \ 3137*c217d954SCole Faust int _src_z = ((Y) + _yk * (DILATION_Y)); \ 3138*c217d954SCole Faust int _src_w = (B); \ 3139*c217d954SCole Faust 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)); \ 3140*c217d954SCole Faust if(!(BOUNDARY_CHECK)) \ 3141*c217d954SCole Faust { \ 3142*c217d954SCole Faust dst[_xk + _yk * (TILE_WIDTH)].v = VLOAD(TILE_CHANNELS) \ 3143*c217d954SCole Faust (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))); \ 3144*c217d954SCole Faust } \ 3145*c217d954SCole Faust else \ 3146*c217d954SCole Faust { \ 3147*c217d954SCole Faust if(_src_valid_y) \ 3148*c217d954SCole Faust { \ 3149*c217d954SCole Faust dst[_xk + _yk * (TILE_WIDTH)].v = VLOAD(TILE_CHANNELS) \ 3150*c217d954SCole Faust (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))); \ 3151*c217d954SCole Faust } \ 3152*c217d954SCole Faust } \ 3153*c217d954SCole Faust }) \ 3154*c217d954SCole Faust }) \ 3155*c217d954SCole Faust }) 3156*c217d954SCole Faust 3157*c217d954SCole Faust 3158*c217d954SCole Faust#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) \ 3159*c217d954SCole Faust ({ \ 3160*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 3161*c217d954SCole Faust { \ 3162*c217d954SCole Faust int _src_y = (X) + xi[_i].v + ((Y) + yi[_i].v) * (TENSOR_WIDTH); \ 3163*c217d954SCole Faust _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \ 3164*c217d954SCole Faust 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)); \ 3165*c217d954SCole Faust if(_src_valid_y != 0) \ 3166*c217d954SCole Faust { \ 3167*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 3168*c217d954SCole Faust } \ 3169*c217d954SCole Faust }) \ 3170*c217d954SCole Faust }) 3171*c217d954SCole Faust 3172*c217d954SCole Faust 3173*c217d954SCole Faust#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) 3174*c217d954SCole Faust#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) 3175*c217d954SCole Faust#define T_LOAD2D_INDIRECT_BUFFER(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) \ 3176*c217d954SCole Faust ({ \ 3177*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 3178*c217d954SCole Faust { \ 3179*c217d954SCole Faust if(yi[0].s[_i] >= 0) \ 3180*c217d954SCole Faust { \ 3181*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, yi[0].s[_i], STRIDE_Y); \ 3182*c217d954SCole Faust } \ 3183*c217d954SCole Faust }) \ 3184*c217d954SCole Faust }) 3185*c217d954SCole Faust 3186*c217d954SCole Faust#define T_LOAD2D_INDIRECT_IMAGE(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, STRIDE_Y, yi, dst) \ 3187*c217d954SCole Faust ({ \ 3188*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 3189*c217d954SCole Faust { \ 3190*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, yi[0].s[_i], STRIDE_Y); \ 3191*c217d954SCole Faust }) \ 3192*c217d954SCole Faust }) 3193*c217d954SCole Faust 3194*c217d954SCole Faust 3195*c217d954SCole Faust#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) \ 3196*c217d954SCole Faust ({ \ 3197*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \ 3198*c217d954SCole Faust { \ 3199*c217d954SCole Faust int _src_y = (X) + xi[_i].v + ((Y) + yi[_i].v) * (TENSOR_WIDTH) + ((Z) + zi[_i].v) * (TENSOR_WIDTH * TENSOR_HEIGHT); \ 3200*c217d954SCole Faust _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT) * (int)(TENSOR_DEPTH); \ 3201*c217d954SCole Faust 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) \ 3202*c217d954SCole Faust && ((Z) + zi[_i].v) >= 0 && ((Z) + zi[_i].v) < (int)(TENSOR_DEPTH)); \ 3203*c217d954SCole Faust if(_src_valid_y != 0) \ 3204*c217d954SCole Faust { \ 3205*c217d954SCole Faust dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \ 3206*c217d954SCole Faust } \ 3207*c217d954SCole Faust }) \ 3208*c217d954SCole Faust }) 3209*c217d954SCole Faust 3210*c217d954SCole Faust 3211*c217d954SCole Faust#define T_STORE_INDIRECT_WIDTH_SELECT(DATA_TYPE, HEIGHT, WIDTH0, WIDTH1, TENSOR_TYPE, TENSOR, X, STRIDE_Y, WIDTH1_CONDITION, src, indirect_y) \ 3212*c217d954SCole Faust ({ \ 3213*c217d954SCole Faust if(WIDTH1_CONDITION) \ 3214*c217d954SCole Faust { \ 3215*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3216*c217d954SCole Faust { \ 3217*c217d954SCole Faust VSTORE_PARTIAL(WIDTH0, WIDTH1) \ 3218*c217d954SCole Faust (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)); \ 3219*c217d954SCole Faust }) \ 3220*c217d954SCole Faust } \ 3221*c217d954SCole Faust else \ 3222*c217d954SCole Faust { \ 3223*c217d954SCole Faust LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \ 3224*c217d954SCole Faust { \ 3225*c217d954SCole Faust VSTORE(WIDTH0) \ 3226*c217d954SCole Faust (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)); \ 3227*c217d954SCole Faust }) \ 3228*c217d954SCole Faust } \ 3229*c217d954SCole Faust }) 3230*c217d954SCole Faust 3231*c217d954SCole Faust 3232*c217d954SCole Faust#define T_OFFSET_CORRECTION(ACC_DATA_TYPE, M0, N0, K0, SRC_OFFSET, WEI_OFFSET, lhs, rhs, dst) \ 3233*c217d954SCole Faust ({ \ 3234*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3235*c217d954SCole Faust { \ 3236*c217d954SCole Faust ACC_DATA_TYPE _tm = 0; \ 3237*c217d954SCole Faust LOOP_UNROLLING(int, _k0, 0, 1, K0, \ 3238*c217d954SCole Faust { \ 3239*c217d954SCole Faust _tm += ((ACC_DATA_TYPE)lhs[_m0].s[_k0] * (ACC_DATA_TYPE)WEI_OFFSET); \ 3240*c217d954SCole Faust }) \ 3241*c217d954SCole Faust LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 3242*c217d954SCole Faust { \ 3243*c217d954SCole Faust dst[_m0].s[_n0] += _tm; \ 3244*c217d954SCole Faust LOOP_UNROLLING(int, _k0, 0, 1, K0, \ 3245*c217d954SCole Faust { \ 3246*c217d954SCole Faust dst[_m0].s[_n0] += ((ACC_DATA_TYPE)rhs[_n0].s[_k0] * (ACC_DATA_TYPE)SRC_OFFSET); \ 3247*c217d954SCole Faust }) \ 3248*c217d954SCole Faust }) \ 3249*c217d954SCole Faust }) \ 3250*c217d954SCole Faust }) 3251*c217d954SCole Faust 3252*c217d954SCole Faust 3253*c217d954SCole Faust#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) 3254*c217d954SCole Faust#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) 3255*c217d954SCole Faust 3256*c217d954SCole Faust 3257*c217d954SCole Faust#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) \ 3258*c217d954SCole Faust ({ \ 3259*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3260*c217d954SCole Faust { \ 3261*c217d954SCole Faust LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 3262*c217d954SCole Faust { \ 3263*c217d954SCole Faust SRC_DATA_TYPE _tmp = 0; \ 3264*c217d954SCole Faust SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 3265*c217d954SCole Faust _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-DST_SHIFT)), ((SRC_DATA_TYPE)DST_SHIFT < (SRC_DATA_TYPE)0)); \ 3266*c217d954SCole Faust SRC_DATA_TYPE overflow = _src == DST_MULTIPLIER && _src == INT_MIN; \ 3267*c217d954SCole Faust long a_64 = (long)(_src); \ 3268*c217d954SCole Faust long b_64 = (long)(DST_MULTIPLIER); \ 3269*c217d954SCole Faust long ab_64 = a_64 * b_64; \ 3270*c217d954SCole Faust long mask1 = 1 << 30; \ 3271*c217d954SCole Faust long mask2 = 1 - (1 << 30); \ 3272*c217d954SCole Faust long is_positive_or_zero = ab_64 >= 0; \ 3273*c217d954SCole Faust long nudge = select(mask2, mask1, is_positive_or_zero); \ 3274*c217d954SCole Faust SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 3275*c217d954SCole Faust _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 3276*c217d954SCole Faust if(DST_SHIFT >= 0) \ 3277*c217d954SCole Faust { \ 3278*c217d954SCole Faust long mask = ((((int)1) << DST_SHIFT) - (long)1); \ 3279*c217d954SCole Faust long threshold = _tmp < (int)0 ? (mask >> 1) + (long)1 : (mask >> 1) + 0; \ 3280*c217d954SCole Faust _tmp = (_tmp & mask) > threshold ? (_tmp >> DST_SHIFT) + (int)1 : (_tmp >> DST_SHIFT); \ 3281*c217d954SCole Faust } \ 3282*c217d954SCole Faust _tmp += DST_OFFSET; \ 3283*c217d954SCole Faust dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 3284*c217d954SCole Faust }) \ 3285*c217d954SCole Faust }) \ 3286*c217d954SCole Faust }) 3287*c217d954SCole Faust 3288*c217d954SCole Faust 3289*c217d954SCole Faust#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) \ 3290*c217d954SCole Faust ({ \ 3291*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3292*c217d954SCole Faust { \ 3293*c217d954SCole Faust LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 3294*c217d954SCole Faust { \ 3295*c217d954SCole Faust SRC_DATA_TYPE _tmp = 0; \ 3296*c217d954SCole Faust SRC_DATA_TYPE _tmp2 = 0; \ 3297*c217d954SCole Faust SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 3298*c217d954SCole Faust SRC_DATA_TYPE _dst_multiplier = dst_multipliers[0].s[_n0]; \ 3299*c217d954SCole Faust SRC_DATA_TYPE _dst_shift = dst_shifts[0].s[_n0]; \ 3300*c217d954SCole Faust _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-_dst_shift)), ((SRC_DATA_TYPE)_dst_shift < (SRC_DATA_TYPE)0)); \ 3301*c217d954SCole Faust SRC_DATA_TYPE overflow = _src == _dst_multiplier && _src == INT_MIN; \ 3302*c217d954SCole Faust long a_64 = (long)(_src); \ 3303*c217d954SCole Faust long b_64 = (long)(_dst_multiplier); \ 3304*c217d954SCole Faust long ab_64 = a_64 * b_64; \ 3305*c217d954SCole Faust long mask1 = 1 << 30; \ 3306*c217d954SCole Faust long mask2 = 1 - (1 << 30); \ 3307*c217d954SCole Faust long is_positive_or_zero = ab_64 >= 0; \ 3308*c217d954SCole Faust long nudge = select(mask2, mask1, is_positive_or_zero); \ 3309*c217d954SCole Faust SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 3310*c217d954SCole Faust _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 3311*c217d954SCole Faust long mask = ((((int)1) << _dst_shift) - (int)1); \ 3312*c217d954SCole Faust long threshold = (mask >> 1) + any(_tmp); \ 3313*c217d954SCole Faust _tmp2 = _tmp >> _dst_shift; \ 3314*c217d954SCole Faust _tmp2 += select(0, 1, (_tmp & mask) > threshold); \ 3315*c217d954SCole Faust _tmp = select(_tmp, _tmp2, _dst_shift >= 0); \ 3316*c217d954SCole Faust _tmp += DST_OFFSET; \ 3317*c217d954SCole Faust dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 3318*c217d954SCole Faust }) \ 3319*c217d954SCole Faust }) \ 3320*c217d954SCole Faust }) 3321*c217d954SCole Faust 3322*c217d954SCole Faust 3323*c217d954SCole Faust#define T_QUANTIZE8_ASYMMETRIC(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst) \ 3324*c217d954SCole Faust ({ \ 3325*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3326*c217d954SCole Faust { \ 3327*c217d954SCole Faust LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 3328*c217d954SCole Faust { \ 3329*c217d954SCole Faust SRC_DATA_TYPE _tmp = 0; \ 3330*c217d954SCole Faust SRC_DATA_TYPE _src = src[_m0].s[_n0]; \ 3331*c217d954SCole Faust _src *= select((SRC_DATA_TYPE)1, ((SRC_DATA_TYPE)1 << (SRC_DATA_TYPE)(-DST_SHIFT)), ((SRC_DATA_TYPE)DST_SHIFT < (SRC_DATA_TYPE)0)); \ 3332*c217d954SCole Faust SRC_DATA_TYPE overflow = _src == DST_MULTIPLIER && _src == INT_MIN; \ 3333*c217d954SCole Faust long a_64 = (long)(_src); \ 3334*c217d954SCole Faust long b_64 = (long)(DST_MULTIPLIER); \ 3335*c217d954SCole Faust long ab_64 = a_64 * b_64; \ 3336*c217d954SCole Faust long mask1 = 1 << 30; \ 3337*c217d954SCole Faust long mask2 = 1 - (1 << 30); \ 3338*c217d954SCole Faust long is_positive_or_zero = ab_64 >= 0; \ 3339*c217d954SCole Faust long nudge = select(mask2, mask1, is_positive_or_zero); \ 3340*c217d954SCole Faust SRC_DATA_TYPE ab_x2_high32 = CONVERT((ab_64 + nudge) / (long)(1ll << 31), SRC_DATA_TYPE); \ 3341*c217d954SCole Faust _tmp = select(ab_x2_high32, (SRC_DATA_TYPE)INT_MAX, overflow); \ 3342*c217d954SCole Faust if(DST_SHIFT >= 0) \ 3343*c217d954SCole Faust { \ 3344*c217d954SCole Faust long mask = ((((int)1) << DST_SHIFT) - (int)1); \ 3345*c217d954SCole Faust long threshold = _tmp < (int)0 ? (mask >> 1) + (long)1 : (mask >> 1) + 0; \ 3346*c217d954SCole Faust _tmp = (_tmp & mask) > threshold ? (_tmp >> DST_SHIFT) + (int)1 : (_tmp >> DST_SHIFT); \ 3347*c217d954SCole Faust } \ 3348*c217d954SCole Faust _tmp += DST_OFFSET; \ 3349*c217d954SCole Faust dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \ 3350*c217d954SCole Faust }) \ 3351*c217d954SCole Faust }) \ 3352*c217d954SCole Faust }) 3353*c217d954SCole Faust 3354*c217d954SCole Faust 3355*c217d954SCole Faust#define T_ROWSET_MASK(DATA_TYPE, M0, N0, VALUE_TO_SET, a, mask) \ 3356*c217d954SCole Faust ({ \ 3357*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3358*c217d954SCole Faust { \ 3359*c217d954SCole Faust LOOP_UNROLLING(int, _n0, 0, 1, N0, \ 3360*c217d954SCole Faust { \ 3361*c217d954SCole Faust 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)); \ 3362*c217d954SCole Faust }) \ 3363*c217d954SCole Faust }) \ 3364*c217d954SCole Faust }) 3365*c217d954SCole Faust 3366*c217d954SCole Faust 3367*c217d954SCole Faust#define T_ACTIVATION(DATA_TYPE, M0, N0, ACTIVATION_TYPE, A_VAL, B_VAL, src, dst) \ 3368*c217d954SCole Faust ({ \ 3369*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3370*c217d954SCole Faust { \ 3371*c217d954SCole Faust dst[_m0].v = ACTIVATION(ACTIVATION_TYPE, DATA_TYPE, N0, src[_m0].v, A_VAL, B_VAL); \ 3372*c217d954SCole Faust }) \ 3373*c217d954SCole Faust }) 3374*c217d954SCole Faust 3375*c217d954SCole Faust 3376*c217d954SCole Faust#define relu_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (max((DATA_TYPE)ZERO_VALUE, x)) 3377*c217d954SCole Faust 3378*c217d954SCole Faust#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))) 3379*c217d954SCole Faust 3380*c217d954SCole Faust#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)) 3381*c217d954SCole Faust 3382*c217d954SCole Faust#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)) 3383*c217d954SCole Faust 3384*c217d954SCole Faust#define identity_op_quantized(DATA_TYPE, VEC_SIZE, ZERO_VALUE, A_VAL, B_VAL, x) (x) 3385*c217d954SCole Faust 3386*c217d954SCole Faust#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) 3387*c217d954SCole Faust#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) 3388*c217d954SCole Faust 3389*c217d954SCole Faust#define V_ADD(A_VAL, B_VAL) ((A_VAL) + (B_VAL)) 3390*c217d954SCole Faust#define V_SUB(A_VAL, B_VAL) ((A_VAL) - (B_VAL)) 3391*c217d954SCole Faust#define V_DIV(A_VAL, B_VAL) ((A_VAL) / (B_VAL)) 3392*c217d954SCole Faust#define V_MUL(A_VAL, B_VAL) ((A_VAL) * (B_VAL)) 3393*c217d954SCole Faust 3394*c217d954SCole Faust 3395*c217d954SCole Faust#define T_ACTIVATION_QUANTIZED(DATA_TYPE, M0, N0, ACTIVATION_TYPE, ZERO_VALUE, A_VAL, B_VAL, src, dst) \ 3396*c217d954SCole Faust ({ \ 3397*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3398*c217d954SCole Faust { \ 3399*c217d954SCole Faust dst[_m0].v = ACTIVATION_QUANTIZED(ACTIVATION_TYPE, DATA_TYPE, N0, ZERO_VALUE, A_VAL, B_VAL, src[_m0].v); \ 3400*c217d954SCole Faust }) \ 3401*c217d954SCole Faust }) 3402*c217d954SCole Faust 3403*c217d954SCole Faust 3404*c217d954SCole Faust#define T_ADD(DATA_TYPE, M0, N0, lhs, rhs, dst) \ 3405*c217d954SCole Faust ({ \ 3406*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3407*c217d954SCole Faust { \ 3408*c217d954SCole Faust dst[_m0].v = lhs[_m0].v + rhs[_m0].v; \ 3409*c217d954SCole Faust }) \ 3410*c217d954SCole Faust }) 3411*c217d954SCole Faust 3412*c217d954SCole Faust 3413*c217d954SCole Faust#define T_ADD_CONSTANT(DATA_TYPE, M0, N0, lhs, rhs_constant, dst) \ 3414*c217d954SCole Faust ({ \ 3415*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3416*c217d954SCole Faust { \ 3417*c217d954SCole Faust dst[_m0].v = lhs[_m0].v + (DATA_TYPE)rhs_constant; \ 3418*c217d954SCole Faust }) \ 3419*c217d954SCole Faust }) 3420*c217d954SCole Faust 3421*c217d954SCole Faust#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) 3422*c217d954SCole Faust#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) 3423*c217d954SCole Faust#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) 3424*c217d954SCole Faust 3425*c217d954SCole Faust#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) 3426*c217d954SCole Faust#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) 3427*c217d954SCole Faust 3428*c217d954SCole Faust#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) 3429*c217d954SCole Faust 3430*c217d954SCole Faust#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) 3431*c217d954SCole Faust#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) 3432*c217d954SCole Faust 3433*c217d954SCole Faust 3434*c217d954SCole Faust#define T_SCALE_CONSTANT(DATA_TYPE, M0, N0, lhs, rhs_constant, dst) \ 3435*c217d954SCole Faust ({ \ 3436*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3437*c217d954SCole Faust { \ 3438*c217d954SCole Faust dst[_m0].v = lhs[_m0].v * (DATA_TYPE)rhs_constant; \ 3439*c217d954SCole Faust }) \ 3440*c217d954SCole Faust }) 3441*c217d954SCole Faust 3442*c217d954SCole Faust 3443*c217d954SCole Faust#define T_ELTWISE_BROADCAST_X(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 3444*c217d954SCole Faust ({ \ 3445*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3446*c217d954SCole Faust { \ 3447*c217d954SCole Faust 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))); \ 3448*c217d954SCole Faust }) \ 3449*c217d954SCole Faust }) 3450*c217d954SCole Faust 3451*c217d954SCole Faust 3452*c217d954SCole Faust#define T_ELTWISE_BROADCAST_LHS_X(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 3453*c217d954SCole Faust ({ \ 3454*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3455*c217d954SCole Faust { \ 3456*c217d954SCole Faust 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))); \ 3457*c217d954SCole Faust }) \ 3458*c217d954SCole Faust }) 3459*c217d954SCole Faust 3460*c217d954SCole Faust#define T_ELTWISE_ADD(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_ADD, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 3461*c217d954SCole Faust#define T_ELTWISE_SUB(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_SUB, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 3462*c217d954SCole Faust#define T_ELTWISE_DIV(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_DIV, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 3463*c217d954SCole Faust#define T_ELTWISE_MUL(DST_DATA_TYPE, M0, N0, lhs, rhs, dst) T_ELTWISE(V_MUL, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) 3464*c217d954SCole Faust 3465*c217d954SCole Faust 3466*c217d954SCole Faust#define T_ELTWISE(T_ELWISE_OP, DST_DATA_TYPE, M0, N0, lhs, rhs, dst) \ 3467*c217d954SCole Faust ({ \ 3468*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3469*c217d954SCole Faust { \ 3470*c217d954SCole Faust 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))); \ 3471*c217d954SCole Faust }) \ 3472*c217d954SCole Faust }) 3473*c217d954SCole Faust 3474*c217d954SCole Faust 3475*c217d954SCole Faust#define T_FLOOR(DST_DATA_TYPE, M0, N0, src, dst) \ 3476*c217d954SCole Faust ({ \ 3477*c217d954SCole Faust LOOP_UNROLLING(int, _m0, 0, 1, M0, \ 3478*c217d954SCole Faust { \ 3479*c217d954SCole Faust dst[_m0].v = floor(CONVERT(src[_m0].v, VEC_DATA_TYPE(DST_DATA_TYPE, N0))); \ 3480*c217d954SCole Faust }) \ 3481*c217d954SCole Faust }) 3482*c217d954SCole Faust 3483*c217d954SCole Faust 3484*c217d954SCole Faust#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) 3485*c217d954SCole Faust#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) 3486*c217d954SCole Faust#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) 3487*c217d954SCole Faust#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) 3488*c217d954SCole Faust#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) 3489*c217d954SCole Faust#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) 3490*c217d954SCole Faust#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) 3491*c217d954SCole Faust#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) 3492*c217d954SCole Faust#define T_MMUL_NT_T_FLOAT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \ 3493*c217d954SCole Faust { \ 3494*c217d954SCole Faust LOOP_UNROLLING(int, _m, 0, 1, M0, \ 3495*c217d954SCole Faust { \ 3496*c217d954SCole Faust LOOP_UNROLLING(int, _n, 0, 1, N0, \ 3497*c217d954SCole Faust { \ 3498*c217d954SCole Faust LOOP_UNROLLING(int, _k, 0, 1, K0, \ 3499*c217d954SCole Faust { \ 3500*c217d954SCole Faust dst[_m].s[_n] = fma((DST_DATA_TYPE)(lhs[_m].s[_k]), (DST_DATA_TYPE)(rhs[_n].s[_k]), dst[_m].s[_n]); \ 3501*c217d954SCole Faust }) \ 3502*c217d954SCole Faust }) \ 3503*c217d954SCole Faust }) \ 3504*c217d954SCole Faust } 3505*c217d954SCole Faust 3506*c217d954SCole Faust#define T_MMUL_NT_T_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \ 3507*c217d954SCole Faust ({ \ 3508*c217d954SCole Faust LOOP_UNROLLING(int, _m, 0, 1, M0, \ 3509*c217d954SCole Faust { \ 3510*c217d954SCole Faust LOOP_UNROLLING(int, _n, 0, 1, N0, \ 3511*c217d954SCole Faust { \ 3512*c217d954SCole Faust DOT_PRODUCT_INTEGER8(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, K0, (lhs[_m].v), (rhs[_n].v), dst[_m].s[_n]); \ 3513*c217d954SCole Faust }) \ 3514*c217d954SCole Faust }) \ 3515*c217d954SCole Faust }) 3516*c217d954SCole Faust 3517*c217d954SCole Faust#endif 3518*c217d954SCole Faust 3519*c217d954SCole Faust#if defined(POOL_AVG) || defined(POOL_L2) 3520*c217d954SCole Faust#define POOL_OP(x, y) ((x) + (y)) 3521*c217d954SCole Faust#else 3522*c217d954SCole Faust#define POOL_OP(x, y) (fmax((x), (y))) 3523*c217d954SCole Faust#endif 3524*c217d954SCole Faust 3525*c217d954SCole Faust#if defined(POOL_L2) 3526*c217d954SCole Faust#define POW2_OP(x, vec_size) ((x) * (x)) 3527*c217d954SCole Faust#else 3528*c217d954SCole Faust#define POW2_OP(x, vec_size) (x) 3529*c217d954SCole Faust#endif 3530*c217d954SCole Faust 3531*c217d954SCole Faust#define DIV_OP(x, y) (x * (1.f / y)) 3532*c217d954SCole Faust#define SQRT_OP(x) sqrt((x)) 3533*c217d954SCole Faust 3534*c217d954SCole Faust#if defined(VEC_SIZE) && defined(VEC_SIZE_LEFTOVER) && defined(SRC_WIDTH) && defined(SRC_HEIGHT) && defined(DST_CHANNELS) && defined(DST_HEIGHT) && defined(DST_BATCH_SIZE) && defined(ACC_DATA_TYPE) 3535*c217d954SCole Faust 3536*c217d954SCole Faust#if defined(POOL_SIZE_X) && defined(POOL_SIZE_Y) 3537*c217d954SCole Faust 3538*c217d954SCole Faust__kernel void pooling_layer_MxN_nhwc( 3539*c217d954SCole Faust TENSOR4D_DECLARATION(input), 3540*c217d954SCole Faust TENSOR4D_DECLARATION(output)) 3541*c217d954SCole Faust{ 3542*c217d954SCole Faust 3543*c217d954SCole Faust 3544*c217d954SCole Faust int idx_out_c = GET_SPATIAL_IDX(0, VEC_SIZE, VEC_SIZE_LEFTOVER); 3545*c217d954SCole Faust int idx_out_w = GET_SPATIAL_IDX(1, 1, 0); 3546*c217d954SCole Faust#if DST_BATCH_SIZE != 1 3547*c217d954SCole Faust 3548*c217d954SCole Faust int idx_out_h = GET_SPATIAL_IDX(2, 1, 0) % DST_HEIGHT; 3549*c217d954SCole Faust int idx_out_n = GET_SPATIAL_IDX(2, 1, 0) / DST_HEIGHT; 3550*c217d954SCole Faust#else 3551*c217d954SCole Faust int idx_out_h = GET_SPATIAL_IDX(2, 1, 0); 3552*c217d954SCole Faust int idx_out_n = 0; 3553*c217d954SCole Faust#endif 3554*c217d954SCole Faust 3555*c217d954SCole Faust __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_w; 3556*c217d954SCole Faust 3557*c217d954SCole Faust __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_n * 3558*c217d954SCole Faust output_stride_w; 3559*c217d954SCole Faust 3560*c217d954SCole Faust VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 3561*c217d954SCole Faust res0 = INITIAL_VALUE; 3562*c217d954SCole Faust 3563*c217d954SCole Faust int idx_in_w = idx_out_w * STRIDE_X - PAD_X; 3564*c217d954SCole Faust int idx_in_h = idx_out_h * STRIDE_Y - PAD_Y; 3565*c217d954SCole Faust 3566*c217d954SCole Faust int pool_x_s = max((int)0, -idx_in_w); 3567*c217d954SCole Faust int pool_x_e = min((int)POOL_SIZE_X, (int)SRC_WIDTH - idx_in_w); 3568*c217d954SCole Faust int pool_y_s = max((int)0, -idx_in_h); 3569*c217d954SCole Faust int pool_y_e = min((int)POOL_SIZE_Y, (int)SRC_HEIGHT - idx_in_h); 3570*c217d954SCole Faust 3571*c217d954SCole Faust#if defined(EXCLUDE_PADDING) 3572*c217d954SCole Faust int filter_size = (pool_y_e - pool_y_s) * (pool_x_e - pool_x_s); 3573*c217d954SCole Faust#else 3574*c217d954SCole Faust int filter_size = POOL_SIZE_X * POOL_SIZE_Y; 3575*c217d954SCole Faust#endif 3576*c217d954SCole Faust 3577*c217d954SCole Faust#if POOL_SIZE_X == SRC_WIDTH && POOL_SIZE_Y == SRC_HEIGHT && PAD_X == 0 && PAD_Y == 0 3578*c217d954SCole Faust 3579*c217d954SCole Faust for(int y = 0; y < POOL_SIZE_Y; ++y) 3580*c217d954SCole Faust { 3581*c217d954SCole Faust#pragma unroll 8 3582*c217d954SCole Faust for(int x = 0; x < POOL_SIZE_X; ++x) 3583*c217d954SCole Faust { 3584*c217d954SCole Faust#else 3585*c217d954SCole Faust for(int y = pool_y_s; y < pool_y_e; ++y) 3586*c217d954SCole Faust { 3587*c217d954SCole Faust#pragma unroll 8 3588*c217d954SCole Faust for(int x = pool_x_s; x < pool_x_e; ++x) 3589*c217d954SCole Faust { 3590*c217d954SCole Faust#endif 3591*c217d954SCole Faust VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 3592*c217d954SCole Faust data0; 3593*c217d954SCole Faust#if defined(FP_MIXED_PRECISION) 3594*c217d954SCole Faust 3595*c217d954SCole Faust data0 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + (x + idx_in_w) * input_stride_y + (y + idx_in_h) * input_stride_z)), VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 3596*c217d954SCole Faust#else 3597*c217d954SCole Faust data0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + (x + idx_in_w) * input_stride_y + (y + idx_in_h) * input_stride_z)); 3598*c217d954SCole Faust#endif 3599*c217d954SCole Faust 3600*c217d954SCole Faust#if defined(POOL_L2) 3601*c217d954SCole Faust 3602*c217d954SCole Faust data0 *= data0; 3603*c217d954SCole Faust#endif 3604*c217d954SCole Faust res0 = POOL_OP(res0, data0); 3605*c217d954SCole Faust } 3606*c217d954SCole Faust } 3607*c217d954SCole Faust 3608*c217d954SCole Faust#if defined(POOL_AVG) || defined(POOL_L2) 3609*c217d954SCole Faust res0 /= (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))filter_size; 3610*c217d954SCole Faust#endif 3611*c217d954SCole Faust 3612*c217d954SCole Faust#if defined(POOL_L2) 3613*c217d954SCole Faust 3614*c217d954SCole Faust res0 = SQRT_OP(res0); 3615*c217d954SCole Faust#endif 3616*c217d954SCole Faust 3617*c217d954SCole Faust 3618*c217d954SCole Faust#if defined(FP_MIXED_PRECISION) 3619*c217d954SCole Faust VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) 3620*c217d954SCole Faust res_converted0 = CONVERT(res0, VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)); 3621*c217d954SCole Faust STORE_VECTOR_SELECT(res_converted, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 3622*c217d954SCole Faust#else 3623*c217d954SCole Faust STORE_VECTOR_SELECT(res, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 3624*c217d954SCole Faust#endif 3625*c217d954SCole Faust} 3626*c217d954SCole Faust#endif 3627*c217d954SCole Faust 3628*c217d954SCole Faust#define SELECT_TYPE SELECT_VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 3629*c217d954SCole Faust 3630*c217d954SCole Faust 3631*c217d954SCole Faust__kernel void pooling_layer_2x2_nhwc( 3632*c217d954SCole Faust TENSOR4D_DECLARATION(input), 3633*c217d954SCole Faust TENSOR4D_DECLARATION(output) 3634*c217d954SCole Faust#if defined(EXTRACT_MAX_INDEX) && defined(POOL_MAX) 3635*c217d954SCole Faust , 3636*c217d954SCole Faust TENSOR4D_DECLARATION(indices) 3637*c217d954SCole Faust#endif 3638*c217d954SCole Faust) 3639*c217d954SCole Faust{ 3640*c217d954SCole Faust 3641*c217d954SCole Faust 3642*c217d954SCole Faust int idx_out_c = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0); 3643*c217d954SCole Faust int idx_out_w = get_global_id(1); 3644*c217d954SCole Faust#if DST_BATCH_SIZE != 1 3645*c217d954SCole Faust 3646*c217d954SCole Faust int idx_out_h = get_global_id(2) % DST_HEIGHT; 3647*c217d954SCole Faust int idx_out_n = get_global_id(2) / DST_HEIGHT; 3648*c217d954SCole Faust#else 3649*c217d954SCole Faust int idx_out_h = get_global_id(2); 3650*c217d954SCole Faust int idx_out_n = 0; 3651*c217d954SCole Faust#endif 3652*c217d954SCole Faust 3653*c217d954SCole Faust int idx_in_w = idx_out_w * STRIDE_X - PAD_X; 3654*c217d954SCole Faust int idx_in_h = idx_out_h * STRIDE_Y - PAD_Y; 3655*c217d954SCole Faust 3656*c217d954SCole Faust __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_w; 3657*c217d954SCole Faust 3658*c217d954SCole Faust __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_n * 3659*c217d954SCole Faust output_stride_w; 3660*c217d954SCole Faust 3661*c217d954SCole Faust int pool_x_s = max((int)0, -idx_in_w); 3662*c217d954SCole Faust int pool_x_e = min((int)2, (int)SRC_WIDTH - idx_in_w); 3663*c217d954SCole Faust int pool_y_s = max((int)0, -idx_in_h); 3664*c217d954SCole Faust int pool_y_e = min((int)2, (int)SRC_HEIGHT - idx_in_h); 3665*c217d954SCole Faust 3666*c217d954SCole Faust int filter_size = (pool_x_e - pool_x_s) * (pool_y_e - pool_y_s); 3667*c217d954SCole Faust 3668*c217d954SCole Faust int x0 = pool_x_s + idx_in_w; 3669*c217d954SCole Faust int y0 = pool_y_s + idx_in_h; 3670*c217d954SCole Faust int x1 = pool_x_e - 1 + idx_in_w; 3671*c217d954SCole Faust int y1 = pool_y_e - 1 + idx_in_h; 3672*c217d954SCole Faust 3673*c217d954SCole Faust REPEAT_VAR_INIT_TO_CONST(4, VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE), data, 0); 3674*c217d954SCole Faust 3675*c217d954SCole Faust#if defined(FP_MIXED_PRECISION) 3676*c217d954SCole Faust 3677*c217d954SCole Faust data0 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x0 * input_stride_y + y0 * input_stride_z)), VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 3678*c217d954SCole Faust data1 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x1 * input_stride_y + y0 * input_stride_z)), VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 3679*c217d954SCole Faust data2 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x0 * input_stride_y + y1 * input_stride_z)), VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 3680*c217d954SCole Faust data3 = CONVERT(VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x1 * input_stride_y + y1 * input_stride_z)), VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE)); 3681*c217d954SCole Faust#else 3682*c217d954SCole Faust data0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x0 * input_stride_y + y0 * input_stride_z)); 3683*c217d954SCole Faust data1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x1 * input_stride_y + y0 * input_stride_z)); 3684*c217d954SCole Faust data2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x0 * input_stride_y + y1 * input_stride_z)); 3685*c217d954SCole Faust data3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(in_base_ptr + x1 * input_stride_y + y1 * input_stride_z)); 3686*c217d954SCole Faust#endif 3687*c217d954SCole Faust 3688*c217d954SCole Faust#if !defined(POOL_MAX) 3689*c217d954SCole Faust if(filter_size != 4) 3690*c217d954SCole Faust { 3691*c217d954SCole Faust SELECT_TYPE cond_w_s = (SELECT_TYPE)idx_in_w < (SELECT_TYPE)0; 3692*c217d954SCole Faust SELECT_TYPE cond_w_e = (SELECT_TYPE)idx_in_w >= (SELECT_TYPE)(SRC_WIDTH - 1); 3693*c217d954SCole Faust SELECT_TYPE cond_h_s = (SELECT_TYPE)idx_in_h < (SELECT_TYPE)0; 3694*c217d954SCole Faust SELECT_TYPE cond_h_e = (SELECT_TYPE)idx_in_h >= (SELECT_TYPE)(SRC_HEIGHT - 1); 3695*c217d954SCole Faust 3696*c217d954SCole Faust 3697*c217d954SCole Faust data0 = select(data0, (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))INITIAL_VALUE, (SELECT_TYPE)(cond_w_s | cond_h_s)); 3698*c217d954SCole Faust data1 = select(data1, (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))INITIAL_VALUE, (SELECT_TYPE)(cond_w_e | cond_h_s)); 3699*c217d954SCole Faust data2 = select(data2, (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))INITIAL_VALUE, (SELECT_TYPE)(cond_w_s | cond_h_e)); 3700*c217d954SCole Faust data3 = select(data3, (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))INITIAL_VALUE, (SELECT_TYPE)(cond_w_e | cond_h_e)); 3701*c217d954SCole Faust } 3702*c217d954SCole Faust#endif 3703*c217d954SCole Faust 3704*c217d954SCole Faust#if defined(POOL_L2) 3705*c217d954SCole Faust 3706*c217d954SCole Faust data0 *= data0; 3707*c217d954SCole Faust data1 *= data1; 3708*c217d954SCole Faust data2 *= data2; 3709*c217d954SCole Faust data3 *= data3; 3710*c217d954SCole Faust#endif 3711*c217d954SCole Faust 3712*c217d954SCole Faust VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE) 3713*c217d954SCole Faust res0 = data0; 3714*c217d954SCole Faust res0 = POOL_OP(res0, data1); 3715*c217d954SCole Faust res0 = POOL_OP(res0, data2); 3716*c217d954SCole Faust res0 = POOL_OP(res0, data3); 3717*c217d954SCole Faust 3718*c217d954SCole Faust#if defined(POOL_AVG) || defined(POOL_L2) 3719*c217d954SCole Faust#if defined(EXCLUDE_PADDING) 3720*c217d954SCole Faust res0 /= (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))filter_size; 3721*c217d954SCole Faust#else 3722*c217d954SCole Faust res0 /= (VEC_DATA_TYPE(ACC_DATA_TYPE, VEC_SIZE))4; 3723*c217d954SCole Faust#endif 3724*c217d954SCole Faust#endif 3725*c217d954SCole Faust 3726*c217d954SCole Faust#if defined(POOL_L2) 3727*c217d954SCole Faust 3728*c217d954SCole Faust res0 = SQRT_OP(res0); 3729*c217d954SCole Faust#endif 3730*c217d954SCole Faust 3731*c217d954SCole Faust 3732*c217d954SCole Faust#if defined(FP_MIXED_PRECISION) 3733*c217d954SCole Faust VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) 3734*c217d954SCole Faust res_converted0 = CONVERT(res0, VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)); 3735*c217d954SCole Faust STORE_VECTOR_SELECT(res_converted, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 3736*c217d954SCole Faust#else 3737*c217d954SCole Faust STORE_VECTOR_SELECT(res, DATA_TYPE, out_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, (VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0); 3738*c217d954SCole Faust#endif 3739*c217d954SCole Faust 3740*c217d954SCole Faust#if defined(EXTRACT_MAX_INDEX) && defined(POOL_MAX) 3741*c217d954SCole Faust 3742*c217d954SCole Faust 3743*c217d954SCole Faust 3744*c217d954SCole Faust 3745*c217d954SCole Faust 3746*c217d954SCole Faust VEC_DATA_TYPE(uint, VEC_SIZE) 3747*c217d954SCole Faust base_index = (uint)idx_out_c; 3748*c217d954SCole Faust 3749*c217d954SCole Faust base_index += VEC_OFFS(uint, VEC_SIZE); 3750*c217d954SCole Faust 3751*c217d954SCole Faust VEC_DATA_TYPE(uint, VEC_SIZE) 3752*c217d954SCole Faust index0 = base_index + (uint)x0 * DST_CHANNELS + (uint)y0 * (DST_CHANNELS * SRC_WIDTH); 3753*c217d954SCole Faust VEC_DATA_TYPE(uint, VEC_SIZE) 3754*c217d954SCole Faust index1 = base_index + (uint)x1 * DST_CHANNELS + (uint)y0 * (DST_CHANNELS * SRC_WIDTH); 3755*c217d954SCole Faust VEC_DATA_TYPE(uint, VEC_SIZE) 3756*c217d954SCole Faust index2 = base_index + (uint)x0 * DST_CHANNELS + (uint)y1 * (DST_CHANNELS * SRC_WIDTH); 3757*c217d954SCole Faust VEC_DATA_TYPE(uint, VEC_SIZE) 3758*c217d954SCole Faust index3 = base_index + (uint)x1 * DST_CHANNELS + (uint)y1 * (DST_CHANNELS * SRC_WIDTH); 3759*c217d954SCole Faust 3760*c217d954SCole Faust index0 = select(index1, index0, CONVERT(isgreaterequal(data0, data1), VEC_DATA_TYPE(int, VEC_SIZE))); 3761*c217d954SCole Faust index1 = select(index3, index2, CONVERT(isgreaterequal(data2, data3), VEC_DATA_TYPE(int, VEC_SIZE))); 3762*c217d954SCole Faust index0 = select(index1, index0, CONVERT(isgreaterequal(max(data0, data1), max(data2, data3)), VEC_DATA_TYPE(int, VEC_SIZE))); 3763*c217d954SCole Faust 3764*c217d954SCole Faust __global unsigned char *idx_base_ptr = indices_ptr + indices_offset_first_element_in_bytes + idx_out_c * sizeof(uint) + idx_out_w * indices_stride_y + idx_out_h * indices_stride_z + idx_out_n * 3765*c217d954SCole Faust indices_stride_w; 3766*c217d954SCole Faust 3767*c217d954SCole Faust 3768*c217d954SCole Faust STORE_VECTOR_SELECT(index, uint, idx_base_ptr, VEC_SIZE, VEC_SIZE_LEFTOVER, ((VEC_SIZE_LEFTOVER != 0) && get_global_id(0) == 0)); 3769*c217d954SCole Faust#endif 3770*c217d954SCole Faust} 3771*c217d954SCole Faust#endif )"