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