| 1 |
// Start of prelude.cl |
| 2 |
|
| 3 |
#define SCALAR_FUN_ATTR static inline |
| 4 |
#define FUTHARK_FUN_ATTR static |
| 5 |
|
| 6 |
typedef char int8_t; |
| 7 |
typedef short int16_t; |
| 8 |
typedef int int32_t; |
| 9 |
typedef long int64_t; |
| 10 |
|
| 11 |
typedef uchar uint8_t; |
| 12 |
typedef ushort uint16_t; |
| 13 |
typedef uint uint32_t; |
| 14 |
typedef ulong uint64_t; |
| 15 |
|
| 16 |
#define get_tblock_id(d) get_group_id(d) |
| 17 |
#define get_num_tblocks(d) get_num_groups(d) |
| 18 |
|
| 19 |
// Clang-based OpenCL implementations need this for 'static' to work. |
| 20 |
#ifdef cl_clang_storage_class_specifiers |
| 21 |
#pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable |
| 22 |
#endif |
| 23 |
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable |
| 24 |
|
| 25 |
#ifdef FUTHARK_F64_ENABLED |
| 26 |
#pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 27 |
#endif |
| 28 |
|
| 29 |
#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable |
| 30 |
#pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable |
| 31 |
|
| 32 |
// NVIDIAs OpenCL does not create device-wide memory fences (see #734), so we |
| 33 |
// use inline assembly if we detect we are on an NVIDIA GPU. |
| 34 |
#ifdef cl_nv_pragma_unroll |
| 35 |
static inline void mem_fence_global() { |
| 36 |
asm("membar.gl;"); |
| 37 |
} |
| 38 |
#else |
| 39 |
static inline void mem_fence_global() { |
| 40 |
mem_fence(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE); |
| 41 |
} |
| 42 |
#endif |
| 43 |
static inline void mem_fence_local() { |
| 44 |
mem_fence(CLK_LOCAL_MEM_FENCE); |
| 45 |
} |
| 46 |
|
| 47 |
static inline void barrier_local() { |
| 48 |
barrier(CLK_LOCAL_MEM_FENCE); |
| 49 |
} |
| 50 |
|
| 51 |
// Important for this to be int64_t so it has proper alignment for any type. |
| 52 |
#define SHARED_MEM_PARAM __local uint64_t* shared_mem, |
| 53 |
#define FUTHARK_KERNEL __kernel |
| 54 |
#define FUTHARK_KERNEL_SIZED(a,b,c) __attribute__((reqd_work_group_size(a, b, c))) __kernel |
| 55 |
|
| 56 |
// End of prelude.cl |