Kokkos Core Kernels Package  Version of the Day
Kokkos_Macros.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_MACROS_HPP
45 #define KOKKOS_MACROS_HPP
46 
47 //----------------------------------------------------------------------------
63 #ifndef KOKKOS_DONT_INCLUDE_CORE_CONFIG_H
64 #include <KokkosCore_config.h>
65 #endif
66 
67 //----------------------------------------------------------------------------
97 //----------------------------------------------------------------------------
98 
99 #if defined( KOKKOS_HAVE_CUDA ) && defined( __CUDACC__ )
100 
101 /* Compiling with a CUDA compiler.
102  *
103  * Include <cuda.h> to pick up the CUDA_VERSION macro defined as:
104  * CUDA_VERSION = ( MAJOR_VERSION * 1000 ) + ( MINOR_VERSION * 10 )
105  *
106  * When generating device code the __CUDA_ARCH__ macro is defined as:
107  * __CUDA_ARCH__ = ( MAJOR_CAPABILITY * 100 ) + ( MINOR_CAPABILITY * 10 )
108  */
109 
110 #include <cuda_runtime.h>
111 #include <cuda.h>
112 
113 #if ! defined( CUDA_VERSION )
114 #error "#include <cuda.h> did not define CUDA_VERSION"
115 #endif
116 
117 #if ( CUDA_VERSION < 6050 )
118 // CUDA supports (inofficially) C++11 in device code starting with
119 // version 6.5. This includes auto type and device code internal
120 // lambdas.
121 #error "Cuda version 6.5 or greater required"
122 #endif
123 
124 #if defined( __CUDA_ARCH__ ) && ( __CUDA_ARCH__ < 300 )
125 /* Compiling with CUDA compiler for device code. */
126 #error "Cuda device capability >= 3.0 is required"
127 #endif
128 
129 #ifdef KOKKOS_CUDA_USE_LAMBDA
130 #if ( CUDA_VERSION < 7000 )
131 // CUDA supports C++11 lambdas generated in host code to be given
132 // to the device starting with version 7.5. But the release candidate (7.5.6)
133 // still identifies as 7.0
134 #error "Cuda version 7.5 or greater required for host-to-device Lambda support"
135 #endif
136 #define KOKKOS_LAMBDA [=]__device__
137 #define KOKKOS_HAVE_CXX11_DISPATCH_LAMBDA 1
138 #endif
139 #endif /* #if defined( KOKKOS_HAVE_CUDA ) && defined( __CUDACC__ ) */
140 
141 /*--------------------------------------------------------------------------*/
142 /* Language info: C++, CUDA, OPENMP */
143 
144 #if defined( __CUDA_ARCH__ ) && defined( KOKKOS_HAVE_CUDA )
145  // Compiling Cuda code to 'ptx'
146 
147  #define KOKKOS_FORCEINLINE_FUNCTION __device__ __host__ __forceinline__
148  #define KOKKOS_INLINE_FUNCTION __device__ __host__ inline
149  #define KOKKOS_FUNCTION __device__ __host__
150 
151 #endif /* #if defined( __CUDA_ARCH__ ) */
152 
153 #if defined( _OPENMP )
154 
155  /* Compiling with OpenMP.
156  * The value of _OPENMP is an integer value YYYYMM
157  * where YYYY and MM are the year and month designation
158  * of the supported OpenMP API version.
159  */
160 
161 #endif /* #if defined( _OPENMP ) */
162 
163 /*--------------------------------------------------------------------------*/
164 /* Mapping compiler built-ins to KOKKOS_COMPILER_*** macros */
165 
166 #if defined( __NVCC__ )
167  // NVIDIA compiler is being used.
168  // Code is parsed and separated into host and device code.
169  // Host code is compiled again with another compiler.
170  // Device code is compile to 'ptx'.
171  #define KOKKOS_COMPILER_NVCC __NVCC__
172 
173 #else
174 #if defined( KOKKOS_HAVE_CXX11 ) && ! defined( KOKKOS_HAVE_CXX11_DISPATCH_LAMBDA )
175  // CUDA (including version 6.5) does not support giving lambdas as
176  // arguments to global functions. Thus its not currently possible
177  // to dispatch lambdas from the host.
178  #define KOKKOS_HAVE_CXX11_DISPATCH_LAMBDA 1
179  #endif
180 #endif /* #if defined( __NVCC__ ) */
181 
182 #if defined( KOKKOS_HAVE_CXX11 ) && !defined (KOKKOS_LAMBDA)
183  #define KOKKOS_LAMBDA [=]
184 #endif
185 
186 #if ! defined( __CUDA_ARCH__ ) /* Not compiling Cuda code to 'ptx'. */
187 
188 /* Intel compiler for host code */
189 
190 #if defined( __INTEL_COMPILER )
191  #define KOKKOS_COMPILER_INTEL __INTEL_COMPILER
192 #elif defined( __ICC )
193  // Old define
194  #define KOKKOS_COMPILER_INTEL __ICC
195 #elif defined( __ECC )
196  // Very old define
197  #define KOKKOS_COMPILER_INTEL __ECC
198 #endif
199 
200 /* CRAY compiler for host code */
201 #if defined( _CRAYC )
202  #define KOKKOS_COMPILER_CRAYC _CRAYC
203 #endif
204 
205 #if defined( __IBMCPP__ )
206  // IBM C++
207  #define KOKKOS_COMPILER_IBM __IBMCPP__
208 #elif defined( __IBMC__ )
209  #define KOKKOS_COMPILER_IBM __IBMC__
210 #endif
211 
212 #if defined( __APPLE_CC__ )
213  #define KOKKOS_COMPILER_APPLECC __APPLE_CC__
214 #endif
215 
216 #if defined (__clang__) && !defined (KOKKOS_COMPILER_INTEL)
217  #define KOKKOS_COMPILER_CLANG __clang_major__*100+__clang_minor__*10+__clang_patchlevel__
218 #endif
219 
220 #if ! defined( __clang__ ) && ! defined( KOKKOS_COMPILER_INTEL ) &&defined( __GNUC__ )
221  #define KOKKOS_COMPILER_GNU __GNUC__*100+__GNUC_MINOR__*10+__GNUC_PATCHLEVEL__
222  #if ( 472 > KOKKOS_COMPILER_GNU )
223  #error "Compiling with GCC version earlier than 4.7.2 is not supported."
224  #endif
225 #endif
226 
227 #if defined( __PGIC__ ) && ! defined( __GNUC__ )
228  #define KOKKOS_COMPILER_PGI __PGIC__*100+__PGIC_MINOR__*10+__PGIC_PATCHLEVEL__
229  #if ( 1540 > KOKKOS_COMPILER_PGI )
230  #error "Compiling with PGI version earlier than 15.4 is not supported."
231  #endif
232 #endif
233 
234 #endif /* #if ! defined( __CUDA_ARCH__ ) */
235 
236 /*--------------------------------------------------------------------------*/
237 /*--------------------------------------------------------------------------*/
238 /* Intel compiler macros */
239 
240 #if defined( KOKKOS_COMPILER_INTEL )
241 
242  #define KOKKOS_HAVE_PRAGMA_UNROLL 1
243  #define KOKKOS_HAVE_PRAGMA_IVDEP 1
244  #define KOKKOS_HAVE_PRAGMA_LOOPCOUNT 1
245  #define KOKKOS_HAVE_PRAGMA_VECTOR 1
246  #define KOKKOS_HAVE_PRAGMA_SIMD 1
247 
248  #if ( 1400 > KOKKOS_COMPILER_INTEL )
249  #if ( 1300 > KOKKOS_COMPILER_INTEL )
250  #error "Compiling with Intel version earlier than 13.0 is not supported. Official minimal version is 14.0."
251  #else
252  #warning "Compiling with Intel version 13.x probably works but is not officially supported. Official minimal version is 14.0."
253  #endif
254  #endif
255  #if ( 1200 <= KOKKOS_COMPILER_INTEL ) && ! defined( KOKKOS_ENABLE_ASM ) && ! defined( _WIN32 )
256  #define KOKKOS_ENABLE_ASM 1
257  #endif
258 
259  #if ( 1200 <= KOKKOS_COMPILER_INTEL ) && ! defined( KOKKOS_FORCEINLINE_FUNCTION )
260  #if !defined (_WIN32)
261  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
262  #else
263  #define KOKKOS_FORCEINLINE_FUNCTION inline
264  #endif
265  #endif
266 
267  #if defined( __MIC__ )
268  // Compiling for Xeon Phi
269  #endif
270 
271 #endif
272 
273 /*--------------------------------------------------------------------------*/
274 /* Cray compiler macros */
275 
276 #if defined( KOKKOS_COMPILER_CRAYC )
277 
278 
279 #endif
280 
281 /*--------------------------------------------------------------------------*/
282 /* IBM Compiler macros */
283 
284 #if defined( KOKKOS_COMPILER_IBM )
285 
286  #define KOKKOS_HAVE_PRAGMA_UNROLL 1
287  //#define KOKKOS_HAVE_PRAGMA_IVDEP 1
288  //#define KOKKOS_HAVE_PRAGMA_LOOPCOUNT 1
289  //#define KOKKOS_HAVE_PRAGMA_VECTOR 1
290  //#define KOKKOS_HAVE_PRAGMA_SIMD 1
291 
292 #endif
293 
294 /*--------------------------------------------------------------------------*/
295 /* CLANG compiler macros */
296 
297 #if defined( KOKKOS_COMPILER_CLANG )
298 
299  //#define KOKKOS_HAVE_PRAGMA_UNROLL 1
300  //#define KOKKOS_HAVE_PRAGMA_IVDEP 1
301  //#define KOKKOS_HAVE_PRAGMA_LOOPCOUNT 1
302  //#define KOKKOS_HAVE_PRAGMA_VECTOR 1
303  //#define KOKKOS_HAVE_PRAGMA_SIMD 1
304 
305  #if ! defined( KOKKOS_FORCEINLINE_FUNCTION )
306  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
307  #endif
308 
309 #endif
310 
311 /*--------------------------------------------------------------------------*/
312 /* GNU Compiler macros */
313 
314 #if defined( KOKKOS_COMPILER_GNU )
315 
316  //#define KOKKOS_HAVE_PRAGMA_UNROLL 1
317  //#define KOKKOS_HAVE_PRAGMA_IVDEP 1
318  //#define KOKKOS_HAVE_PRAGMA_LOOPCOUNT 1
319  //#define KOKKOS_HAVE_PRAGMA_VECTOR 1
320  //#define KOKKOS_HAVE_PRAGMA_SIMD 1
321 
322  #if ! defined( KOKKOS_FORCEINLINE_FUNCTION )
323  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
324  #endif
325 
326  #if ! defined( KOKKOS_ENABLE_ASM ) && \
327  ! ( defined( __powerpc) || \
328  defined(__powerpc__) || \
329  defined(__powerpc64__) || \
330  defined(__POWERPC__) || \
331  defined(__ppc__) || \
332  defined(__ppc64__) || \
333  defined(__PGIC__) )
334  #define KOKKOS_ENABLE_ASM 1
335  #endif
336 
337 #endif
338 
339 /*--------------------------------------------------------------------------*/
340 
341 #if defined( KOKKOS_COMPILER_PGI )
342 
343  #define KOKKOS_HAVE_PRAGMA_UNROLL 1
344  #define KOKKOS_HAVE_PRAGMA_IVDEP 1
345  //#define KOKKOS_HAVE_PRAGMA_LOOPCOUNT 1
346  #define KOKKOS_HAVE_PRAGMA_VECTOR 1
347  //#define KOKKOS_HAVE_PRAGMA_SIMD 1
348 
349 #endif
350 
351 /*--------------------------------------------------------------------------*/
352 
353 #if defined( KOKKOS_COMPILER_NVCC )
354 
355  #if defined(__CUDA_ARCH__ )
356  #define KOKKOS_HAVE_PRAGMA_UNROLL 1
357  #endif
358 
359 #endif
360 
361 //----------------------------------------------------------------------------
364 #if ! defined( KOKKOS_FORCEINLINE_FUNCTION )
365 #define KOKKOS_FORCEINLINE_FUNCTION inline
366 #endif
367 
368 #if ! defined( KOKKOS_INLINE_FUNCTION )
369 #define KOKKOS_INLINE_FUNCTION inline
370 #endif
371 
372 #if ! defined( KOKKOS_FUNCTION )
373 #define KOKKOS_FUNCTION
374 #endif
375 
376 //----------------------------------------------------------------------------
381 #if 1 < ( ( defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_CUDA ) ? 1 : 0 ) + \
382  ( defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP ) ? 1 : 0 ) + \
383  ( defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS ) ? 1 : 0 ) + \
384  ( defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL ) ? 1 : 0 ) )
385 
386 #error "More than one KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_* specified" ;
387 
388 #endif
389 
393 #if defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_CUDA )
394 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP )
395 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS )
396 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL )
397 #elif defined ( KOKKOS_HAVE_CUDA )
398 #define KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_CUDA
399 #elif defined ( KOKKOS_HAVE_OPENMP )
400 #define KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP
401 #elif defined ( KOKKOS_HAVE_PTHREAD )
402 #define KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS
403 #else
404 #define KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL
405 #endif
406 
407 //----------------------------------------------------------------------------
410 #if defined( __CUDACC__ ) && defined( __CUDA_ARCH__ ) && defined (KOKKOS_HAVE_CUDA)
411 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA
412 #else
413 #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
414 #endif
415 
416 //----------------------------------------------------------------------------
417 //----------------------------------------------------------------------------
418 
419 #if ( defined( _POSIX_C_SOURCE ) && _POSIX_C_SOURCE >= 200112L ) || \
420  ( defined( _XOPEN_SOURCE ) && _XOPEN_SOURCE >= 600 )
421 #if defined(KOKKOS_ENABLE_PERFORMANCE_POSIX_MEMALIGN)
422 #define KOKKOS_POSIX_MEMALIGN_AVAILABLE 1
423 #endif
424 #endif
425 #endif /* #ifndef KOKKOS_MACROS_HPP */
426