CMS 3D CMS Logo

CMSUnrollLoop.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_interface_CMSUnrollLoop_h
2 #define FWCore_Utilities_interface_CMSUnrollLoop_h
3 
4 // convert the macro argument to a null-terminated quoted string
5 #define STRINGIFY_(ARG) #ARG
6 #define STRINGIFY(ARG) STRINGIFY_(ARG)
7 
8 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
9 // CUDA or HIP device compiler
10 
11 #define CMS_UNROLL_LOOP _Pragma(STRINGIFY(unroll))
12 #define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(unroll N))
13 #define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(unroll 1))
14 
15 #define CMS_DEVICE_UNROLL_LOOP _Pragma(STRINGIFY(unroll))
16 #define CMS_DEVICE_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(unroll N))
17 #define CMS_DEVICE_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(unroll 1))
18 
19 #else // defined (__CUDA_ARCH__) || defined (__HIP_DEVICE_COMPILE__)
20 
21 // any host compiler
22 #define CMS_DEVICE_UNROLL_LOOP
23 #define CMS_DEVICE_UNROLL_LOOP_COUNT(N)
24 #define CMS_DEVICE_UNROLL_LOOP_DISABLE
25 
26 #if defined(__clang__)
27 // clang host compiler
28 
29 #define CMS_UNROLL_LOOP _Pragma(STRINGIFY(clang loop unroll(enable)))
30 #define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(clang loop unroll_count(N)))
31 #define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(clang loop unroll(disable)))
32 
33 #elif defined(__GNUC__)
34 // GCC host compiler
35 
36 #define CMS_UNROLL_LOOP _Pragma(STRINGIFY(GCC ivdep))
37 #define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(GCC unroll N)) _Pragma(STRINGIFY(GCC ivdep))
38 #define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(GCC unroll 1))
39 
40 #else
41 // unsupported or unknown compiler
42 
43 #define CMS_UNROLL_LOOP
44 #define CMS_UNROLL_LOOP_COUNT(N)
45 #define CMS_UNROLL_LOOP_DISABLE
46 
47 #endif // defined(__clang__) || defined(__GNUC__) || ...
48 
49 #endif // defined (__CUDA_ARCH__) || defined (__HIP_DEVICE_COMPILE__)
50 
51 #endif // FWCore_Utilities_interface_CMSUnrollLoop_h