Skip to content

Commit

Permalink
Define at most one KOKKOS_COMPILER* macro
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Apr 8, 2023
1 parent b6d1dba commit 140cbd7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
45 changes: 20 additions & 25 deletions core/src/Kokkos_Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@
//
//@HEADER

#include <gtest/gtest.h>
#include <Kokkos_Core.hpp>

#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"
Expand All @@ -26,8 +37,6 @@
#endif
#endif

#define KOKKOS_PRAGMA_UNROLL(a)

namespace TestCompilerMacros {

template <class DEVICE_TYPE>
Expand All @@ -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);
Expand All @@ -75,7 +84,7 @@ bool Test() {
} // namespace TestCompilerMacros

namespace Test {
TEST(TEST_CATEGORY, compiler_macros) {
ASSERT_TRUE((TestCompilerMacros::Test<TEST_EXECSPACE>()));
TEST(defaultdevicetype, compiler_macros) {
ASSERT_TRUE((TestCompilerMacros::Test<Kokkos::DefaultHostExecutionSpace>()));
}
} // namespace Test

0 comments on commit 140cbd7

Please sign in to comment.