23 #ifndef HIP_INCLUDE_HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H 24 #define HIP_INCLUDE_HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H 29 #include <hip/hip_runtime_api.h> 33 #include <hip/hip_vector_types.h> 41 __device__
static inline unsigned int __popc(
unsigned int input) {
42 return __builtin_popcount(input);
44 __device__
static inline unsigned int __popcll(
unsigned long long int input) {
45 return __builtin_popcountll(input);
48 __device__
static inline int __clz(
int input) {
49 return __ockl_clz_u32((uint)input);
52 __device__
static inline int __clzll(
long long int input) {
53 return __ockl_clz_u64((ullong)input);
56 __device__
static inline unsigned int __ffs(
unsigned int input) {
57 return ( input == 0 ? -1 : __builtin_ctz(input) ) + 1;
60 __device__
static inline unsigned int __ffsll(
unsigned long long int input) {
61 return ( input == 0 ? -1 : __builtin_ctzll(input) ) + 1;
64 __device__
static inline unsigned int __ffs(
int input) {
65 return ( input == 0 ? -1 : __builtin_ctz(input) ) + 1;
68 __device__
static inline unsigned int __ffsll(
long long int input) {
69 return ( input == 0 ? -1 : __builtin_ctzll(input) ) + 1;
72 __device__
static inline unsigned int __brev(
unsigned int input) {
73 return __llvm_bitrev_b32(input);
76 __device__
static inline unsigned long long int __brevll(
unsigned long long int input) {
77 return __llvm_bitrev_b64(input);
80 __device__
static inline unsigned int __lastbit_u32_u64(uint64_t input) {
81 return input == 0 ? -1 : __builtin_ctzl(input);
84 __device__
static inline unsigned int __bitextract_u32(
unsigned int src0,
unsigned int src1,
unsigned int src2) {
85 uint32_t offset = src1 & 31;
86 uint32_t width = src2 & 31;
87 return width == 0 ? 0 : (src0 << (32 - offset - width)) >> (32 - width);
90 __device__
static inline uint64_t __bitextract_u64(uint64_t src0,
unsigned int src1,
unsigned int src2) {
91 uint64_t offset = src1 & 63;
92 uint64_t width = src2 & 63;
93 return width == 0 ? 0 : (src0 << (64 - offset - width)) >> (64 - width);
96 __device__
static inline unsigned int __bitinsert_u32(
unsigned int src0,
unsigned int src1,
unsigned int src2,
unsigned int src3) {
97 uint32_t offset = src2 & 31;
98 uint32_t width = src3 & 31;
99 uint32_t mask = (1 << width) - 1;
100 return ((src0 & ~(mask << offset)) | ((src1 & mask) << offset));
103 __device__
static inline uint64_t __bitinsert_u64(uint64_t src0, uint64_t src1,
unsigned int src2,
unsigned int src3) {
104 uint64_t offset = src2 & 63;
105 uint64_t width = src3 & 63;
106 uint64_t mask = (1ULL << width) - 1;
107 return ((src0 & ~(mask << offset)) | ((src1 & mask) << offset));
110 __device__
static unsigned int __byte_perm(
unsigned int x,
unsigned int y,
unsigned int s);
111 __device__
static unsigned int __hadd(
int x,
int y);
112 __device__
static int __mul24(
int x,
int y);
113 __device__
static long long int __mul64hi(
long long int x,
long long int y);
114 __device__
static int __mulhi(
int x,
int y);
115 __device__
static int __rhadd(
int x,
int y);
116 __device__
static unsigned int __sad(
int x,
int y,
int z);
117 __device__
static unsigned int __uhadd(
unsigned int x,
unsigned int y);
118 __device__
static int __umul24(
unsigned int x,
unsigned int y);
119 __device__
static unsigned long long int __umul64hi(
unsigned long long int x,
unsigned long long int y);
120 __device__
static unsigned int __umulhi(
unsigned int x,
unsigned int y);
121 __device__
static unsigned int __urhadd(
unsigned int x,
unsigned int y);
122 __device__
static unsigned int __usad(
unsigned int x,
unsigned int y,
unsigned int z);
129 } __attribute__((aligned(4)));
136 } __attribute__((aligned(8)));
139 static inline unsigned int __byte_perm(
unsigned int x,
unsigned int y,
unsigned int s) {
146 cHoldOut.c[0] = cHoldVal.c[cHoldKey.c[0]];
147 cHoldOut.c[1] = cHoldVal.c[cHoldKey.c[1]];
148 cHoldOut.c[2] = cHoldVal.c[cHoldKey.c[2]];
149 cHoldOut.c[3] = cHoldVal.c[cHoldKey.c[3]];
153 __device__
static inline unsigned int __hadd(
int x,
int y) {
155 int sign = z & 0x8000000;
156 int value = z & 0x7FFFFFFF;
157 return ((value) >> 1 || sign);
160 __device__
static inline int __mul24(
int x,
int y) {
161 return __ockl_mul24_i32(x, y);
164 __device__
static inline long long __mul64hi(
long long int x,
long long int y) {
165 ulong x0 = (ulong)x & 0xffffffffUL;
167 ulong y0 = (ulong)y & 0xffffffffUL;
170 long t = x1*y0 + (z0 >> 32);
171 long z1 = t & 0xffffffffL;
174 return x1*y1 + z2 + (z1 >> 32);
177 __device__
static inline int __mulhi(
int x,
int y) {
178 return __ockl_mul_hi_i32(x, y);
181 __device__
static inline int __rhadd(
int x,
int y) {
183 int sign = z & 0x8000000;
184 int value = z & 0x7FFFFFFF;
185 return ((value) >> 1 || sign);
187 __device__
static inline unsigned int __sad(
int x,
int y,
int z) {
188 return x > y ? x - y + z : y - x + z;
190 __device__
static inline unsigned int __uhadd(
unsigned int x,
unsigned int y) {
193 __device__
static inline int __umul24(
unsigned int x,
unsigned int y) {
194 return __ockl_mul24_u32(x, y);
198 static inline unsigned long long __umul64hi(
unsigned long long int x,
unsigned long long int y) {
199 ulong x0 = x & 0xffffffffUL;
201 ulong y0 = y & 0xffffffffUL;
204 ulong t = x1*y0 + (z0 >> 32);
205 ulong z1 = t & 0xffffffffUL;
208 return x1*y1 + z2 + (z1 >> 32);
211 __device__
static inline unsigned int __umulhi(
unsigned int x,
unsigned int y) {
212 return __ockl_mul_hi_u32(x, y);
214 __device__
static inline unsigned int __urhadd(
unsigned int x,
unsigned int y) {
215 return (x + y + 1) >> 1;
217 __device__
static inline unsigned int __usad(
unsigned int x,
unsigned int y,
unsigned int z) {
218 return __ockl_sad_u32(x, y, z);
221 __device__
static inline unsigned int __lane_id() {
return __mbcnt_hi(-1, __mbcnt_lo(-1, 0)); }
227 __device__
static inline unsigned __hip_ds_bpermute(
int index,
unsigned src) {
228 union {
int i;
unsigned u;
float f; } tmp; tmp.u = src;
229 tmp.i = __llvm_amdgcn_ds_bpermute(index, tmp.i);
233 __device__
static inline float __hip_ds_bpermutef(
int index,
float src) {
234 union {
int i;
unsigned u;
float f; } tmp; tmp.f = src;
235 tmp.i = __llvm_amdgcn_ds_bpermute(index, tmp.i);
239 __device__
static inline unsigned __hip_ds_permute(
int index,
unsigned src) {
240 union {
int i;
unsigned u;
float f; } tmp; tmp.u = src;
241 tmp.i = __llvm_amdgcn_ds_permute(index, tmp.i);
245 __device__
static inline float __hip_ds_permutef(
int index,
float src) {
246 union {
int i;
unsigned u;
float f; } tmp; tmp.u = src;
247 tmp.i = __llvm_amdgcn_ds_permute(index, tmp.i);
251 #define __hip_ds_swizzle(src, pattern) __hip_ds_swizzle_N<(pattern)>((src)) 252 #define __hip_ds_swizzlef(src, pattern) __hip_ds_swizzlef_N<(pattern)>((src)) 254 template <
int pattern>
255 __device__
static inline unsigned __hip_ds_swizzle_N(
unsigned int src) {
256 union {
int i;
unsigned u;
float f; } tmp; tmp.u = src;
258 tmp.i = __llvm_amdgcn_ds_swizzle(tmp.i, pattern);
260 tmp.i = __builtin_amdgcn_ds_swizzle(tmp.i, pattern);
265 template <
int pattern>
266 __device__
static inline float __hip_ds_swizzlef_N(
float src) {
267 union {
int i;
unsigned u;
float f; } tmp; tmp.f = src;
269 tmp.i = __llvm_amdgcn_ds_swizzle(tmp.i, pattern);
271 tmp.i = __builtin_amdgcn_ds_swizzle(tmp.i, pattern);
276 #define __hip_move_dpp(src, dpp_ctrl, row_mask, bank_mask, bound_ctrl) \ 277 __hip_move_dpp_N<(dpp_ctrl), (row_mask), (bank_mask), (bound_ctrl)>((src)) 279 template <
int dpp_ctrl,
int row_mask,
int bank_mask,
bool bound_ctrl>
280 __device__
static inline int __hip_move_dpp_N(
int src) {
281 return __llvm_amdgcn_move_dpp(src, dpp_ctrl, row_mask, bank_mask,
285 static constexpr
int warpSize = 64;
289 int __shfl(
int var,
int src_lane,
int width = warpSize) {
290 int self = __lane_id();
291 int index = src_lane + (
self & ~(width-1));
292 return __llvm_amdgcn_ds_bpermute(index<<2, var);
296 unsigned int __shfl(
unsigned int var,
int src_lane,
int width = warpSize) {
297 union {
int i;
unsigned u;
float f; } tmp; tmp.u = var;
298 tmp.i = __shfl(tmp.i, src_lane, width);
303 float __shfl(
float var,
int src_lane,
int width = warpSize) {
304 union {
int i;
unsigned u;
float f; } tmp; tmp.f = var;
305 tmp.i = __shfl(tmp.i, src_lane, width);
310 double __shfl(
double var,
int src_lane,
int width = warpSize) {
311 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
312 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
"");
314 int tmp[2]; __builtin_memcpy(tmp, &var,
sizeof(tmp));
315 tmp[0] = __shfl(tmp[0], src_lane, width);
316 tmp[1] = __shfl(tmp[1], src_lane, width);
318 uint64_t tmp0 = (
static_cast<uint64_t
>(tmp[1]) << 32ull) |
static_cast<uint32_t
>(tmp[0]);
319 double tmp1; __builtin_memcpy(&tmp1, &tmp0,
sizeof(tmp0));
325 int __shfl_up(
int var,
unsigned int lane_delta,
int width = warpSize) {
326 int self = __lane_id();
327 int index =
self - lane_delta;
328 index = (index < (
self & ~(width-1)))?
self:index;
329 return __llvm_amdgcn_ds_bpermute(index<<2, var);
333 unsigned int __shfl_up(
unsigned int var,
unsigned int lane_delta,
int width = warpSize) {
334 union {
int i;
unsigned u;
float f; } tmp; tmp.u = var;
335 tmp.i = __shfl_up(tmp.i, lane_delta, width);
340 float __shfl_up(
float var,
unsigned int lane_delta,
int width = warpSize) {
341 union {
int i;
unsigned u;
float f; } tmp; tmp.f = var;
342 tmp.i = __shfl_up(tmp.i, lane_delta, width);
347 double __shfl_up(
double var,
unsigned int lane_delta,
int width = warpSize) {
348 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
349 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
"");
351 int tmp[2]; __builtin_memcpy(tmp, &var,
sizeof(tmp));
352 tmp[0] = __shfl_up(tmp[0], lane_delta, width);
353 tmp[1] = __shfl_up(tmp[1], lane_delta, width);
355 uint64_t tmp0 = (
static_cast<uint64_t
>(tmp[1]) << 32ull) |
static_cast<uint32_t
>(tmp[0]);
356 double tmp1; __builtin_memcpy(&tmp1, &tmp0,
sizeof(tmp0));
362 int __shfl_down(
int var,
unsigned int lane_delta,
int width = warpSize) {
363 int self = __lane_id();
364 int index =
self + lane_delta;
365 index = (int)((
self&(width-1))+lane_delta) >= width?
self:index;
366 return __llvm_amdgcn_ds_bpermute(index<<2, var);
370 unsigned int __shfl_down(
unsigned int var,
unsigned int lane_delta,
int width = warpSize) {
371 union {
int i;
unsigned u;
float f; } tmp; tmp.u = var;
372 tmp.i = __shfl_down(tmp.i, lane_delta, width);
377 float __shfl_down(
float var,
unsigned int lane_delta,
int width = warpSize) {
378 union {
int i;
unsigned u;
float f; } tmp; tmp.f = var;
379 tmp.i = __shfl_down(tmp.i, lane_delta, width);
384 double __shfl_down(
double var,
unsigned int lane_delta,
int width = warpSize) {
385 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
386 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
"");
388 int tmp[2]; __builtin_memcpy(tmp, &var,
sizeof(tmp));
389 tmp[0] = __shfl_down(tmp[0], lane_delta, width);
390 tmp[1] = __shfl_down(tmp[1], lane_delta, width);
392 uint64_t tmp0 = (
static_cast<uint64_t
>(tmp[1]) << 32ull) |
static_cast<uint32_t
>(tmp[0]);
393 double tmp1; __builtin_memcpy(&tmp1, &tmp0,
sizeof(tmp0));
399 int __shfl_xor(
int var,
int lane_mask,
int width = warpSize) {
400 int self = __lane_id();
401 int index =
self^lane_mask;
402 index = index >= ((
self+width)&~(width-1))?
self:index;
403 return __llvm_amdgcn_ds_bpermute(index<<2, var);
407 unsigned int __shfl_xor(
unsigned int var,
int lane_mask,
int width = warpSize) {
408 union {
int i;
unsigned u;
float f; } tmp; tmp.u = var;
409 tmp.i = __shfl_xor(tmp.i, lane_mask, width);
414 float __shfl_xor(
float var,
int lane_mask,
int width = warpSize) {
415 union {
int i;
unsigned u;
float f; } tmp; tmp.f = var;
416 tmp.i = __shfl_xor(tmp.i, lane_mask, width);
421 double __shfl_xor(
double var,
int lane_mask,
int width = warpSize) {
422 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
423 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
"");
425 int tmp[2]; __builtin_memcpy(tmp, &var,
sizeof(tmp));
426 tmp[0] = __shfl_xor(tmp[0], lane_mask, width);
427 tmp[1] = __shfl_xor(tmp[1], lane_mask, width);
429 uint64_t tmp0 = (
static_cast<uint64_t
>(tmp[1]) << 32ull) |
static_cast<uint32_t
>(tmp[0]);
430 double tmp1; __builtin_memcpy(&tmp1, &tmp0,
sizeof(tmp0));
434 #define MASK1 0x00ff00ff 435 #define MASK2 0xff00ff00 437 __device__
static inline char4 __hip_hc_add8pk(char4 in1, char4 in2) {
439 unsigned one1 = in1.w & MASK1;
440 unsigned one2 = in2.w & MASK1;
441 out.w = (one1 + one2) & MASK1;
442 one1 = in1.w & MASK2;
443 one2 = in2.w & MASK2;
444 out.w = out.w | ((one1 + one2) & MASK2);
448 __device__
static inline char4 __hip_hc_sub8pk(char4 in1, char4 in2) {
450 unsigned one1 = in1.w & MASK1;
451 unsigned one2 = in2.w & MASK1;
452 out.w = (one1 - one2) & MASK1;
453 one1 = in1.w & MASK2;
454 one2 = in2.w & MASK2;
455 out.w = out.w | ((one1 - one2) & MASK2);
459 __device__
static inline char4 __hip_hc_mul8pk(char4 in1, char4 in2) {
461 unsigned one1 = in1.w & MASK1;
462 unsigned one2 = in2.w & MASK1;
463 out.w = (one1 * one2) & MASK1;
464 one1 = in1.w & MASK2;
465 one2 = in2.w & MASK2;
466 out.w = out.w | ((one1 * one2) & MASK2);
475 __device__
static inline float __double2float_rd(
double x) {
return (
double)x; }
476 __device__
static inline float __double2float_rn(
double x) {
return (
double)x; }
477 __device__
static inline float __double2float_ru(
double x) {
return (
double)x; }
478 __device__
static inline float __double2float_rz(
double x) {
return (
double)x; }
480 __device__
static inline int __double2hiint(
double x) {
481 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
484 __builtin_memcpy(tmp, &x,
sizeof(tmp));
488 __device__
static inline int __double2loint(
double x) {
489 static_assert(
sizeof(
double) == 2 *
sizeof(
int),
"");
492 __builtin_memcpy(tmp, &x,
sizeof(tmp));
497 __device__
static inline int __double2int_rd(
double x) {
return (
int)x; }
498 __device__
static inline int __double2int_rn(
double x) {
return (
int)x; }
499 __device__
static inline int __double2int_ru(
double x) {
return (
int)x; }
500 __device__
static inline int __double2int_rz(
double x) {
return (
int)x; }
502 __device__
static inline long long int __double2ll_rd(
double x) {
return (
long long int)x; }
503 __device__
static inline long long int __double2ll_rn(
double x) {
return (
long long int)x; }
504 __device__
static inline long long int __double2ll_ru(
double x) {
return (
long long int)x; }
505 __device__
static inline long long int __double2ll_rz(
double x) {
return (
long long int)x; }
507 __device__
static inline unsigned int __double2uint_rd(
double x) {
return (
unsigned int)x; }
508 __device__
static inline unsigned int __double2uint_rn(
double x) {
return (
unsigned int)x; }
509 __device__
static inline unsigned int __double2uint_ru(
double x) {
return (
unsigned int)x; }
510 __device__
static inline unsigned int __double2uint_rz(
double x) {
return (
unsigned int)x; }
512 __device__
static inline unsigned long long int __double2ull_rd(
double x) {
513 return (
unsigned long long int)x;
515 __device__
static inline unsigned long long int __double2ull_rn(
double x) {
516 return (
unsigned long long int)x;
518 __device__
static inline unsigned long long int __double2ull_ru(
double x) {
519 return (
unsigned long long int)x;
521 __device__
static inline unsigned long long int __double2ull_rz(
double x) {
522 return (
unsigned long long int)x;
525 __device__
static inline long long int __double_as_longlong(
double x) {
526 static_assert(
sizeof(
long long) ==
sizeof(
double),
"");
529 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
548 __device__
static inline int __float2int_rd(
float x) {
return (
int)__ocml_floor_f32(x); }
549 __device__
static inline int __float2int_rn(
float x) {
return (
int)__ocml_rint_f32(x); }
550 __device__
static inline int __float2int_ru(
float x) {
return (
int)__ocml_ceil_f32(x); }
551 __device__
static inline int __float2int_rz(
float x) {
return (
int)__ocml_trunc_f32(x); }
553 __device__
static inline long long int __float2ll_rd(
float x) {
return (
long long int)x; }
554 __device__
static inline long long int __float2ll_rn(
float x) {
return (
long long int)x; }
555 __device__
static inline long long int __float2ll_ru(
float x) {
return (
long long int)x; }
556 __device__
static inline long long int __float2ll_rz(
float x) {
return (
long long int)x; }
558 __device__
static inline unsigned int __float2uint_rd(
float x) {
return (
unsigned int)x; }
559 __device__
static inline unsigned int __float2uint_rn(
float x) {
return (
unsigned int)x; }
560 __device__
static inline unsigned int __float2uint_ru(
float x) {
return (
unsigned int)x; }
561 __device__
static inline unsigned int __float2uint_rz(
float x) {
return (
unsigned int)x; }
563 __device__
static inline unsigned long long int __float2ull_rd(
float x) {
564 return (
unsigned long long int)x;
566 __device__
static inline unsigned long long int __float2ull_rn(
float x) {
567 return (
unsigned long long int)x;
569 __device__
static inline unsigned long long int __float2ull_ru(
float x) {
570 return (
unsigned long long int)x;
572 __device__
static inline unsigned long long int __float2ull_rz(
float x) {
573 return (
unsigned long long int)x;
576 __device__
static inline int __float_as_int(
float x) {
577 static_assert(
sizeof(
int) ==
sizeof(
float),
"");
580 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
585 __device__
static inline unsigned int __float_as_uint(
float x) {
586 static_assert(
sizeof(
unsigned int) ==
sizeof(
float),
"");
589 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
594 __device__
static inline double __hiloint2double(
int hi,
int lo) {
595 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
"");
597 uint64_t tmp0 = (
static_cast<uint64_t
>(hi) << 32ull) |
static_cast<uint32_t
>(lo);
599 __builtin_memcpy(&tmp1, &tmp0,
sizeof(tmp0));
604 __device__
static inline double __int2double_rn(
int x) {
return (
double)x; }
606 __device__
static inline float __int2float_rd(
int x) {
return (
float)x; }
607 __device__
static inline float __int2float_rn(
int x) {
return (
float)x; }
608 __device__
static inline float __int2float_ru(
int x) {
return (
float)x; }
609 __device__
static inline float __int2float_rz(
int x) {
return (
float)x; }
611 __device__
static inline float __int_as_float(
int x) {
612 static_assert(
sizeof(
float) ==
sizeof(
int),
"");
615 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
620 __device__
static inline double __ll2double_rd(
long long int x) {
return (
double)x; }
621 __device__
static inline double __ll2double_rn(
long long int x) {
return (
double)x; }
622 __device__
static inline double __ll2double_ru(
long long int x) {
return (
double)x; }
623 __device__
static inline double __ll2double_rz(
long long int x) {
return (
double)x; }
625 __device__
static inline float __ll2float_rd(
long long int x) {
return (
float)x; }
626 __device__
static inline float __ll2float_rn(
long long int x) {
return (
float)x; }
627 __device__
static inline float __ll2float_ru(
long long int x) {
return (
float)x; }
628 __device__
static inline float __ll2float_rz(
long long int x) {
return (
float)x; }
630 __device__
static inline double __longlong_as_double(
long long int x) {
631 static_assert(
sizeof(
double) ==
sizeof(
long long),
"");
634 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
639 __device__
static inline double __uint2double_rn(
int x) {
return (
double)x; }
641 __device__
static inline float __uint2float_rd(
unsigned int x) {
return (
float)x; }
642 __device__
static inline float __uint2float_rn(
unsigned int x) {
return (
float)x; }
643 __device__
static inline float __uint2float_ru(
unsigned int x) {
return (
float)x; }
644 __device__
static inline float __uint2float_rz(
unsigned int x) {
return (
float)x; }
646 __device__
static inline float __uint_as_float(
unsigned int x) {
647 static_assert(
sizeof(
float) ==
sizeof(
unsigned int),
"");
650 __builtin_memcpy(&tmp, &x,
sizeof(tmp));
655 __device__
static inline double __ull2double_rd(
unsigned long long int x) {
return (
double)x; }
656 __device__
static inline double __ull2double_rn(
unsigned long long int x) {
return (
double)x; }
657 __device__
static inline double __ull2double_ru(
unsigned long long int x) {
return (
double)x; }
658 __device__
static inline double __ull2double_rz(
unsigned long long int x) {
return (
double)x; }
660 __device__
static inline float __ull2float_rd(
unsigned long long int x) {
return (
float)x; }
661 __device__
static inline float __ull2float_rn(
unsigned long long int x) {
return (
float)x; }
662 __device__
static inline float __ull2float_ru(
unsigned long long int x) {
return (
float)x; }
663 __device__
static inline float __ull2float_rz(
unsigned long long int x) {
return (
float)x; }
666 #define __HCC_OR_HIP_CLANG__ 1 667 #elif defined(__clang__) && defined(__HIP__) 668 #define __HCC_OR_HIP_CLANG__ 1 670 #define __HCC_OR_HIP_CLANG__ 0 673 #ifdef __HCC_OR_HIP_CLANG__ 676 __device__
long long int __clock64();
677 __device__
long long int __clock();
678 __device__
long long int clock64();
679 __device__
long long int clock();
681 __device__
void __named_sync(
int a,
int b);
683 #ifdef __HIP_DEVICE_COMPILE__ 687 extern "C" uint64_t __clock_u64() __HC__;
691 inline __attribute((always_inline))
692 long long int __clock64() {
695 return (
long long int) __clock_u64();
697 return (
long long int) __builtin_amdgcn_s_memrealtime();
702 inline __attribute((always_inline))
703 long long int __clock() {
return __clock64(); }
706 inline __attribute__((always_inline))
707 long long int clock64() {
return __clock64(); }
710 inline __attribute__((always_inline))
711 long long int clock() {
return __clock(); }
716 void __named_sync(
int a,
int b) { __builtin_amdgcn_s_barrier(); }
718 #endif // __HIP_DEVICE_COMPILE__ 723 int __all(
int predicate) {
724 return __ockl_wfall_i32(predicate);
729 int __any(
int predicate) {
730 return __ockl_wfany_i32(predicate);
738 unsigned long long int __ballot(
int predicate) {
739 return __builtin_amdgcn_uicmp(predicate, 0, ICMP_NE);
744 unsigned long long int __ballot64(
int predicate) {
745 return __builtin_amdgcn_uicmp(predicate, 0, ICMP_NE);
751 uint64_t __lanemask_gt()
753 uint32_t lane = __ockl_lane_u32();
756 uint64_t ballot = __ballot64(1);
757 uint64_t mask = (~((uint64_t)0)) << (lane + 1);
758 return mask & ballot;
763 uint64_t __lanemask_lt()
765 uint32_t lane = __ockl_lane_u32();
766 int64_t ballot = __ballot64(1);
767 uint64_t mask = ((uint64_t)1 << lane) - (uint64_t)1;
768 return mask & ballot;
773 uint64_t __lanemask_eq()
775 uint32_t lane = __ockl_lane_u32();
776 int64_t mask = ((uint64_t)1 << lane);
781 __device__
inline void* __local_to_generic(
void* p) {
return p; }
783 #ifdef __HIP_DEVICE_COMPILE__ 786 void* __get_dynamicgroupbaseptr()
789 return (
char*)__local_to_generic((
void*)__to_local(__llvm_amdgcn_groupstaticsize()));
793 void* __get_dynamicgroupbaseptr();
794 #endif // __HIP_DEVICE_COMPILE__ 798 void *__amdgcn_get_dynamicgroupbaseptr() {
799 return __get_dynamicgroupbaseptr();
802 #if defined(__HCC__) && (__hcc_minor__ < 3) 804 #define __CLK_LOCAL_MEM_FENCE 0x01 805 typedef unsigned __cl_mem_fence_flags;
807 typedef enum __memory_scope {
808 __memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
809 __memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
810 __memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
811 __memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
812 __memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
816 typedef enum __memory_order
818 __memory_order_relaxed = __ATOMIC_RELAXED,
819 __memory_order_acquire = __ATOMIC_ACQUIRE,
820 __memory_order_release = __ATOMIC_RELEASE,
821 __memory_order_acq_rel = __ATOMIC_ACQ_REL,
822 __memory_order_seq_cst = __ATOMIC_SEQ_CST
828 __atomic_work_item_fence(__cl_mem_fence_flags flags, __memory_order order, __memory_scope scope)
831 if (order != __memory_order_relaxed) {
833 case __memory_scope_work_item:
835 case __memory_scope_sub_group:
837 case __memory_order_relaxed:
break;
838 case __memory_order_acquire: __llvm_fence_acq_sg();
break;
839 case __memory_order_release: __llvm_fence_rel_sg();
break;
840 case __memory_order_acq_rel: __llvm_fence_ar_sg();
break;
841 case __memory_order_seq_cst: __llvm_fence_sc_sg();
break;
844 case __memory_scope_work_group:
846 case __memory_order_relaxed:
break;
847 case __memory_order_acquire: __llvm_fence_acq_wg();
break;
848 case __memory_order_release: __llvm_fence_rel_wg();
break;
849 case __memory_order_acq_rel: __llvm_fence_ar_wg();
break;
850 case __memory_order_seq_cst: __llvm_fence_sc_wg();
break;
853 case __memory_scope_device:
855 case __memory_order_relaxed:
break;
856 case __memory_order_acquire: __llvm_fence_acq_dev();
break;
857 case __memory_order_release: __llvm_fence_rel_dev();
break;
858 case __memory_order_acq_rel: __llvm_fence_ar_dev();
break;
859 case __memory_order_seq_cst: __llvm_fence_sc_dev();
break;
862 case __memory_scope_all_svm_devices:
864 case __memory_order_relaxed:
break;
865 case __memory_order_acquire: __llvm_fence_acq_sys();
break;
866 case __memory_order_release: __llvm_fence_rel_sys();
break;
867 case __memory_order_acq_rel: __llvm_fence_ar_sys();
break;
868 case __memory_order_seq_cst: __llvm_fence_sc_sys();
break;
879 static void __threadfence()
881 __atomic_work_item_fence(0, __memory_order_seq_cst, __memory_scope_device);
886 static void __threadfence_block()
888 __atomic_work_item_fence(0, __memory_order_seq_cst, __memory_scope_work_group);
893 static void __threadfence_system()
895 __atomic_work_item_fence(0, __memory_order_seq_cst, __memory_scope_all_svm_devices);
901 __attribute__((weak))
903 return __builtin_trap();
907 #endif // __HCC_OR_HIP_CLANG__ 917 #define HIP_DYNAMIC_SHARED(type, var) type* var = (type*)__get_dynamicgroupbaseptr(); 919 #define HIP_DYNAMIC_SHARED_ATTRIBUTE 922 #elif defined(__clang__) && defined(__HIP__) 924 #pragma push_macro("__DEVICE__") 925 #define __DEVICE__ extern "C" __device__ __attribute__((always_inline)) \ 926 __attribute__((weak)) 930 void __assert_fail(
const char * __assertion,
933 const char *__function)
941 void __assertfail(
const char * __assertion,
944 const char *__function,
953 static void __work_group_barrier(__cl_mem_fence_flags flags, __memory_scope scope)
956 __atomic_work_item_fence(flags, __memory_order_release, scope);
957 __builtin_amdgcn_s_barrier();
958 __atomic_work_item_fence(flags, __memory_order_acquire, scope);
960 __builtin_amdgcn_s_barrier();
966 static void __barrier(
int n)
968 __work_group_barrier((__cl_mem_fence_flags)n, __memory_scope_work_group);
973 __attribute__((convergent))
976 __barrier(__CLK_LOCAL_MEM_FENCE);
997 #define HW_ID_CU_ID_SIZE 4 998 #define HW_ID_CU_ID_OFFSET 8 1000 #define HW_ID_SE_ID_SIZE 2 1001 #define HW_ID_SE_ID_OFFSET 13 1010 #define GETREG_IMMED(SZ,OFF,REG) (((SZ) << 11) | ((OFF) << 6) | (REG)) 1020 unsigned __smid(
void)
1022 unsigned cu_id = __builtin_amdgcn_s_getreg(
1023 GETREG_IMMED(HW_ID_CU_ID_SIZE-1, HW_ID_CU_ID_OFFSET, HW_ID));
1024 unsigned se_id = __builtin_amdgcn_s_getreg(
1025 GETREG_IMMED(HW_ID_SE_ID_SIZE-1, HW_ID_SE_ID_OFFSET, HW_ID));
1028 return (se_id << HW_ID_CU_ID_SIZE) + cu_id;
1031 #pragma push_macro("__DEVICE__") 1035 #define HIP_DYNAMIC_SHARED(type, var) \ 1036 type* var = (type*)__amdgcn_get_dynamicgroupbaseptr(); 1038 #define HIP_DYNAMIC_SHARED_ATTRIBUTE 1041 #endif //defined(__clang__) && defined(__HIP__) 1045 static inline __device__
void* __hip_hc_memcpy(
void* dst,
const void* src,
size_t size) {
1046 auto dstPtr =
static_cast<unsigned char*
>(dst);
1047 auto srcPtr =
static_cast<const unsigned char*
>(src);
1049 while (size >= 4u) {
1050 dstPtr[0] = srcPtr[0];
1051 dstPtr[1] = srcPtr[1];
1052 dstPtr[2] = srcPtr[2];
1053 dstPtr[3] = srcPtr[3];
1061 dstPtr[2] = srcPtr[2];
1063 dstPtr[1] = srcPtr[1];
1065 dstPtr[0] = srcPtr[0];
1071 static inline __device__
void* __hip_hc_memset(
void* dst,
unsigned char val,
size_t size) {
1072 auto dstPtr =
static_cast<unsigned char*
>(dst);
1074 while (size >= 4u) {
1094 static inline __device__
void* memcpy(
void* dst,
const void* src,
size_t size) {
1095 return __hip_hc_memcpy(dst, src, size);
1098 static inline __device__
void* memset(
void* ptr,
int val,
size_t size) {
1099 unsigned char val8 =
static_cast<unsigned char>(val);
1100 return __hip_hc_memset(ptr, val8, size);
Contains declarations for types and functions in device library.
Definition: device_functions.h:124
Definition: device_functions.h:131
Contains declarations for wrapper functions for llvm intrinsics like llvm.amdgcn.s.barrier.