alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Tag.hpp
Go to the documentation of this file.
1/* Copyright 2025 Simeon Ehrig, Jan Stephan, Andrea Bocci, Aurora Perego
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8
9#include <iostream>
10#include <tuple>
11#include <type_traits>
12
13namespace alpaka
14{
16 {
17 };
18} // namespace alpaka
19
20#define CREATE_ACC_TAG(tag_name) \
21 struct tag_name : public alpaka::InterfaceTag \
22 { \
23 static std::string get_name() \
24 { \
25 return #tag_name; \
26 } \
27 }
28
29namespace alpaka
30{
44
45 namespace concepts
46 {
47 template<typename T>
48 concept Tag = requires {
49 {
50 T::get_name()
51 } -> std::same_as<std::string>;
52 requires std::default_initializable<T>;
53 requires std::derived_from<T, alpaka::InterfaceTag>;
54 };
55 } // namespace concepts
56
57 namespace trait
58 {
59 template<typename TAcc>
60 struct AccToTag;
61
62 template<concepts::Tag TTag, typename TDim, typename TIdx>
63 struct TagToAcc;
64 } // namespace trait
65
66 //! \brief maps an acc type to a tag type
67 //! \tparam TAcc alpaka acc type
68 template<typename TAcc>
70
71 //! \brief maps a tag type to an acc type
72 //! \tparam TTag alpaka tag type
73 //! \tparam TDim dimension of the mapped acc type
74 //! \tparam TIdx index type of the mapped acc type
75 template<concepts::Tag TTag, typename TDim, typename TIdx>
77
78 template<typename TAcc, concepts::Tag... TTag>
79 inline constexpr bool accMatchesTags = (std::is_same_v<alpaka::AccToTag<TAcc>, TTag> || ...);
80
81 //! list of all available tags
82 using AccTags = std::tuple<
95
96 //! \brief Function to print the names of each tag in the given tuple of tags
97 //! \tparam TTuple is the type of the tuple of tags
98 template<typename TTuple>
100 {
101 // Check if the tuple is empty using std::tuple_size_v
102 if(std::tuple_size_v<TTuple> == 0)
103 {
104 std::cout << "No Tags!";
105 }
106 else
107 {
108 std::cout << "Tags: ";
109 // Print tags with comma in between
110 std::apply(
111 [](auto... args)
112 {
113 auto index = std::tuple_size_v<TTuple>;
114 ((std::cout << args.get_name() << (--index > 0u ? "," : "")), ...);
115 },
116 TTuple{});
117 }
118 std::cout << std::endl;
119 }
120} // namespace alpaka
#define CREATE_ACC_TAG(tag_name)
Definition Tag.hpp:20
The alpaka accelerator library.
std::tuple< alpaka::TagCpuSerial, alpaka::TagCpuThreads, alpaka::TagCpuTbbBlocks, alpaka::TagCpuOmp2Blocks, alpaka::TagCpuOmp2Threads, alpaka::TagGpuCudaRt, alpaka::TagGpuHipRt, alpaka::TagCpuSycl, alpaka::TagFpgaSyclIntel, alpaka::TagGpuSyclIntel, alpaka::TagGpuSyclNvidia, alpaka::TagGpuSyclAmd > AccTags
list of all available tags
Definition Tag.hpp:94
constexpr bool accMatchesTags
Definition Tag.hpp:79
void printTagNames()
Function to print the names of each tag in the given tuple of tags.
Definition Tag.hpp:99
typename trait::AccToTag< TAcc >::type AccToTag
maps an acc type to a tag type
Definition Tag.hpp:69
typename trait::TagToAcc< TTag, TDim, TIdx >::type TagToAcc
maps a tag type to an acc type
Definition Tag.hpp:76