Skip to content

Commit

Permalink
implement AccIsEnabled
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
SimeonEhrig committed May 13, 2024
1 parent 850995c commit 153fe2c
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
15 changes: 15 additions & 0 deletions cmake/alpakaCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<$<AND:$<CXX_COMPILER_ID:Clang,AppleClang,IntelLLVM>>: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 "$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:CXX>>:SHELL:-Og>"
Expand Down Expand Up @@ -570,6 +577,13 @@ if(alpaka_ACC_GPU_HIP_ENABLE)
alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$<COMPILE_LANGUAGE:CXX>:-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 "$<$<COMPILE_LANGUAGE:HIP>:SHELL:-frelaxed-template-template-args>")

alpaka_compiler_option(HIP_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps 'CMakeFiles/<targetname>.dir'" OFF)
if(alpaka_HIP_KEEP_FILES)
alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$<COMPILE_LANGUAGE:HIP>:SHELL:-save-temps>")
Expand Down Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions include/alpaka/acc/Tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename TAcc>
using AccToTag = typename trait::AccToTag<TAcc>::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<typename TTag, typename TDim, typename TIdx>
using TagToAcc = typename trait::TagToAcc<TTag, TDim, TIdx>::type;

template<typename TAcc, typename... TTag>
inline constexpr bool accMatchesTags = (std::is_same_v<alpaka::AccToTag<TAcc>, 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
36 changes: 36 additions & 0 deletions include/alpaka/acc/TagAccIsEnabled.hpp
Original file line number Diff line number Diff line change
@@ -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 <type_traits>

namespace alpaka
{
//! \brief check if the accelerator is enabled for a given tag
//! \tparam TTag alpaka tag type
template<typename TTag, typename = void>
struct AccIsEnabled : std::false_type
{
};

template<typename TTag>
struct AccIsEnabled<TTag, std::void_t<TagToAcc<TTag, alpaka::DimInt<1>, int>>> : std::true_type
{
};

//! list of all tags where the related accelerator is enabled
using EnabledAccTags = alpaka::meta::Filter<AccTags, alpaka::AccIsEnabled>;

} // namespace alpaka
1 change: 1 addition & 0 deletions include/alpaka/alpaka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions test/unit/acc/src/AccTagTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alpaka/alpaka.hpp>
#include <alpaka/test/acc/TestAccs.hpp>

Expand Down Expand Up @@ -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<TestAcc, int>)
{
STATIC_REQUIRE(alpaka::AccIsEnabled<TestTag>::value);
}
else
{
STATIC_REQUIRE_FALSE(alpaka::AccIsEnabled<TestTag>::value);
}
}


TEST_CASE("test EnabledAccTags", "[acc][tag]")
{
using AllAccs = alpaka::test::EnabledAccs<alpaka::DimInt<1>, int>;
STATIC_REQUIRE(std::tuple_size<AllAccs>::value == std::tuple_size<alpaka::EnabledAccTags>::value);
}

0 comments on commit 153fe2c

Please sign in to comment.