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
  • Loading branch information
SimeonEhrig committed May 6, 2024
1 parent 850995c commit a596bda
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/alpaka/acc/Tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "alpaka/core/BoostPredef.hpp"
#include "alpaka/dim/DimIntegralConst.hpp"

#include <iostream>
#include <type_traits>
Expand Down Expand Up @@ -56,3 +57,32 @@ namespace alpaka
template<typename TAcc, typename... TTag>
inline constexpr bool accMatchesTags = (std::is_same_v<alpaka::AccToTag<TAcc>, TTag> || ...);
} // namespace alpaka

// 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 after defining the traits alpaka::AccToTag and alpaka::TagToAcc because it
// is a circular dependency
#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"

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
{
};
} // namespace alpaka
16 changes: 16 additions & 0 deletions test/unit/acc/src/AccTagTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,19 @@ 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);
}
}

0 comments on commit a596bda

Please sign in to comment.