From 140cbd72c877249e1e03e2ea6e04204569d1694c Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sat, 8 Apr 2023 14:22:06 -0400 Subject: [PATCH] Define at most one KOKKOS_COMPILER* macro --- core/src/Kokkos_Macros.hpp | 45 +++++++++---------- ...pilerMacros.hpp => TestCompilerMacros.cpp} | 19 +++++--- 2 files changed, 34 insertions(+), 30 deletions(-) rename core/unit_test/{TestCompilerMacros.hpp => TestCompilerMacros.cpp} (75%) diff --git a/core/src/Kokkos_Macros.hpp b/core/src/Kokkos_Macros.hpp index 2c02ef8fd6..5a44391982 100644 --- a/core/src/Kokkos_Macros.hpp +++ b/core/src/Kokkos_Macros.hpp @@ -123,46 +123,41 @@ #if defined(__INTEL_COMPILER) #define KOKKOS_COMPILER_INTEL __INTEL_COMPILER + #elif defined(__INTEL_LLVM_COMPILER) #define KOKKOS_COMPILER_INTEL __INTEL_LLVM_COMPILER -#elif defined(__ICC) -// Old define -#define KOKKOS_COMPILER_INTEL __ICC -#elif defined(__ECC) -// Very old define -#define KOKKOS_COMPILER_INTEL __ECC -#endif +#elif defined(_CRAYC) // CRAY compiler for host code -#if defined(_CRAYC) #define KOKKOS_COMPILER_CRAYC _CRAYC -#endif -#if defined(__APPLE_CC__) +#elif defined(__APPLE_CC__) #define KOKKOS_COMPILER_APPLECC __APPLE_CC__ -#endif -#if defined(__clang__) && !defined(KOKKOS_COMPILER_INTEL) +#elif defined(__NVCOMPILER) +#define KOKKOS_COMPILER_NVHPC \ + __NVCOMPILER_MAJOR__ * 10000 + __NVCOMPILER_MINOR__ * 100 + \ + __NVCOMPILER_PATCHLEVEL__ + +#elif defined(__clang__) +// Check this after the Clang-based proprietary compilers which will also define +// __clang__ #define KOKKOS_COMPILER_CLANG \ __clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__ -#endif -#if !defined(__clang__) && !defined(KOKKOS_COMPILER_INTEL) && defined(__GNUC__) +#elif defined(__GNUC__) +// Check this here because many compilers (at least Clang variants and Intel +// classic) define `__GNUC__` for compatibility #define KOKKOS_COMPILER_GNU \ __GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ -#if (530 > KOKKOS_COMPILER_GNU) -#error "Compiling with GCC version earlier than 5.3.0 is not supported." -#endif -#endif - -#if defined(__NVCOMPILER) -#define KOKKOS_COMPILER_NVHPC \ - __NVCOMPILER_MAJOR__ * 10000 + __NVCOMPILER_MINOR__ * 100 + \ - __NVCOMPILER_PATCHLEVEL__ +#if (820 > KOKKOS_COMPILER_GNU) +#error "Compiling with GCC version earlier than 8.2.0 is not supported." #endif -#if defined(_MSC_VER) && !defined(KOKKOS_COMPILER_INTEL) +#elif defined(_MSC_VER) +// Check this after Intel and Clang because those define _MSC_VER for +// compatibility #define KOKKOS_COMPILER_MSVC _MSC_VER #endif @@ -207,7 +202,7 @@ #endif #endif -#if (1900 > KOKKOS_COMPILER_INTEL) +#if defined(KOKKOS_COMPILER_INTEL) && (1900 > KOKKOS_COMPILER_INTEL) #error "Compiling with Intel version earlier than 19.0.5 is not supported." #endif diff --git a/core/unit_test/TestCompilerMacros.hpp b/core/unit_test/TestCompilerMacros.cpp similarity index 75% rename from core/unit_test/TestCompilerMacros.hpp rename to core/unit_test/TestCompilerMacros.cpp index 9d22c4b0a7..e719ad83fb 100644 --- a/core/unit_test/TestCompilerMacros.hpp +++ b/core/unit_test/TestCompilerMacros.cpp @@ -14,8 +14,19 @@ // //@HEADER +#include #include +#if 1 != ((defined(KOKKOS_COMPILER_INTEL) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_CRAYC) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_APPLECC) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_CLANG) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_GNU) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_NVHPC) ? 1 : 0) + \ + (defined(KOKKOS_COMPILER_MSVC) ? 1 : 0)) +#error "Only one host compiler macro can be defined" +#endif + #if defined(KOKKOS_ENABLE_CUDA) && !defined(KOKKOS_ENABLE_CUDA_LAMBDA) #if defined(KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA) #error "Macro bug: KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA shouldn't be defined" @@ -26,8 +37,6 @@ #endif #endif -#define KOKKOS_PRAGMA_UNROLL(a) - namespace TestCompilerMacros { template @@ -51,7 +60,7 @@ struct AddFunctor { #pragma vector always #endif #ifdef KOKKOS_ENABLE_PRAGMA_LOOPCOUNT -#pragma loop count(128) +#pragma loop_count(128) #endif for (int j = 0; j < length; j++) { a(i, j) += b(i, j); @@ -75,7 +84,7 @@ bool Test() { } // namespace TestCompilerMacros namespace Test { -TEST(TEST_CATEGORY, compiler_macros) { - ASSERT_TRUE((TestCompilerMacros::Test())); +TEST(defaultdevicetype, compiler_macros) { + ASSERT_TRUE((TestCompilerMacros::Test())); } } // namespace Test