alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Tag.hpp
Go to the documentation of this file.
1/* Copyright 2023 Simeon Ehrig, Jan Stephan, Andrea Bocci
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{
42
43 namespace concepts
44 {
45 template<typename T>
46 concept Tag = requires {
47 {
48 T::get_name()
49 } -> std::same_as<std::string>;
50 requires std::default_initializable<T>;
51 requires std::derived_from<T, alpaka::InterfaceTag>;
52 };
53 } // namespace concepts
54
55 namespace trait
56 {
57 template<typename TAcc>
58 struct AccToTag;
59
60 template<concepts::Tag TTag, typename TDim, typename TIdx>
61 struct TagToAcc;
62 } // namespace trait
63
64 //! \brief maps an acc type to a tag type
65 //! \tparam TAcc alpaka acc type
66 template<typename TAcc>
68
69 //! \brief maps a tag type to an acc type
70 //! \tparam TTag alpaka tag type
71 //! \tparam TDim dimension of the mapped acc type
72 //! \tparam TIdx index type of the mapped acc type
73 template<concepts::Tag TTag, typename TDim, typename TIdx>
75
76 template<typename TAcc, concepts::Tag... TTag>
77 inline constexpr bool accMatchesTags = (std::is_same_v<alpaka::AccToTag<TAcc>, TTag> || ...);
78
79 //! list of all available tags
80 using AccTags = std::tuple<
91
92 //! \brief Function to print the names of each tag in the given tuple of tags
93 //! \tparam TTuple is the type of the tuple of tags
94 template<typename TTuple>
96 {
97 // Check if the tuple is empty using std::tuple_size_v
98 if(std::tuple_size_v<TTuple> == 0)
99 {
100 std::cout << "No Tags!";
101 }
102 else
103 {
104 std::cout << "Tags: ";
105 // Print tags with comma in between
106 std::apply(
107 [](auto... args)
108 {
109 auto index = std::tuple_size_v<TTuple>;
110 ((std::cout << args.get_name() << (--index > 0u ? "," : "")), ...);
111 },
112 TTuple{});
113 }
114 std::cout << std::endl;
115 }
116} // 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 > AccTags
list of all available tags
Definition Tag.hpp:90
constexpr bool accMatchesTags
Definition Tag.hpp:77
void printTagNames()
Function to print the names of each tag in the given tuple of tags.
Definition Tag.hpp:95
typename trait::AccToTag< TAcc >::type AccToTag
maps an acc type to a tag type
Definition Tag.hpp:67
typename trait::TagToAcc< TTag, TDim, TIdx >::type TagToAcc
maps a tag type to an acc type
Definition Tag.hpp:74