alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1/* Copyright 2023 Benjamin Worpitz, Matthias Werner, René Widera, Sergei Bastrakov, Jeffrey Kelling,
2 * Bernhard Manfred Gruber, Jan Stephan, Mehmet Yusufoglu
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
8#include "alpaka/core/PP.hpp"
10#include "alpaka/version.hpp"
11
12// guard cmake target alpaka
13#if defined(ALPAKA_CMAKE_TARGET_ALPAKA) && !defined(ALPAKA_CMAKE_TARGET_ALPAKA_FINALIZE_CALLED)
14# error "After adding the cmake target alpaka or alpaka::alpaka you should call 'alpaka_finalize(targetName)'"
15#endif
16// guard cmake target alpaka::headers
17#if defined(ALPAKA_CMAKE_TARGET_HEADERS) && !defined(ALPAKA_CMAKE_TARGET_HEADERS_FINALIZE_CALLED)
18# error "After adding the cmake target alpaka::headers you should call 'alpaka_finalize(targetName)'"
19#endif
20// guard cmake target alpaka::cuda
21#if defined(ALPAKA_CMAKE_TARGET_CUDA) && !defined(ALPAKA_CMAKE_TARGET_CUDA_FINALIZE_CALLED)
22# error "After adding the cmake target alpaka::cuda you should call 'alpaka_finalize(targetName)'"
23#endif
24// guard cmake target alpaka::hip
25#if defined(ALPAKA_CMAKE_TARGET_HIP) && !defined(ALPAKA_CMAKE_TARGET_HIP_FINALIZE_CALLED)
26# error "After adding the cmake target alpaka::hip you should call 'alpaka_finalize(targetName)'"
27#endif
28// guard cmake target alpaka::onapi
29#if defined(ALPAKA_CMAKE_TARGET_ONEAPI) && !defined(ALPAKA_CMAKE_TARGET_ONEAPI_FINALIZE_CALLED)
30# error "After adding the cmake target alpaka::oneapi you should call 'alpaka_finalize(targetName)'"
31#endif
32// guard cmake target alpaka::host
33#if defined(ALPAKA_CMAKE_TARGET_HOST) && !defined(ALPAKA_CMAKE_TARGET_HOST_FINALIZE_CALLED)
34# error "After adding the cmake target alpaka::host you should call 'alpaka_finalize(targetName)'"
35#endif
36
37#ifdef __INTEL_COMPILER
38# warning \
39 "The Intel Classic compiler (icpc) is no longer supported. Please upgrade to the Intel LLVM compiler (ipcx)."
40#endif
41
42// ######## detect operating systems ########
43
44// WINDOWS
45#if !defined(ALPAKA_OS_WINDOWS)
46# if defined(_WIN64) || defined(__MINGW64__)
47# define ALPAKA_OS_WINDOWS 1
48# else
49# define ALPAKA_OS_WINDOWS 0
50# endif
51#endif
52
53
54// Linux
55#if !defined(ALPAKA_OS_LINUX)
56# if defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
57# define ALPAKA_OS_LINUX 1
58# else
59# define ALPAKA_OS_LINUX 0
60# endif
61#endif
62
63// Apple
64#if !defined(ALPAKA_OS_IOS)
65# if defined(__APPLE__)
66# define ALPAKA_OS_IOS 1
67# else
68# define ALPAKA_OS_IOS 0
69# endif
70#endif
71
72// Cygwin
73#if !defined(ALPAKA_OS_CYGWIN)
74# if defined(__CYGWIN__)
75# define ALPAKA_OS_CYGWIN 1
76# else
77# define ALPAKA_OS_CYGWIN 0
78# endif
79#endif
80
81// ### architectures
82
83// X86
84#if !defined(ALPAKA_ARCH_X86)
85# if defined(__x86_64__) || defined(_M_X64)
86# define ALPAKA_ARCH_X86 1
87# else
88# define ALPAKA_ARCH_X86 0
89# endif
90#endif
91
92// RISCV
93#if !defined(ALPAKA_ARCH_RISCV)
94# if defined(__riscv)
95# define ALPAKA_ARCH_RISCV 1
96# else
97# define ALPAKA_ARCH_RISCV 0
98# endif
99#endif
100
101// ARM
102#if !defined(ALPAKA_ARCH_ARM)
103# if defined(__ARM_ARCH) || defined(__arm__) || defined(__arm64)
104# define ALPAKA_ARCH_ARM 1
105# else
106# define ALPAKA_ARCH_ARM 0
107# endif
108#endif
109
110/** NVIDIA device compile
111 *
112 * * The version on the host side will always be ALPAKA_VERSION_NUMBER_NOT_AVAILABLE.
113 *
114 * Rules:
115 * - sm75 -> ALPAKA_VERSION_NUMBER(7,5,0)
116 * - sm91 -> ALPAKA_VERSION_NUMBER(9,1,0)
117 */
118#if !defined(ALPAKA_ARCH_PTX)
119# if defined(__CUDA_ARCH__)
120# define ALPAKA_ARCH_PTX ALPAKA_VRP_TO_VERSION(__CUDA_ARCH__)
121# else
122# define ALPAKA_ARCH_PTX ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
123# endif
124#endif
125
126/** HIP device compile
127 *
128 * The version on the host side will always be ALPAKA_VERSION_NUMBER_NOT_AVAILABLE.
129 * On the device side unknown version will be set to ALPAKA_VERSION_NUMBER_UNKNOWN.
130 *
131 * Rules:
132 * - the last two digits will be handled as HEX values and support 0-9 and a-f
133 * - gfx9xy (numeric): 9xy -> ALPAKA_VERSION_NUMBER(9,x,y)
134 * - gfx10xy / gfx11xy: stxy -> ALPAKA_VERSION_NUMBER(st,x,y)
135 * - Suffix: a == 10, b == 11, c == 12
136 * - gfx90a -> ALPAKA_VERSION_NUMBER(9,0,10)
137 * - gfx90c -> ALPAKA_VERSION_NUMBER(9,0,12)
138 */
139#if !defined(ALPAKA_ARCH_AMD)
140# if defined(__HIP__) && defined(__HIP_DEVICE_COMPILE__) && __HIP_DEVICE_COMPILE__ == 1
141# define ALPAKA_ARCH_AMD ALPAKA_AMDGPU_ARCH
142# else
143# define ALPAKA_ARCH_AMD ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
144# endif
145#endif
146
147// ######## compiler ########
148
149// HIP compiler detection
150#if !defined(ALPAKA_COMP_HIP)
151# if defined(__HIP__) // Defined by hip-clang and vanilla clang in HIP mode.
152# include <hip/hip_version.h>
153// HIP doesn't give us a patch level for the last entry, just a gitdate
154# define ALPAKA_COMP_HIP ALPAKA_VERSION_NUMBER(HIP_VERSION_MAJOR, HIP_VERSION_MINOR, 0)
155# else
156# define ALPAKA_COMP_HIP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
157# endif
158#endif
159
160// nvcc compiler
161#if defined(__NVCC__)
162# define ALPAKA_COMP_NVCC ALPAKA_VERSION_NUMBER(__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, __CUDACC_VER_BUILD__)
163#else
164# define ALPAKA_COMP_NVCC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
165#endif
166
167// clang compiler
168#if defined(__clang__)
169# define ALPAKA_COMP_CLANG ALPAKA_VERSION_NUMBER(__clang_major__, __clang_minor__, __clang_patchlevel__)
170#else
171# define ALPAKA_COMP_CLANG ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
172#endif
173
174// MSVC compiler
175#if defined(_MSC_VER)
176# define ALPAKA_COMP_MSVC \
177 ALPAKA_VERSION_NUMBER((_MSC_FULL_VER) % 10'000'000, ((_MSC_FULL_VER) / 100000) % 100, (_MSC_FULL_VER) % 100000)
178#else
179# define ALPAKA_COMP_MSVC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
180#endif
181
182// gnu compiler (excluding compilers which emulates gnu compiler like clang)
183#if defined(__GNUC__) && !defined(__clang__)
184# if defined(__GNUC_PATCHLEVEL__)
185# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
186# else
187# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER(__GNUC__, __GNUC_MINOR__, 0)
188# endif
189#else
190# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
191#endif
192
193// IBM compiler
194// only clang based is supported
195#if defined(__ibmxl__)
196# define ALPAKA_COMP_IBM ALPAKA_VERSION_NUMBER(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
197#else
198# define ALPAKA_COMP_IBM ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
199#endif
200
201// clang CUDA compiler detection
202// Currently __CUDA__ is only defined by clang when compiling CUDA code.
203#if defined(__clang__) && defined(__CUDA__)
204# define ALPAKA_COMP_CLANG_CUDA ALPAKA_VERSION_NUMBER(__clang_major__, __clang_minor__, __clang_patchlevel__)
205#else
206# define ALPAKA_COMP_CLANG_CUDA ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
207#endif
208
209// PGI and NV HPC SDK compiler detection
210#if defined(__PGI)
211# define ALPAKA_COMP_PGI ALPAKA_VERSION_NUMBER(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
212#else
213# define ALPAKA_COMP_PGI ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
214#endif
215
216// Intel LLVM compiler detection
217#if !defined(ALPAKA_COMP_ICPX)
218# if defined(SYCL_LANGUAGE_VERSION) && defined(__INTEL_LLVM_COMPILER)
219// The version string for icpx 2023.1.0 is 20230100. In Boost.Predef this becomes (53,1,0).
220# define ALPAKA_COMP_ICPX ALPAKA_YYYYMMDD_TO_VERSION(__INTEL_LLVM_COMPILER)
221# else
222# define ALPAKA_COMP_ICPX ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
223# endif
224#endif
225
226// ######## C++ language ########
227
228//---------------------------------------HIP-----------------------------------
229// __HIP__ is defined by both hip-clang and vanilla clang in HIP mode.
230// https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_porting_guide.md#compiler-defines-summary
231#if !defined(ALPAKA_LANG_HIP)
232# if defined(__HIP__)
233# include <hip/hip_version.h>
234// HIP doesn't give us a patch level for the last entry, just a gitdate
235# define ALPAKA_LANG_HIP ALPAKA_VERSION_NUMBER(HIP_VERSION_MAJOR, HIP_VERSION_MINOR, 0)
236# else
237# define ALPAKA_LANG_HIP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
238# endif
239#endif
240
241// CUDA
242#if !defined(ALPAKA_LANG_CUDA)
243# if defined(__CUDACC__) || defined(__CUDA__)
244# include <cuda.h>
245# if __has_include(<cuda/atomic>)
246# define ALPAKA_CUDA_ATOMIC
247# include <cuda/atomic>
248# if ALPAKA_COMP_CLANG_CUDA && defined(_Float16)
249# pragma clang diagnostic push
250# pragma clang diagnostic ignored "-Wreserved-identifier"
251// We see errors when using clang as the CUDA compiler if TBB is also enabled
252// Errors occour inside TBB because the _Float16 macro is redefined and pulled in from <cuda/atomic>
253# undef _Float16
254# pragma clang diagnostic pop
255# endif
256# endif
257// CUDA doesn't give us a patch level for the last entry, just zero.
258# define ALPAKA_LANG_CUDA ALPAKA_VVRRP_TO_VERSION(CUDART_VERSION)
259# else
260# define ALPAKA_LANG_CUDA ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
261# endif
262#endif
263
264// Intel OneAPI Sycl GPU
265#if !defined(ALPAKA_LANG_SYCL)
266# if defined(SYCL_LANGUAGE_VERSION)
267# define ALPAKA_LANG_SYCL ALPAKA_YYYYMMDD_TO_VERSION(SYCL_LANGUAGE_VERSION)
268# else
269# define ALPAKA_LANG_SYCL ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
270# endif
271# if (ALPAKA_COMP_ICPX)
272// ONE API must be detected via the ICPX compiler see
273// https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/use-predefined-macros-to-specify-intel-compilers.html
274# define ALPAKA_LANG_ONEAPI ALPAKA_COMP_ICPX
275# else
276# define ALPAKA_LANG_ONEAPI ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
277# endif
278#endif
279
280// OpenMP
281#if !defined(ALPAKA_OMP)
282# if defined(_OPENMP)
283# include <omp.h>
284# endif
285# if defined(_OPENMP)
286# define ALPAKA_OMP ALPAKA_YYYYMM_TO_VERSION(_OPENMP)
287# else
288# define ALPAKA_OMP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
289# endif
290#endif
291
292// oneTBB
293// Use _has_include to detect oneTBB version if available, there is no predefined macro like OpenMP _OPENMP
294// When the header is available we define ALPAKA_TBB to the real version, otherwise it drops back to
295// ALPAKA_VERSION_NUMBER_NOT_AVAILABLE.
296#if !defined(ALPAKA_TBB)
297# // Does not provide a macro we can check therefore we need to load the headers first to set ALPAKA_TBB
298# if defined(__has_include)
299# // alpaka assumes if the TBB headers can be found, TBB can be activated for usage.
300# // If CMake is not used e.g. in compiler explorers or other build engines, the macro ALPAKA_DISABLE_TBB
301# // must be set if the TBB headers are available but linker flags for TBB are not passed.
302# // This can be the reason together if icpx is used since oneAPI is mostly shipping TBB directly.
303# if __has_include(<oneapi/tbb/version.h>) && !defined(ALPAKA_DISABLE_TBB)
304# include <oneapi/tbb/version.h>
305# endif
306# endif
307# // TBB headers define TBB_VERSION_* when present; otherwise we fall back to NOT_AVAILABLE.
308# if defined(TBB_VERSION_MAJOR)
309# if defined(TBB_VERSION_PATCH)
310# define ALPAKA_TBB ALPAKA_VERSION_NUMBER(TBB_VERSION_MAJOR, TBB_VERSION_MINOR, TBB_VERSION_PATCH)
311# else
312# define ALPAKA_TBB ALPAKA_VERSION_NUMBER(TBB_VERSION_MAJOR, TBB_VERSION_MINOR, 0)
313# endif
314# else
315# define ALPAKA_TBB ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
316# endif
317#endif