forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport: add and use preprocessors macros for loop unrolling (cms-sw…
…#32499) (#596) Define preprocessor macros that exoand to pragmas controlling loop unrolling. Two set of macrso are defined: - CMS_UNROLL_LOOP and friends are applied on both host and device compilation - CMS_DEVICE_UNROLL_LOOP and friends is only applied in device compilation, and expands to nothing on the host The supported compilers are - CUDA nvcc - HIP (untested) - gcc - clang Use CMS_UNROLL_LOOP instead of #pragma unroll .
- Loading branch information
Showing
5 changed files
with
107 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef FWCore_Utilities_interface_CMSUnrollLoop_h | ||
#define FWCore_Utilities_interface_CMSUnrollLoop_h | ||
|
||
// convert the macro argument to a null-terminated quoted string | ||
#define STRINGIFY_(ARG) #ARG | ||
#define STRINGIFY(ARG) STRINGIFY_(ARG) | ||
|
||
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) | ||
// CUDA or HIP device compiler | ||
|
||
#define CMS_UNROLL_LOOP _Pragma(STRINGIFY(unroll)) | ||
#define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(unroll N)) | ||
#define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(unroll 1)) | ||
|
||
#define CMS_DEVICE_UNROLL_LOOP _Pragma(STRINGIFY(unroll)) | ||
#define CMS_DEVICE_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(unroll N)) | ||
#define CMS_DEVICE_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(unroll 1)) | ||
|
||
#else // defined (__CUDA_ARCH__) || defined (__HIP_DEVICE_COMPILE__) | ||
|
||
// any host compiler | ||
#define CMS_DEVICE_UNROLL_LOOP | ||
#define CMS_DEVICE_UNROLL_LOOP_COUNT(N) | ||
#define CMS_DEVICE_UNROLL_LOOP_DISABLE | ||
|
||
#if defined(__clang__) | ||
// clang host compiler | ||
|
||
#define CMS_UNROLL_LOOP _Pragma(STRINGIFY(clang loop unroll(enable))) | ||
#define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(clang loop unroll_count(N))) | ||
#define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(clang loop unroll(disable))) | ||
|
||
#elif defined(__GNUC__) | ||
// GCC host compiler | ||
|
||
#define CMS_UNROLL_LOOP _Pragma(STRINGIFY(GCC ivdep)) | ||
#define CMS_UNROLL_LOOP_COUNT(N) _Pragma(STRINGIFY(GCC unroll N)) _Pragma(STRINGIFY(GCC ivdep)) | ||
#define CMS_UNROLL_LOOP_DISABLE _Pragma(STRINGIFY(GCC unroll 1)) | ||
|
||
#else | ||
// unsupported or unknown compiler | ||
|
||
#define CMS_UNROLL_LOOP | ||
#define CMS_UNROLL_LOOP_COUNT(N) | ||
#define CMS_UNROLL_LOOP_DISABLE | ||
|
||
#endif // defined(__clang__) || defined(__GNUC__) || ... | ||
|
||
#endif // defined (__CUDA_ARCH__) || defined (__HIP_DEVICE_COMPILE__) | ||
|
||
#endif // FWCore_Utilities_interface_CMSUnrollLoop_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters