RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
macros.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_INTERNAL_MACROS_HPP
21 #define RAJA_INTERNAL_MACROS_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <cstdlib>
26 #include <stdexcept>
27 #include <stdio.h>
28 
29 #if defined(RAJA_HIP_ACTIVE)
30 #include <hip/hip_runtime.h>
31 #endif
32 
33 //
34 // Macros for decorating host/device functions for CUDA and HIP kernels.
35 // We need a better solution than this as it is a pain to manage
36 // this stuff in an application.
37 //
38 #if (defined(RAJA_ENABLE_CUDA) && defined(__CUDA_ARCH__)) || \
39  (defined(RAJA_ENABLE_HIP) && defined(__HIP_DEVICE_COMPILE__)) || \
40  (defined(RAJA_ENABLE_SYCL) && defined(__SYCL_DEVICE_ONLY__))
41 #define RAJA_GPU_DEVICE_COMPILE_PASS_ACTIVE
42 #endif
43 
44 #if defined(RAJA_ENABLE_CUDA) && defined(__CUDACC__)
45 #define RAJA_HOST_DEVICE __host__ __device__
46 #define RAJA_DEVICE __device__
47 #define RAJA_HOST __host__
48 
49 #if defined(RAJA_ENABLE_CLANG_CUDA)
50 #define RAJA_SUPPRESS_HD_WARN
51 #else
52 #define RAJA_SUPPRESS_HD_WARN RAJA_PRAGMA(nv_exec_check_disable)
53 #endif
54 
55 #elif defined(RAJA_ENABLE_HIP) && defined(__HIPCC__)
56 #define RAJA_HOST_DEVICE __host__ __device__
57 #define RAJA_DEVICE __device__
58 #define RAJA_HOST __host__
59 #define RAJA_SUPPRESS_HD_WARN
60 
61 #define RAJA_USE_HIP_INTRINSICS
62 
63 #else
64 
65 #define RAJA_HOST_DEVICE
66 #define RAJA_DEVICE
67 #define RAJA_HOST
68 #define RAJA_SUPPRESS_HD_WARN
69 #endif
70 
71 
72 #if defined(__has_builtin)
73 #define RAJA_INTERNAL_CLANG_HAS_BUILTIN(x) __has_builtin(x)
74 #else
75 #define RAJA_INTERNAL_CLANG_HAS_BUILTIN(x) 0
76 #endif
77 
97 #define RAJA_UNUSED_ARG(x)
98 
119 template<typename... T>
120 RAJA_HOST_DEVICE RAJA_INLINE void RAJA_UNUSED_VAR(T&&...) noexcept {}
121 
122 #define RAJA_DIVIDE_CEILING_INT(dividend, divisor) \
123  (((dividend) + (divisor) - 1) / (divisor))
124 
129 #if defined(RAJA_ENABLE_OPENMP)
130 #define RAJA_OMP_DECLARE_REDUCTION_COMBINE \
131  RAJA_UNUSED_VAR(EXEC_POL {}); \
132  _Pragma(" omp declare reduction( combine \
133  : typename std::remove_reference<decltype(f_params)>::type \
134  : RAJA::expt::ParamMultiplexer::parampack_combine(EXEC_POL{}, omp_out, omp_in) ) ") // initializer(omp_priv = omp_in) ")
135 
136 #define RAJA_OMP_DECLARE_TUPLE_REDUCTION_COMBINE \
137  _Pragma(" omp declare reduction( combine \
138  : typename std::remove_reference<decltype(reducers_tuple)>::type \
139  : RAJA::expt::detail::combine_params<EXEC_POL>(omp_out, omp_in) ) ")
140 #endif
141 
142 
143 RAJA_HOST_DEVICE inline void RAJA_ABORT_OR_THROW(const char* str)
144 {
145 #if defined(__SYCL_DEVICE_ONLY__)
146  RAJA_UNUSED_VAR(str);
147  // segfault here ran into linking problems
148  *((volatile char*)0) = 0; // write to address 0
149 #else
150  printf("%s\n", str);
151 #if defined(RAJA_ENABLE_TARGET_OPENMP) && (_OPENMP >= 201511)
152  // seg faulting here instead of calling std::abort for omp target
153  *((volatile char*)0) = 0; // write to address 0
154 #elif defined(__CUDA_ARCH__)
155  asm("trap;");
156 
157 #elif defined(__HIP_DEVICE_COMPILE__)
158  abort();
159 
160 #else
161 #ifdef RAJA_COMPILER_MSVC
162  fflush(stdout);
163  char* value;
164  size_t len;
165  bool no_except = false;
166  if (_dupenv_s(&value, &len, "RAJA_NO_EXCEPT") == 0 && value != nullptr)
167  {
168  no_except = true;
169  free(value);
170  }
171 
172 #else
173  bool no_except = std::getenv("RAJA_NO_EXCEPT") != nullptr;
174 #endif
175 
176  fflush(stdout);
177  if (no_except)
178  {
179  std::abort();
180  }
181  else
182  {
183  throw std::runtime_error(str);
184  }
185 #endif
186 #endif
187 }
188 
190 
199 #if (__cplusplus >= 201402L)
200 #define RAJA_HAS_CXX14 1
201 #define RAJA_HAS_CXX_ATTRIBUTE_DEPRECATED 1
202 #elif defined(__has_cpp_attribute)
203 #if __has_cpp_attribute(deprecated)
204 #define RAJA_HAS_CXX_ATTRIBUTE_DEPRECATED 1
205 #endif
206 #endif
207 
208 #if defined(RAJA_HAS_CXX_ATTRIBUTE_DEPRECATED)
209 // When using a C++14 compiler, use the standard-specified deprecated attribute
210 #define RAJA_DEPRECATE(Msg) [[deprecated(Msg)]]
211 #define RAJA_DEPRECATE_ALIAS(Msg) [[deprecated(Msg)]]
212 
213 #elif defined(_MSC_VER)
214 
215 // for MSVC, use __declspec
216 #define RAJA_DEPRECATE(Msg) __declspec(deprecated(Msg))
217 #define RAJA_DEPRECATE_ALIAS(Msg)
218 
219 #else
220 
221 // else use __attribute__(deprecated("Message"))
222 #define RAJA_DEPRECATE(Msg) __attribute__((deprecated(Msg)))
223 #define RAJA_DEPRECATE_ALIAS(Msg)
224 
225 #endif
226 
227 #endif /* RAJA_INTERNAL_MACROS_HPP */
RAJA_HOST_DEVICE RAJA_INLINE void RAJA_UNUSED_VAR(T &&...) noexcept
Definition: macros.hpp:120
RAJA_HOST_DEVICE void RAJA_ABORT_OR_THROW(const char *str)
Definition: macros.hpp:143
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65