From 153fe2c68e84f6ba7ade214bc22dabb60d3f2178 Mon Sep 17 00:00:00 2001 From: Simeon Ehrig Date: Mon, 13 May 2024 12:54:38 +0200 Subject: [PATCH] implement AccIsEnabled - the value of AccIsEnabled indicates whether an accelerator is enabled for a specific tag - AccTags list which contains all tags - EnabledAccTags contains all tags, where the related Acc is enabled - isCpuTag returns true, if the related Acc is bounded the cpuplatform - enable relaxed template template argument matching for Clang base compiler --- cmake/alpakaCommon.cmake | 15 +++++++++++ include/alpaka/acc/Tag.hpp | 26 ++++++++++++++----- include/alpaka/acc/TagAccIsEnabled.hpp | 36 ++++++++++++++++++++++++++ include/alpaka/alpaka.hpp | 1 + test/unit/acc/src/AccTagTest.cpp | 29 +++++++++++++++++++++ 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 include/alpaka/acc/TagAccIsEnabled.hpp diff --git a/cmake/alpakaCommon.cmake b/cmake/alpakaCommon.cmake index 10fc92fadd04..7c81504639f1 100644 --- a/cmake/alpakaCommon.cmake +++ b/cmake/alpakaCommon.cmake @@ -194,6 +194,13 @@ else() endif() endif() + # C++17 relaxed template template argument matching is disabled by default until Clang 19 + # https://github.com/llvm/llvm-project/commit/b86e0992bfa6 + # https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#150 + # for example, is required to create alpaka::EnabledAccTags + # the feature is implemented since Clang 4 + alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$>:SHELL:-frelaxed-template-template-args>") + # Add debug optimization levels. CMake doesn't do this by default. # Note that -Og is the recommended gcc optimization level for debug mode but is equivalent to -O1 for clang (and its derivates). alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$,$,$>:SHELL:-Og>" @@ -570,6 +577,13 @@ if(alpaka_ACC_GPU_HIP_ENABLE) alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$:-D__HIP_PLATFORM_HCC__>") endif() + # C++17 relaxed template template argument matching is disabled by default until Clang 19 + # https://github.com/llvm/llvm-project/commit/b86e0992bfa6 + # https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#150 + # for example, is required to create alpaka::EnabledAccTags + # TODO(SimeonEhrig): restict HIP version, if first HIP version is release using Clang 19 + alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$:SHELL:-frelaxed-template-template-args>") + alpaka_compiler_option(HIP_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps 'CMakeFiles/.dir'" OFF) if(alpaka_HIP_KEEP_FILES) alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$:SHELL:-save-temps>") @@ -630,6 +644,7 @@ if(alpaka_ACC_SYCL_ENABLE) alpaka_set_compiler_options(HOST_DEVICE target alpaka "-fsycl") target_link_options(alpaka INTERFACE "-fsycl") alpaka_set_compiler_options(HOST_DEVICE target alpaka "-sycl-std=2020") + alpaka_set_compiler_options(HOST_DEVICE target alpaka "-frelaxed-template-template-args") #----------------------------------------------------------------------------------------------------------------- # Determine SYCL targets diff --git a/include/alpaka/acc/Tag.hpp b/include/alpaka/acc/Tag.hpp index 611ee558d941..f7880afd6f15 100644 --- a/include/alpaka/acc/Tag.hpp +++ b/include/alpaka/acc/Tag.hpp @@ -41,18 +41,32 @@ namespace alpaka struct TagToAcc; } // namespace trait - /// @brief maps an acc type to a tag type - /// @tparam TAcc alpaka acc type + //! \brief maps an acc type to a tag type + //! \tparam TAcc alpaka acc type template using AccToTag = typename trait::AccToTag::type; - /// @brief maps a tag type to an acc type - /// @tparam TTag alpaka tag type - /// @tparam TDim dimension of the mapped acc type - /// @tparam TIdx index type of the mapped acc type + //! \brief maps a tag type to an acc type + //! \tparam TTag alpaka tag type + //! \tparam TDim dimension of the mapped acc type + //! \tparam TIdx index type of the mapped acc type template using TagToAcc = typename trait::TagToAcc::type; template inline constexpr bool accMatchesTags = (std::is_same_v, TTag> || ...); + + //! list of all available tags + using AccTags = std::tuple< + alpaka::TagCpuSerial, + alpaka::TagCpuThreads, + alpaka::TagCpuTbbBlocks, + alpaka::TagCpuOmp2Blocks, + alpaka::TagCpuOmp2Threads, + alpaka::TagGpuCudaRt, + alpaka::TagGpuHipRt, + alpaka::TagCpuSycl, + alpaka::TagFpgaSyclIntel, + alpaka::TagGpuSyclIntel>; + } // namespace alpaka diff --git a/include/alpaka/acc/TagAccIsEnabled.hpp b/include/alpaka/acc/TagAccIsEnabled.hpp new file mode 100644 index 000000000000..c21fd2b149aa --- /dev/null +++ b/include/alpaka/acc/TagAccIsEnabled.hpp @@ -0,0 +1,36 @@ +#pragma once + +// include all Acc's because of the struct AccIsEnabled +// if an acc is not include, it will be not enabled independent of the compiler flags +#include "alpaka/acc/AccCpuOmp2Blocks.hpp" +#include "alpaka/acc/AccCpuOmp2Threads.hpp" +#include "alpaka/acc/AccCpuSerial.hpp" +#include "alpaka/acc/AccCpuSycl.hpp" +#include "alpaka/acc/AccCpuTbbBlocks.hpp" +#include "alpaka/acc/AccCpuThreads.hpp" +#include "alpaka/acc/AccFpgaSyclIntel.hpp" +#include "alpaka/acc/AccGpuCudaRt.hpp" +#include "alpaka/acc/AccGpuHipRt.hpp" +#include "alpaka/dim/DimIntegralConst.hpp" +#include "alpaka/meta/Filter.hpp" + +#include + +namespace alpaka +{ + //! \brief check if the accelerator is enabled for a given tag + //! \tparam TTag alpaka tag type + template + struct AccIsEnabled : std::false_type + { + }; + + template + struct AccIsEnabled, int>>> : std::true_type + { + }; + + //! list of all tags where the related accelerator is enabled + using EnabledAccTags = alpaka::meta::Filter; + +} // namespace alpaka diff --git a/include/alpaka/alpaka.hpp b/include/alpaka/alpaka.hpp index 99cd03754ae2..e06dede53d48 100644 --- a/include/alpaka/alpaka.hpp +++ b/include/alpaka/alpaka.hpp @@ -23,6 +23,7 @@ #include "alpaka/acc/AccGpuHipRt.hpp" #include "alpaka/acc/AccGpuSyclIntel.hpp" #include "alpaka/acc/Tag.hpp" +#include "alpaka/acc/TagAccIsEnabled.hpp" #include "alpaka/acc/Traits.hpp" // atomic #include "alpaka/atomic/AtomicCpu.hpp" diff --git a/test/unit/acc/src/AccTagTest.cpp b/test/unit/acc/src/AccTagTest.cpp index 49024fc73a96..6b221249f6a8 100644 --- a/test/unit/acc/src/AccTagTest.cpp +++ b/test/unit/acc/src/AccTagTest.cpp @@ -2,6 +2,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +// Undefine ALPAKA_CI for this test, because the variable set the value of some acc types, like +// AccCpuThreadsIfAvailableElseInt to int independent of the cmake configuration. This avoids long running test cases +// but is problematic for this test. +#undef ALPAKA_CI #include #include @@ -248,3 +252,28 @@ TEMPLATE_LIST_TEST_CASE("kernel specialization with tags", "[acc][tag]", TestAcc REQUIRE(alpaka::getPtrNative(memHost)[0] == expected_result); } + +TEMPLATE_LIST_TEST_CASE("test AccIsEnabled", "[acc][tag]", AccToTagMap) +{ + using TestAcc = std::tuple_element_t<0, TestType>; + using TestTag = std::tuple_element_t<1, TestType>; + + + // if the Acc is not enabled, the type is int + if constexpr(!std::is_same_v) + { + STATIC_REQUIRE(alpaka::AccIsEnabled::value); + } + else + { + STATIC_REQUIRE_FALSE(alpaka::AccIsEnabled::value); + } +} + + +TEST_CASE("test EnabledAccTags", "[acc][tag]") +{ + using AllAccs = alpaka::test::EnabledAccs, int>; + STATIC_REQUIRE(std::tuple_size::value == std::tuple_size::value); +} +