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