| 1 |
// start of prelude.cu |
| 2 |
|
| 3 |
#define SCALAR_FUN_ATTR __device__ static inline |
| 4 |
#define FUTHARK_FUN_ATTR __device__ static |
| 5 |
#define FUTHARK_F64_ENABLED |
| 6 |
|
| 7 |
#if defined(__CUDACC_RTC__) || defined(__HIPCC_RTC__) |
| 8 |
typedef char int8_t; |
| 9 |
typedef short int16_t; |
| 10 |
typedef int int32_t; |
| 11 |
typedef long long int64_t; |
| 12 |
typedef unsigned char uint8_t; |
| 13 |
typedef unsigned short uint16_t; |
| 14 |
typedef unsigned int uint32_t; |
| 15 |
typedef unsigned long long uint64_t; |
| 16 |
#else |
| 17 |
// This is for the benefit of offline compilation with clang. |
| 18 |
typedef signed char int8_t; |
| 19 |
typedef short int16_t; |
| 20 |
typedef int int32_t; |
| 21 |
typedef long int64_t; |
| 22 |
typedef unsigned char uint8_t; |
| 23 |
typedef unsigned short uint16_t; |
| 24 |
typedef unsigned int uint32_t; |
| 25 |
typedef unsigned long uint64_t; |
| 26 |
#endif |
| 27 |
|
| 28 |
#if defined(__CUDACC_RTC__) |
| 29 |
typedef uint64_t uintptr_t; |
| 30 |
#endif |
| 31 |
|
| 32 |
#if defined(__HIPCC_RTC__) |
| 33 |
typedef uint64_t uintptr_t; |
| 34 |
#endif |
| 35 |
|
| 36 |
#define __global |
| 37 |
#define __local |
| 38 |
#define __private |
| 39 |
#define __constant |
| 40 |
#define __write_only |
| 41 |
#define __read_only |
| 42 |
|
| 43 |
static inline __device__ int get_tblock_id(int d) { |
| 44 |
switch (d) { |
| 45 |
case 0: return blockIdx.x; |
| 46 |
case 1: return blockIdx.y; |
| 47 |
case 2: return blockIdx.z; |
| 48 |
default: return 0; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
static inline __device__ int get_num_tblocks(int d) { |
| 53 |
switch(d) { |
| 54 |
case 0: return gridDim.x; |
| 55 |
case 1: return gridDim.y; |
| 56 |
case 2: return gridDim.z; |
| 57 |
default: return 0; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
static inline __device__ int get_global_id(int d) { |
| 62 |
switch (d) { |
| 63 |
case 0: return threadIdx.x + blockIdx.x * blockDim.x; |
| 64 |
case 1: return threadIdx.y + blockIdx.y * blockDim.y; |
| 65 |
case 2: return threadIdx.z + blockIdx.z * blockDim.z; |
| 66 |
default: return 0; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
static inline __device__ int get_local_id(int d) { |
| 71 |
switch (d) { |
| 72 |
case 0: return threadIdx.x; |
| 73 |
case 1: return threadIdx.y; |
| 74 |
case 2: return threadIdx.z; |
| 75 |
default: return 0; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
static inline __device__ int get_local_size(int d) { |
| 80 |
switch (d) { |
| 81 |
case 0: return blockDim.x; |
| 82 |
case 1: return blockDim.y; |
| 83 |
case 2: return blockDim.z; |
| 84 |
default: return 0; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
static inline __device__ int get_global_size(int d) { |
| 89 |
switch (d) { |
| 90 |
case 0: return gridDim.x * blockDim.x; |
| 91 |
case 1: return gridDim.y * blockDim.y; |
| 92 |
case 2: return gridDim.z * blockDim.z; |
| 93 |
default: return 0; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
#define CLK_LOCAL_MEM_FENCE 1 |
| 99 |
#define CLK_GLOBAL_MEM_FENCE 2 |
| 100 |
static inline __device__ void barrier(int x) { |
| 101 |
__syncthreads(); |
| 102 |
} |
| 103 |
static inline __device__ void mem_fence_local() { |
| 104 |
__threadfence_block(); |
| 105 |
} |
| 106 |
static inline __device__ void mem_fence_global() { |
| 107 |
__threadfence(); |
| 108 |
} |
| 109 |
|
| 110 |
static inline __device__ void barrier_local() { |
| 111 |
__syncthreads(); |
| 112 |
} |
| 113 |
|
| 114 |
#if defined(__CUDACC_RTC__) || defined(__HIPCC_RTC__) |
| 115 |
#define NAN (0.0/0.0) |
| 116 |
#define INFINITY (1.0/0.0) |
| 117 |
#endif |
| 118 |
|
| 119 |
extern volatile __shared__ unsigned char shared_mem[]; |
| 120 |
|
| 121 |
#define SHARED_MEM_PARAM |
| 122 |
#define FUTHARK_KERNEL extern "C" __global__ __launch_bounds__(MAX_THREADS_PER_BLOCK) |
| 123 |
#define FUTHARK_KERNEL_SIZED(a,b,c) extern "C" __global__ __launch_bounds__(a*b*c) |
| 124 |
|
| 125 |
// End of prelude.cu |