1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
//
// This file defines SPIRV vstoren, vstore_half, vstore_half_r, vstore_halfn,
// vstore_halfn_r, vstorea_halfn and vstorea_halfn_r built-ins.
//
//*****************************************************************************/
// helper functions
//*****************************************************************************/
static OVERLOADABLE half __intel_spirv_float2half(float f, RoundingMode_t r)
{
switch (r)
{
case rte:
return SPIRV_BUILTIN(FConvert, _RTE_f16_f32, _Rhalf_rte)(f);
case rtz:
return SPIRV_BUILTIN(FConvert, _RTZ_f16_f32, _Rhalf_rtz)(f);
case rtp:
return SPIRV_BUILTIN(FConvert, _RTP_f16_f32, _Rhalf_rtp)(f);
case rtn:
return SPIRV_BUILTIN(FConvert, _RTN_f16_f32, _Rhalf_rtn)(f);
}
}
GENERATE_VECTOR_FUNCTIONS_2ARGS_VS_NO_MANG(__intel_spirv_float2half, half, float, RoundingMode_t)
#if defined(cl_khr_fp64)
static OVERLOADABLE half __intel_spirv_double2half(double d, RoundingMode_t r)
{
switch (r)
{
case rte:
return SPIRV_BUILTIN(FConvert, _RTE_f16_f64, _Rhalf_rte)(d);
case rtz:
return SPIRV_BUILTIN(FConvert, _RTZ_f16_f64, _Rhalf_rtz)(d);
case rtp:
return SPIRV_BUILTIN(FConvert, _RTP_f16_f64, _Rhalf_rtp)(d);
case rtn:
return SPIRV_BUILTIN(FConvert, _RTN_f16_f64, _Rhalf_rtn)(d);
}
}
GENERATE_VECTOR_FUNCTIONS_2ARGS_VS_NO_MANG(__intel_spirv_double2half, half, double, RoundingMode_t)
#endif //defined(cl_khr_fp64)
//*****************************************************************************/
// vstoren
// "Writes n components from the data vector value to the address computed as (p + (offset * n)),
// where n is equal to the component count of the vector data."
//*****************************************************************************/
#define VSTOREN_DEF(addressSpace, scalarType, numElements, offsetType, mangle) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN(vstore, numElements##_##mangle, n)( \
scalarType##numElements data, offsetType offset, addressSpace scalarType *p) { \
addressSpace scalarType *pOffset = p + offset * numElements; \
scalarType##numElements ret = data; \
__builtin_IB_memcpy_private_to_##addressSpace((addressSpace uchar *)pOffset, (private uchar *)&ret, \
sizeof(scalarType) * numElements, sizeof(scalarType)); \
}
#define VSTOREN_AS(addressSpace, scalarType, typemang, mang) \
VSTOREN_DEF(addressSpace, scalarType, 2, long, v2##typemang##_i64_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 2, int, v2##typemang##_i32_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 3, long, v3##typemang##_i64_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 3, int, v3##typemang##_i32_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 4, long, v4##typemang##_i64_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 4, int, v4##typemang##_i32_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 8, long, v8##typemang##_i64_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 8, int, v8##typemang##_i32_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 16, long, v16##typemang##_i64_##mang) \
VSTOREN_DEF(addressSpace, scalarType, 16, int, v16##typemang##_i32_##mang)
#if (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
#define VSTOREN_TYPE(TYPE, TYPEMANG) \
VSTOREN_AS(global, TYPE, TYPEMANG, p1##TYPEMANG) \
VSTOREN_AS(local, TYPE, TYPEMANG, p3##TYPEMANG) \
VSTOREN_AS(private, TYPE, TYPEMANG, p0##TYPEMANG) \
VSTOREN_AS(generic, TYPE, TYPEMANG, p4##TYPEMANG)
#else
#define VSTOREN_TYPE(TYPE, TYPEMANG) \
VSTOREN_AS(global, TYPE, TYPEMANG, p1##TYPEMANG) \
VSTOREN_AS(local, TYPE, TYPEMANG, p3##TYPEMANG) \
VSTOREN_AS(private, TYPE, TYPEMANG, p0##TYPEMANG)
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
VSTOREN_TYPE(char, i8)
VSTOREN_TYPE(short, i16)
VSTOREN_TYPE(int, i32)
VSTOREN_TYPE(long, i64)
VSTOREN_TYPE(half, f16)
VSTOREN_TYPE(float, f32)
#if defined(cl_khr_fp64)
VSTOREN_TYPE(double, f64)
#endif
//*****************************************************************************/
// vstore_half
// "Converts the data float or double value to a half value using the default rounding mode
// and writes the half value to the address computed as (p + offset)."
// vstore_half_r
// "Converts the data float or double value to a half value using the specified rounding mode
// mode and writes the half value to the address computed as (p + offset)."
//*****************************************************************************/
#define VSTORE_HALF_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN(vstore_half, _##MANGSRC##_##MANGSIZE##_p##ASNUM##f16, )( \
srcType data, SIZETYPE offset, addressSpace half * p) { \
addressSpace half *pHalf = (addressSpace half *)(p + offset); \
*pHalf = __intel_spirv_##srcType##2half(data, rte); \
}
#define VSTORE_HALF_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN(vstore_half_r, _##MANGSRC##_##MANGSIZE##_p##ASNUM##f16_i32, )( \
srcType data, SIZETYPE offset, addressSpace half * p, RoundingMode_t r) { \
addressSpace half *pHalf = (addressSpace half *)(p + offset); \
*pHalf = __intel_spirv_##srcType##2half(data, r); \
}
#define VSTORE_HALF_BOTH(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType) \
VSTORE_HALF_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType) \
VSTORE_HALF_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType)
#if defined(cl_khr_fp64)
#define VSTORE_HALF_ALL_TYPES(addressSpace, ASNUM) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i64, long, f32, float) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i64, long, f64, double) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i32, int, f32, float) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i32, int, f64, double)
#else
#define VSTORE_HALF_ALL_TYPES(addressSpace, ASNUM) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i64, long, f32, float) \
VSTORE_HALF_BOTH(addressSpace, ASNUM, i32, int, f32, float)
#endif
VSTORE_HALF_ALL_TYPES(private, 0)
VSTORE_HALF_ALL_TYPES(global, 1)
VSTORE_HALF_ALL_TYPES(local, 3)
#if (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
VSTORE_HALF_ALL_TYPES(generic, 4)
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
//*****************************************************************************/
// vstore_halfn
// "Converts the data vector of float or vector of double values to a vector of half values
// using the default rounding mode and writes the half values to memory."
// vstore_halfn_r
// "Converts the data vector of float or vector of double values to a vector of half values
// using the specified rounding mode mode and writes the half values to memory."
//*****************************************************************************/
#define VSTORE_HALFN_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, numElements) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN( \
vstore_half, numElements##_v##numElements##MANGSRC##_##MANGSIZE##_p##ASNUM##f16, \
n)(srcType##numElements data, SIZETYPE offset, addressSpace half * p) { \
SPIRV_OCL_BUILTIN(vstore, numElements##_v##numElements##f16##_##MANGSIZE##_p##ASNUM##f16, n) \
(__intel_spirv_##srcType##2half(data, rte), offset, p); \
}
#define VSTORE_HALFN_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, numElements) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN( \
vstore_half, numElements##_r_v##numElements##MANGSRC##_##MANGSIZE##_p##ASNUM##f16_i32, \
n_r)(srcType##numElements data, SIZETYPE offset, addressSpace half * p, RoundingMode_t r) { \
SPIRV_OCL_BUILTIN(vstore, numElements##_v##numElements##f16##_##MANGSIZE##_p##ASNUM##f16, n) \
(__intel_spirv_##srcType##2half(data, r), offset, p); \
}
#define VSTORE_HALFN_BOTH(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, numElements) \
VSTORE_HALFN_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, numElements) \
VSTORE_HALFN_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, numElements)
#if defined(cl_khr_fp64)
#define VSTORE_HALFN_ALL_TYPES(addressSpace, ASNUM) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 16) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 16) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 16) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 16)
#else
#define VSTORE_HALFN_ALL_TYPES(addressSpace, ASNUM) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 16) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 2) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 3) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 8) \
VSTORE_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 16)
#endif //defined(cl_khr_fp64)
VSTORE_HALFN_ALL_TYPES(private, 0)
VSTORE_HALFN_ALL_TYPES(global, 1)
VSTORE_HALFN_ALL_TYPES(local, 3)
#if (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
VSTORE_HALFN_ALL_TYPES(generic, 4)
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
//*****************************************************************************/
// vstorea_halfn
// "Converts the data vector of float or vector of double values to a vector of half values using the default rounding mode,
// and then writes the converted vector of half values to aligned memory."
// vstorea_halfn_r
// "Converts the data vector of float or vector of double values to a vector of half values using the specified rounding mode mode,
// and then write the converted vector of half values to aligned memory."
//*****************************************************************************/
#define VSTOREA_HALFN_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, step, numElements) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN( \
vstorea_half, numElements##_v##numElements##MANGSRC##_##MANGSIZE##_p##ASNUM##f16, \
n)(srcType##numElements data, SIZETYPE offset, addressSpace half * p) { \
addressSpace half##numElements *pHalf = (addressSpace half##numElements *)(p + offset * step); \
*pHalf = __intel_spirv_##srcType##2half(data, rte); \
}
#define VSTOREA_HALFN_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, step, numElements) \
INLINE void SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN( \
vstorea_half, numElements##_r_v##numElements##MANGSRC##_##MANGSIZE##_p##ASNUM##f16_i32, \
n_r)(srcType##numElements data, SIZETYPE offset, addressSpace half * p, RoundingMode_t r) { \
addressSpace half##numElements *pHalf = (addressSpace half##numElements *)(p + offset * step); \
*pHalf = __intel_spirv_##srcType##2half(data, r); \
}
#define VSTOREA_HALFN_BOTH(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, step, numElements) \
VSTOREA_HALFN_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, step, numElements) \
VSTOREA_HALFN_R_DEF(addressSpace, ASNUM, MANGSIZE, SIZETYPE, MANGSRC, srcType, step, numElements)
#if defined(cl_khr_fp64)
#define VSTOREA_HALFN_ALL_TYPES(addressSpace, ASNUM) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 16, 16) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f64, double, 16, 16) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 16, 16) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f64, double, 16, 16)
#else
#define VSTOREA_HALFN_ALL_TYPES(addressSpace, ASNUM) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i64, long, f32, float, 16, 16) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 2, 2) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4, 3) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 4, 4) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 8, 8) \
VSTOREA_HALFN_BOTH(addressSpace, ASNUM, i32, int, f32, float, 16, 16)
#endif //defined(cl_khr_fp64)
VSTOREA_HALFN_ALL_TYPES(private, 0)
VSTOREA_HALFN_ALL_TYPES(global, 1)
VSTOREA_HALFN_ALL_TYPES(local, 3)
#if (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
VSTOREA_HALFN_ALL_TYPES(generic, 4)
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
|