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 //----------------------------------------------------------------------------
61 #ifndef KOKKOS_DONT_INCLUDE_CORE_CONFIG_H
62  #include <KokkosCore_config.h>
63 #endif
64 
65 #include <impl/Kokkos_OldMacros.hpp>
66 
67 //----------------------------------------------------------------------------
97 //----------------------------------------------------------------------------
98 
99 #if defined( KOKKOS_ENABLE_CUDA ) && defined( __CUDACC__ )
100  // Compiling with a CUDA compiler.
101  //
102  // Include <cuda.h> to pick up the CUDA_VERSION macro defined as:
103  // CUDA_VERSION = ( MAJOR_VERSION * 1000 ) + ( MINOR_VERSION * 10 )
104  //
105  // When generating device code the __CUDA_ARCH__ macro is defined as:
106  // __CUDA_ARCH__ = ( MAJOR_CAPABILITY * 100 ) + ( MINOR_CAPABILITY * 10 )
107 
108  #include <cuda_runtime.h>
109  #include <cuda.h>
110 
111  #if !defined( CUDA_VERSION )
112  #error "#include <cuda.h> did not define CUDA_VERSION."
113  #endif
114 
115  #if ( CUDA_VERSION < 7000 )
116  // CUDA supports C++11 in device code starting with version 7.0.
117  // This includes auto type and device code internal lambdas.
118  #error "Cuda version 7.0 or greater required."
119  #endif
120 
121  #if defined( __CUDA_ARCH__ ) && ( __CUDA_ARCH__ < 300 )
122  // Compiling with CUDA compiler for device code.
123  #error "Cuda device capability >= 3.0 is required."
124  #endif
125 
126  #ifdef KOKKOS_ENABLE_CUDA_LAMBDA
127  #if ( CUDA_VERSION < 7050 )
128  // CUDA supports C++11 lambdas generated in host code to be given
129  // to the device starting with version 7.5. But the release candidate (7.5.6)
130  // still identifies as 7.0.
131  #error "Cuda version 7.5 or greater required for host-to-device Lambda support."
132  #endif
133 
134  #if ( CUDA_VERSION < 8000 ) && defined( __NVCC__ )
135  #define KOKKOS_LAMBDA [=]__device__
136  #else
137  #define KOKKOS_LAMBDA [=]__host__ __device__
138 
139  #if defined( KOKKOS_ENABLE_CXX1Z )
140  #define KOKKOS_CLASS_LAMBDA [=,*this] __host__ __device__
141  #endif
142  #endif
143 
144  #define KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA 1
145  #endif
146 #endif // #if defined( KOKKOS_ENABLE_CUDA ) && defined( __CUDACC__ )
147 
148 #if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
149  // Cuda version 8.0 still needs the functor wrapper
150  #if /* ( CUDA_VERSION < 8000 ) && */ defined( __NVCC__ )
151  #define KOKKOS_IMPL_NEED_FUNCTOR_WRAPPER
152  #endif
153 #endif
154 
155 //----------------------------------------------------------------------------
156 // Language info: C++, CUDA, OPENMP
157 
158 #if defined( KOKKOS_ENABLE_CUDA )
159  // Compiling Cuda code to 'ptx'
160 
161  #define KOKKOS_FORCEINLINE_FUNCTION __device__ __host__ __forceinline__
162  #define KOKKOS_INLINE_FUNCTION __device__ __host__ inline
163  #define KOKKOS_FUNCTION __device__ __host__
164 #endif // #if defined( __CUDA_ARCH__ )
165 
166 #if defined( _OPENMP )
167  // Compiling with OpenMP.
168  // The value of _OPENMP is an integer value YYYYMM
169  // where YYYY and MM are the year and month designation
170  // of the supported OpenMP API version.
171 #endif // #if defined( _OPENMP )
172 
173 //----------------------------------------------------------------------------
174 // Mapping compiler built-ins to KOKKOS_COMPILER_*** macros
175 
176 #if defined( __NVCC__ )
177  // NVIDIA compiler is being used.
178  // Code is parsed and separated into host and device code.
179  // Host code is compiled again with another compiler.
180  // Device code is compile to 'ptx'.
181  #define KOKKOS_COMPILER_NVCC __NVCC__
182 #else
183  #if !defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
184  #if !defined( KOKKOS_ENABLE_CUDA ) // Compiling with clang for Cuda does not work with LAMBDAs either
185  // CUDA (including version 6.5) does not support giving lambdas as
186  // arguments to global functions. Thus its not currently possible
187  // to dispatch lambdas from the host.
188  #define KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA 1
189  #endif
190  #endif
191 #endif // #if defined( __NVCC__ )
192 
193 #if !defined( KOKKOS_LAMBDA )
194  #define KOKKOS_LAMBDA [=]
195 #endif
196 
197 #if defined( KOKKOS_ENABLE_CXX1Z ) && !defined( KOKKOS_CLASS_LAMBDA )
198  #define KOKKOS_CLASS_LAMBDA [=,*this]
199 #endif
200 
201 //#if !defined( __CUDA_ARCH__ ) // Not compiling Cuda code to 'ptx'.
202 
203 // Intel compiler for host code.
204 
205 #if defined( __INTEL_COMPILER )
206  #define KOKKOS_COMPILER_INTEL __INTEL_COMPILER
207 #elif defined( __ICC )
208  // Old define
209  #define KOKKOS_COMPILER_INTEL __ICC
210 #elif defined( __ECC )
211  // Very old define
212  #define KOKKOS_COMPILER_INTEL __ECC
213 #endif
214 
215 // CRAY compiler for host code
216 #if defined( _CRAYC )
217  #define KOKKOS_COMPILER_CRAYC _CRAYC
218 #endif
219 
220 #if defined( __IBMCPP__ )
221  // IBM C++
222  #define KOKKOS_COMPILER_IBM __IBMCPP__
223 #elif defined( __IBMC__ )
224  #define KOKKOS_COMPILER_IBM __IBMC__
225 #endif
226 
227 #if defined( __APPLE_CC__ )
228  #define KOKKOS_COMPILER_APPLECC __APPLE_CC__
229 #endif
230 
231 #if defined( __clang__ ) && !defined( KOKKOS_COMPILER_INTEL )
232  #define KOKKOS_COMPILER_CLANG __clang_major__*100+__clang_minor__*10+__clang_patchlevel__
233 #endif
234 
235 #if !defined( __clang__ ) && !defined( KOKKOS_COMPILER_INTEL ) &&defined( __GNUC__ )
236  #define KOKKOS_COMPILER_GNU __GNUC__*100+__GNUC_MINOR__*10+__GNUC_PATCHLEVEL__
237 
238  #if ( 472 > KOKKOS_COMPILER_GNU )
239  #error "Compiling with GCC version earlier than 4.7.2 is not supported."
240  #endif
241 #endif
242 
243 #if defined( __PGIC__ ) && !defined( __GNUC__ )
244  #define KOKKOS_COMPILER_PGI __PGIC__*100+__PGIC_MINOR__*10+__PGIC_PATCHLEVEL__
245 
246  #if ( 1540 > KOKKOS_COMPILER_PGI )
247  #error "Compiling with PGI version earlier than 15.4 is not supported."
248  #endif
249 #endif
250 
251 //#endif // #if !defined( __CUDA_ARCH__ )
252 
253 //----------------------------------------------------------------------------
254 // Intel compiler macros
255 
256 #if defined( KOKKOS_COMPILER_INTEL )
257  #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
258  #define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
259  #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
260  #define KOKKOS_ENABLE_PRAGMA_SIMD 1
261 
262  #if ( __INTEL_COMPILER > 1400 )
263  #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
264  #endif
265 
266  #define KOKKOS_RESTRICT __restrict__
267 
268  #ifndef KOKKOS_ALIGN
269  #define KOKKOS_ALIGN(size) __attribute__((aligned(size)))
270  #endif
271 
272  #ifndef KOKKOS_ALIGN_PTR
273  #define KOKKOS_ALIGN_PTR(size) __attribute__((align_value(size)))
274  #endif
275 
276  #ifndef KOKKOS_ALIGN_SIZE
277  #define KOKKOS_ALIGN_SIZE 64
278  #endif
279 
280  #if ( 1400 > KOKKOS_COMPILER_INTEL )
281  #if ( 1300 > KOKKOS_COMPILER_INTEL )
282  #error "Compiling with Intel version earlier than 13.0 is not supported. Official minimal version is 14.0."
283  #else
284  #warning "Compiling with Intel version 13.x probably works but is not officially supported. Official minimal version is 14.0."
285  #endif
286  #endif
287 
288  #if !defined( KOKKOS_ENABLE_ASM ) && !defined( _WIN32 )
289  #define KOKKOS_ENABLE_ASM 1
290  #endif
291 
292  #if !defined( KOKKOS_FORCEINLINE_FUNCTION )
293  #if !defined( _WIN32 )
294  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
295  #else
296  #define KOKKOS_FORCEINLINE_FUNCTION inline
297  #endif
298  #endif
299 
300  #if defined( __MIC__ )
301  // Compiling for Xeon Phi
302  #endif
303 #endif
304 
305 //----------------------------------------------------------------------------
306 // Cray compiler macros
307 
308 #if defined( KOKKOS_COMPILER_CRAYC )
309 #endif
310 
311 //----------------------------------------------------------------------------
312 // IBM Compiler macros
313 
314 #if defined( KOKKOS_COMPILER_IBM )
315  #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
316  //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
317  //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
318  //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
319  //#define KOKKOS_ENABLE_PRAGMA_SIMD 1
320 #endif
321 
322 //----------------------------------------------------------------------------
323 // CLANG compiler macros
324 
325 #if defined( KOKKOS_COMPILER_CLANG )
326  //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
327  //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
328  //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
329  //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
330  //#define KOKKOS_ENABLE_PRAGMA_SIMD 1
331 
332  #if !defined( KOKKOS_FORCEINLINE_FUNCTION )
333  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
334  #endif
335 #endif
336 
337 //----------------------------------------------------------------------------
338 // GNU Compiler macros
339 
340 #if defined( KOKKOS_COMPILER_GNU )
341  //#define KOKKOS_ENABLE_PRAGMA_UNROLL 1
342  //#define KOKKOS_ENABLE_PRAGMA_IVDEP 1
343  //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
344  //#define KOKKOS_ENABLE_PRAGMA_VECTOR 1
345  //#define KOKKOS_ENABLE_PRAGMA_SIMD 1
346 
347  #if !defined( KOKKOS_FORCEINLINE_FUNCTION )
348  #define KOKKOS_FORCEINLINE_FUNCTION inline __attribute__((always_inline))
349  #endif
350 
351  #if !defined( KOKKOS_ENABLE_ASM ) && !defined( __PGIC__ ) && \
352  ( defined( __amd64 ) || defined( __amd64__ ) || \
353  defined( __x86_64 ) || defined( __x86_64__ ) )
354  #define KOKKOS_ENABLE_ASM 1
355  #endif
356 #endif
357 
358 //----------------------------------------------------------------------------
359 
360 #if defined( KOKKOS_COMPILER_PGI )
361  #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
362  #define KOKKOS_ENABLE_PRAGMA_IVDEP 1
363  //#define KOKKOS_ENABLE_PRAGMA_LOOPCOUNT 1
364  #define KOKKOS_ENABLE_PRAGMA_VECTOR 1
365  //#define KOKKOS_ENABLE_PRAGMA_SIMD 1
366 #endif
367 
368 //----------------------------------------------------------------------------
369 
370 #if defined( KOKKOS_COMPILER_NVCC )
371  #if defined( __CUDA_ARCH__ )
372  #define KOKKOS_ENABLE_PRAGMA_UNROLL 1
373  #endif
374 #endif
375 
376 //----------------------------------------------------------------------------
377 // Define function marking macros if compiler specific macros are undefined:
378 
379 #if !defined( KOKKOS_FORCEINLINE_FUNCTION )
380  #define KOKKOS_FORCEINLINE_FUNCTION inline
381 #endif
382 
383 #if !defined( KOKKOS_INLINE_FUNCTION )
384  #define KOKKOS_INLINE_FUNCTION inline
385 #endif
386 
387 #if !defined( KOKKOS_FUNCTION )
388  #define KOKKOS_FUNCTION
389 #endif
390 
391 //----------------------------------------------------------------------------
392 // Define empty macro for restrict if necessary:
393 
394 #if !defined( KOKKOS_RESTRICT )
395  #define KOKKOS_RESTRICT
396 #endif
397 
398 //----------------------------------------------------------------------------
399 // Define Macro for alignment:
400 
401 #if !defined KOKKOS_ALIGN_SIZE
402  #define KOKKOS_ALIGN_SIZE 16
403 #endif
404 
405 #if !defined( KOKKOS_ALIGN )
406  #define KOKKOS_ALIGN(size) __attribute__((aligned(size)))
407 #endif
408 
409 #if !defined( KOKKOS_ALIGN_PTR )
410  #define KOKKOS_ALIGN_PTR(size) __attribute__((aligned(size)))
411 #endif
412 
413 //----------------------------------------------------------------------------
414 // Determine the default execution space for parallel dispatch.
415 // There is zero or one default execution space specified.
416 
417 #if 1 < ( ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA ) ? 1 : 0 ) + \
418  ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET ) ? 1 : 0 ) + \
419  ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP ) ? 1 : 0 ) + \
420  ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS ) ? 1 : 0 ) + \
421  ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS ) ? 1 : 0 ) + \
422  ( defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL ) ? 1 : 0 ) )
423  #error "More than one KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_* specified."
424 #endif
425 
426 // If default is not specified then chose from enabled execution spaces.
427 // Priority: CUDA, OPENMP, THREADS, QTHREADS, SERIAL
428 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA )
429 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET )
430 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
431 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
432 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
433 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
434 #elif defined( KOKKOS_ENABLE_CUDA )
435  #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA
436 #elif defined( KOKKOS_ENABLE_OPENMPTARGET )
437  #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET
438 #elif defined( KOKKOS_ENABLE_OPENMP )
439  #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP
440 #elif defined( KOKKOS_ENABLE_THREADS )
441  #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS
442 //#elif defined( KOKKOS_ENABLE_QTHREADS )
443 // #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS
444 #else
445  #define KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL
446 #endif
447 
448 //----------------------------------------------------------------------------
449 // Determine for what space the code is being compiled:
450 
451 #if defined( __CUDACC__ ) && defined( __CUDA_ARCH__ ) && defined( KOKKOS_ENABLE_CUDA )
452  #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA
453 #else
454  #define KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
455 #endif
456 
457 //----------------------------------------------------------------------------
458 
459 #if ( defined( _POSIX_C_SOURCE ) && _POSIX_C_SOURCE >= 200112L ) || \
460  ( defined( _XOPEN_SOURCE ) && _XOPEN_SOURCE >= 600 )
461  #if defined( KOKKOS_ENABLE_PERFORMANCE_POSIX_MEMALIGN )
462  #define KOKKOS_ENABLE_POSIX_MEMALIGN 1
463  #endif
464 #endif
465 
466 //----------------------------------------------------------------------------
467 // If compiling with CUDA then must be using CUDA 8 or better
468 // and use relocateable device code to enable the task policy.
469 // nvcc relocatable device code option: --relocatable-device-code=true
470 
471 #if ( defined( KOKKOS_ENABLE_CUDA ) )
472  #if ( 8000 <= CUDA_VERSION ) && defined( KOKKOS_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE )
473  #define KOKKOS_ENABLE_TASKDAG
474  #endif
475 #else
476  #define KOKKOS_ENABLE_TASKDAG
477 #endif
478 
479 #endif // #ifndef KOKKOS_MACROS_HPP
480