alpaka
Abstraction Library for Parallel Kernel Acceleration
TestAccs.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Benjamin Worpitz, Erik Zenker, Matthias Werner, Andrea Bocci, Bernhard Manfred Gruber, Jan Stephan,
2  * Aurora Perego
3  * SPDX-License-Identifier: MPL-2.0
4  */
5 
6 #pragma once
7 
8 #include "alpaka/alpaka.hpp"
11 
12 #include <iosfwd>
13 #include <tuple>
14 #include <type_traits>
15 
16 // When compiling the tests with CUDA enabled (nvcc or native clang) on the CI infrastructure
17 // we have to dramatically reduce the number of tested combinations.
18 // Else the log length would be exceeded.
19 #if defined(ALPAKA_CI)
20 # if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && BOOST_LANG_CUDA \
21  || defined(ALPAKA_ACC_GPU_HIP_ENABLED) && BOOST_LANG_HIP
22 # define ALPAKA_CUDA_CI
23 # endif
24 #endif
25 
26 namespace alpaka::test
27 {
28  //! The detail namespace is used to separate implementation details from user accessible code.
29  namespace detail
30  {
31 #if defined(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED)
32  template<typename TDim, typename TIdx>
34 #else
35  template<typename TDim, typename TIdx>
37 #endif
38 #if defined(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED) && !defined(ALPAKA_CUDA_CI)
39  template<typename TDim, typename TIdx>
41 #else
42  template<typename TDim, typename TIdx>
44 #endif
45 #if defined(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED)
46  template<typename TDim, typename TIdx>
47  using AccCpuTbbIfAvailableElseInt = AccCpuTbbBlocks<TDim, TIdx>;
48 #else
49  template<typename TDim, typename TIdx>
51 #endif
52 #if defined(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED)
53  template<typename TDim, typename TIdx>
55 #else
56  template<typename TDim, typename TIdx>
58 #endif
59 #if defined(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED) && !defined(ALPAKA_CUDA_CI)
60  template<typename TDim, typename TIdx>
62 #else
63  template<typename TDim, typename TIdx>
65 #endif
66 #if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && (BOOST_LANG_CUDA || defined(ALPAKA_HOST_ONLY))
67  template<typename TDim, typename TIdx>
69 #else
70  template<typename TDim, typename TIdx>
72 #endif
73 #if defined(ALPAKA_ACC_GPU_HIP_ENABLED) && (BOOST_LANG_HIP || defined(ALPAKA_HOST_ONLY))
74  template<typename TDim, typename TIdx>
76  typename std::conditional<std::is_same_v<TDim, DimInt<3u>> == false, AccGpuHipRt<TDim, TIdx>, int>::type;
77 #else
78  template<typename TDim, typename TIdx>
80 #endif
81 #if defined(ALPAKA_ACC_SYCL_ENABLED) && defined(ALPAKA_SYCL_TARGET_CPU)
82  template<typename TDim, typename TIdx>
83  using AccCpuSyclIfAvailableElseInt = AccCpuSycl<TDim, TIdx>;
84 #else
85  template<typename TDim, typename TIdx>
87 #endif
88 #if defined(ALPAKA_ACC_SYCL_ENABLED) && defined(ALPAKA_SYCL_TARGET_FPGA)
89  template<typename TDim, typename TIdx>
90  using AccFpgaSyclIntelIfAvailableElseInt = AccFpgaSyclIntel<TDim, TIdx>;
91 #else
92  template<typename TDim, typename TIdx>
94 #endif
95 #if defined(ALPAKA_ACC_SYCL_ENABLED) && defined(ALPAKA_SYCL_TARGET_GPU)
96  template<typename TDim, typename TIdx>
97  using AccGpuSyclIntelIfAvailableElseInt = AccGpuSyclIntel<TDim, TIdx>;
98 #else
99  template<typename TDim, typename TIdx>
101 #endif
102 
103  //! A vector containing all available accelerators and int's.
104  template<typename TDim, typename TIdx>
105  using EnabledAccsElseInt = std::tuple<
116  } // namespace detail
117 
118  //! A vector containing all available accelerators.
119  template<typename TDim, typename TIdx>
121 
122  namespace detail
123  {
124  //! The accelerator name write wrapper.
126  {
127  template<typename TAcc>
128  ALPAKA_FN_HOST auto operator()(std::ostream& os) -> void
129  {
130  os << getAccName<TAcc>();
131  os << " ";
132  }
133  };
134  } // namespace detail
135 
136  //! Writes the enabled accelerators to the given stream.
137  template<typename TDim, typename TIdx>
138  ALPAKA_FN_HOST auto writeEnabledAccs(std::ostream& os) -> void
139  {
140  os << "Accelerators enabled: ";
141 
142  meta::forEachType<EnabledAccs<TDim, TIdx>>(detail::StreamOutAccName(), std::ref(os));
143 
144  os << std::endl;
145  }
146 
147  namespace detail
148  {
149  //! A std::tuple holding multiple std::tuple consisting of a dimension and a idx type.
150  //!
151  //! TestDimIdxTuples =
152  //! tuple<
153  //! tuple<Dim1,Idx1>,
154  //! tuple<Dim2,Idx1>,
155  //! tuple<Dim3,Idx1>,
156  //! ...,
157  //! tuple<DimN,IdxN>>
159 
160  template<typename TList>
162 
163  //! A std::tuple containing std::tuple with fully instantiated accelerators.
164  //!
165  //! TestEnabledAccs =
166  //! tuple<
167  //! tuple<Acc1<Dim1,Idx1>, ..., AccN<Dim1,Idx1>>,
168  //! tuple<Acc1<Dim2,Idx1>, ..., AccN<Dim2,Idx1>>,
169  //! ...,
170  //! tuple<Acc1<DimN,IdxN>, ..., AccN<DimN,IdxN>>>
172  } // namespace detail
173 
174  //! A std::tuple containing fully instantiated accelerators.
175  //!
176  //! TestAccs =
177  //! tuple<
178  //! Acc1<Dim1,Idx1>, ..., AccN<Dim1,Idx1>,
179  //! Acc1<Dim2,Idx1>, ..., AccN<Dim2,Idx1>,
180  //! ...,
181  //! Acc1<DimN,IdxN>, ..., AccN<DimN,IdxN>>
183 } // namespace alpaka::test
The CPU OpenMP 2.0 block accelerator.
The CPU OpenMP 2.0 thread accelerator.
The CPU serial accelerator.
The CPU threads accelerator.
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
typename detail::TransformImpl< Ts, TOp >::type Transform
Definition: Transform.hpp:21
typename detail::FilterImpl< TList, TPred >::type Filter
Definition: Filter.hpp:46
typename detail::CartesianProductImpl< TList, Ts... >::type CartesianProduct
typename detail::ApplyImpl< TList, TApplicant >::type Apply
Definition: Apply.hpp:21
std::tuple< AccCpuSerialIfAvailableElseInt< TDim, TIdx >, AccCpuThreadsIfAvailableElseInt< TDim, TIdx >, AccCpuTbbIfAvailableElseInt< TDim, TIdx >, AccCpuOmp2BlocksIfAvailableElseInt< TDim, TIdx >, AccCpuOmp2ThreadsIfAvailableElseInt< TDim, TIdx >, AccGpuCudaRtIfAvailableElseInt< TDim, TIdx >, AccGpuHipRtIfAvailableElseInt< TDim, TIdx >, AccCpuSyclIfAvailableElseInt< TDim, TIdx >, AccFpgaSyclIntelIfAvailableElseInt< TDim, TIdx >, AccGpuSyclIntelIfAvailableElseInt< TDim, TIdx > > EnabledAccsElseInt
A vector containing all available accelerators and int's.
Definition: TestAccs.hpp:115
int AccFpgaSyclIntelIfAvailableElseInt
Definition: TestAccs.hpp:93
meta::Apply< TList, EnabledAccs > ApplyEnabledAccs
Definition: TestAccs.hpp:161
int AccGpuHipRtIfAvailableElseInt
Definition: TestAccs.hpp:79
int AccGpuCudaRtIfAvailableElseInt
Definition: TestAccs.hpp:71
int AccCpuTbbIfAvailableElseInt
Definition: TestAccs.hpp:50
meta::CartesianProduct< std::tuple, NonZeroTestDims, TestIdxs > TestDimIdxTuples
A std::tuple holding multiple std::tuple consisting of a dimension and a idx type.
Definition: TestAccs.hpp:158
int AccCpuSyclIfAvailableElseInt
Definition: TestAccs.hpp:86
meta::Transform< TestDimIdxTuples, ApplyEnabledAccs > InstantiatedEnabledAccs
A std::tuple containing std::tuple with fully instantiated accelerators.
Definition: TestAccs.hpp:171
int AccGpuSyclIntelIfAvailableElseInt
Definition: TestAccs.hpp:100
The test specifics.
Definition: TestAccs.hpp:27
typename meta::Filter< detail::EnabledAccsElseInt< TDim, TIdx >, std::is_class > EnabledAccs
A vector containing all available accelerators.
Definition: TestAccs.hpp:120
meta::Apply< detail::InstantiatedEnabledAccs, meta::Concatenate > TestAccs
A std::tuple containing fully instantiated accelerators.
Definition: TestAccs.hpp:182
ALPAKA_FN_HOST auto writeEnabledAccs(std::ostream &os) -> void
Writes the enabled accelerators to the given stream.
Definition: TestAccs.hpp:138
The accelerator name write wrapper.
Definition: TestAccs.hpp:126
ALPAKA_FN_HOST auto operator()(std::ostream &os) -> void
Definition: TestAccs.hpp:128