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
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
8#ifdef __INTEL_COMPILER
9# warning \
10 "The Intel Classic compiler (icpc) is no longer supported. Please upgrade to the Intel LLVM compiler (ipcx)."
11#endif
12
13#define ALPAKA_VERSION_NUMBER(major, minor, patch) \
14 ((((major) % 1000llu) * 100'000'000llu) + (((minor) % 1000llu) * 100000llu) + ((patch) % 100000llu))
15
16#define ALPAKA_VERSION_NUMBER_NOT_AVAILABLE ALPAKA_VERSION_NUMBER(0llu, 0llu, 0llu)
17
18#define ALPAKA_YYYYMMDD_TO_VERSION(V) ALPAKA_VERSION_NUMBER(((V) / 10000llu), ((V) / 100llu) % 100llu, (V) % 100llu)
19
20#define ALPAKA_YYYYMM_TO_VERSION(V) ALPAKA_VERSION_NUMBER(((V) / 100llu) % 100llu, (V) % 100llu, 0llu)
21
22#define ALPAKA_VVRRP_10_TO_VERSION(V) \
23 ALPAKA_VERSION_NUMBER(((V) / 1000llu) % 100llu, ((V) / 10llu) % 100llu, (V) % 10llu)
24
25// ######## detect operating systems ########
26
27// WINDOWS
28#if !defined(ALPAKA_OS_WINDOWS)
29# if defined(__WIN32__) || defined(__MINGW32__) || defined(WIN32)
30# define ALPAKA_OS_WINDOWS 1
31# else
32# define ALPAKA_OS_WINDOWS 0
33# endif
34#endif
35
36
37// Linux
38#if !defined(ALPAKA_OS_LINUX)
39# if defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
40# define ALPAKA_OS_LINUX 1
41# else
42# define ALPAKA_OS_LINUX 0
43# endif
44#endif
45
46// Apple
47#if !defined(ALPAKA_OS_IOS)
48# if defined(__APPLE__)
49# define ALPAKA_OS_IOS 1
50# else
51# define ALPAKA_OS_IOS 0
52# endif
53#endif
54
55// Cygwin
56#if !defined(ALPAKA_OS_CYGWIN)
57# if defined(__CYGWIN__)
58# define ALPAKA_OS_CYGWIN 1
59# else
60# define ALPAKA_OS_CYGWIN 0
61# endif
62#endif
63
64// ### architectures
65
66// X86
67#if !defined(ALPAKA_ARCH_X86)
68# if defined(__x86_64__) || defined(_M_X64)
69# define ALPAKA_ARCH_X86 1
70# else
71# define ALPAKA_ARCH_X86 0
72# endif
73#endif
74
75// RISCV
76#if !defined(ALPAKA_ARCH_RISCV)
77# if defined(__riscv)
78# define ALPAKA_ARCH_RISCV 1
79# else
80# define ALPAKA_ARCH_RISCV 0
81# endif
82#endif
83
84// ARM
85#if !defined(ALPAKA_ARCH_ARM)
86# if defined(__ARM_ARCH) || defined(__arm__) || defined(__arm64)
87# define ALPAKA_ARCH_ARM 1
88# else
89# define ALPAKA_ARCH_ARM 0
90# endif
91#endif
92
93// NVIDIA device compile
94#if !defined(ALPAKA_ARCH_PTX)
95# if defined(__CUDA_ARCH__)
96# define ALPAKA_ARCH_PTX 1
97# else
98# define ALPAKA_ARCH_PTX 0
99# endif
100#endif
101
102// HIP device compile
103#if !defined(ALPAKA_ARCH_HSA)
104# if defined(__HIP__) && defined(__HIP_DEVICE_COMPILE__) && __HIP_DEVICE_COMPILE__ == 1
105# define ALPAKA_ARCH_HSA 1
106# else
107# define ALPAKA_ARCH_HSA 0
108# endif
109#endif
110
111// ######## compiler ########
112
113// HIP compiler detection
114#if !defined(ALPAKA_COMP_HIP)
115# if defined(__HIP__) // Defined by hip-clang and vanilla clang in HIP mode.
116# include <hip/hip_version.h>
117// HIP doesn't give us a patch level for the last entry, just a gitdate
118# define ALPAKA_COMP_HIP ALPAKA_VERSION_NUMBER(HIP_VERSION_MAJOR, HIP_VERSION_MINOR, 0)
119# else
120# define ALPAKA_COMP_HIP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
121# endif
122#endif
123
124// nvcc compiler
125#if defined(__NVCC__)
126# define ALPAKA_COMP_NVCC ALPAKA_VERSION_NUMBER(__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, __CUDACC_VER_BUILD__)
127#else
128# define ALPAKA_COMP_NVCC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
129#endif
130
131// clang compiler
132#if defined(__clang__)
133# define ALPAKA_COMP_CLANG ALPAKA_VERSION_NUMBER(__clang_major__, __clang_minor__, __clang_patchlevel__)
134#else
135# define ALPAKA_COMP_CLANG ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
136#endif
137
138// MSVC compiler
139#if defined(_MSC_VER)
140# define ALPAKA_COMP_MSVC \
141 ALPAKA_VERSION_NUMBER((_MSC_FULL_VER) % 10'000'000, ((_MSC_FULL_VER) / 100000) % 100, (_MSC_FULL_VER) % 100000)
142#else
143# define ALPAKA_COMP_MSVC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
144#endif
145
146// gnu compiler (excluding compilers which emulates gnu compiler like clang)
147#if defined(__GNUC__) && !defined(__clang__)
148# if defined(__GNUC_PATCHLEVEL__)
149# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
150# else
151# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER(__GNUC__, __GNUC_MINOR__, 0)
152# endif
153#else
154# define ALPAKA_COMP_GNUC ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
155#endif
156
157// IBM compiler
158// only clang based is supported
159#if defined(__ibmxl__)
160# define ALPAKA_COMP_IBM ALPAKA_VERSION_NUMBER(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
161#else
162# define ALPAKA_COMP_IBM ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
163#endif
164
165// clang CUDA compiler detection
166// Currently __CUDA__ is only defined by clang when compiling CUDA code.
167#if defined(__clang__) && defined(__CUDA__)
168# define ALPAKA_COMP_CLANG_CUDA ALPAKA_VERSION_NUMBER(__clang_major__, __clang_minor__, __clang_patchlevel__)
169#else
170# define ALPAKA_COMP_CLANG_CUDA ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
171#endif
172
173// PGI and NV HPC SDK compiler detection
174#if defined(__PGI)
175# define ALPAKA_COMP_PGI ALPAKA_VERSION_NUMBER(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
176#else
177# define ALPAKA_COMP_PGI ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
178#endif
179
180// Intel LLVM compiler detection
181#if !defined(ALPAKA_COMP_ICPX)
182# if defined(SYCL_LANGUAGE_VERSION) && defined(__INTEL_LLVM_COMPILER)
183// The version string for icpx 2023.1.0 is 20230100. In Boost.Predef this becomes (53,1,0).
184# define ALPAKA_COMP_ICPX ALPAKA_YYYYMMDD_TO_VERSION(__INTEL_LLVM_COMPILER)
185# else
186# define ALPAKA_COMP_ICPX ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
187# endif
188#endif
189
190// ######## C++ language ########
191
192//---------------------------------------HIP-----------------------------------
193// __HIP__ is defined by both hip-clang and vanilla clang in HIP mode.
194// https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_porting_guide.md#compiler-defines-summary
195#if !defined(ALPAKA_LANG_HIP)
196# if defined(__HIP__)
197# include <hip/hip_version.h>
198// HIP doesn't give us a patch level for the last entry, just a gitdate
199# define ALPAKA_LANG_HIP ALPAKA_VERSION_NUMBER(HIP_VERSION_MAJOR, HIP_VERSION_MINOR, 0)
200# else
201# define ALPAKA_LANG_HIP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
202# endif
203#endif
204
205// CUDA
206#if !defined(ALPAKA_LANG_CUDA)
207# if defined(__CUDACC__) || defined(__CUDA__)
208# include <cuda.h>
209// CUDA doesn't give us a patch level for the last entry, just zero.
210# define ALPAKA_LANG_CUDA ALPAKA_VVRRP_10_TO_VERSION(CUDART_VERSION)
211# else
212# define ALPAKA_LANG_CUDA ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
213# endif
214#endif
215
216// Intel OneAPI Sycl GPU
217#if !defined(ALPAKA_LANG_SYCL)
218# if defined(SYCL_LANGUAGE_VERSION)
219# define ALPAKA_LANG_SYCL ALPAKA_YYYYMMDD_TO_VERSION(SYCL_LANGUAGE_VERSION)
220# else
221# define ALPAKA_LANG_SYCL ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
222# endif
223# if(ALPAKA_COMP_ICPX)
224// ONE API must be detected via the ICPX compiler see
225// 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
226# define ALPAKA_LANG_ONEAPI ALPAKA_COMP_ICPX
227# endif
228#endif
229
230// OpenMP
231#if !defined(ALPAKA_OMP)
232# if defined(_OPENMP)
233# include <omp.h>
234# endif
235# if defined(_OPENMP)
236# define ALPAKA_OMP ALPAKA_YYYYMM_TO_VERSION(_OPENMP)
237# else
238# define ALPAKA_OMP ALPAKA_VERSION_NUMBER_NOT_AVAILABLE
239# endif
240#endif