alpaka
Abstraction Library for Parallel Kernel Acceleration
AccGenericSycl.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Jan Stephan, Antonio Di Pilato, Andrea Bocci, Luca Ferragina, Aurora Perego
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 // Base classes.
24 
25 // Specialized traits.
26 #include "alpaka/acc/Traits.hpp"
27 #include "alpaka/dev/Traits.hpp"
28 #include "alpaka/idx/Traits.hpp"
29 #include "alpaka/kernel/Traits.hpp"
31 #include "alpaka/vec/Vec.hpp"
32 
33 // Implementation details.
35 #include "alpaka/core/ClipCast.hpp"
37 #include "alpaka/core/Sycl.hpp"
38 
39 #include <cstddef>
40 #include <string>
41 #include <type_traits>
42 
43 #ifdef ALPAKA_ACC_SYCL_ENABLED
44 
45 # include <sycl/sycl.hpp>
46 
47 namespace alpaka
48 {
49  template<concepts::Tag TTag, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
50  class TaskKernelGenericSycl;
51 
52  //! The SYCL accelerator.
53  //!
54  //! This accelerator allows parallel kernel execution on SYCL devices.
55  template<concepts::Tag TTag, typename TDim, typename TIdx>
56  class AccGenericSycl
57  : public WorkDivGenericSycl<TDim, TIdx>
58  , public gb::IdxGbGenericSycl<TDim, TIdx>
59  , public bt::IdxBtGenericSycl<TDim, TIdx>
60  , public AtomicHierarchy<AtomicGenericSycl, AtomicGenericSycl, AtomicGenericSycl>
61  , public math::MathGenericSycl
62  , public BlockSharedMemDynGenericSycl
63  , public BlockSharedMemStGenericSycl
64  , public BlockSyncGenericSycl<TDim>
65  , public IntrinsicGenericSycl
66  , public MemFenceGenericSycl
67 # ifdef ALPAKA_DISABLE_VENDOR_RNG
68  , public rand::RandDefault
69 # else
70  , public rand::RandGenericSycl<TDim>
71 # endif
72  , public warp::WarpGenericSycl<TDim>
73  , public interface::Implements<ConceptAcc, AccGenericSycl<TTag, TDim, TIdx>>
74  {
75  static_assert(TDim::value > 0, "The SYCL accelerator must have a dimension greater than zero.");
76 
77  public:
78  AccGenericSycl(AccGenericSycl const&) = delete;
79  AccGenericSycl(AccGenericSycl&&) = delete;
80  auto operator=(AccGenericSycl const&) -> AccGenericSycl& = delete;
81  auto operator=(AccGenericSycl&&) -> AccGenericSycl& = delete;
82 
83  AccGenericSycl(
84  Vec<TDim, TIdx> const& threadElemExtent,
85  sycl::nd_item<TDim::value> work_item,
86  sycl::local_accessor<std::byte> dyn_shared_acc,
87  sycl::local_accessor<std::byte> st_shared_acc)
88  : WorkDivGenericSycl<TDim, TIdx>{threadElemExtent, work_item}
89  , gb::IdxGbGenericSycl<TDim, TIdx>{work_item}
90  , bt::IdxBtGenericSycl<TDim, TIdx>{work_item}
91  , BlockSharedMemDynGenericSycl{dyn_shared_acc}
92  , BlockSharedMemStGenericSycl{st_shared_acc}
93  , BlockSyncGenericSycl<TDim>{work_item}
94 # ifndef ALPAKA_DISABLE_VENDOR_RNG
95  , rand::RandGenericSycl<TDim>{work_item}
96 # endif
97  , warp::WarpGenericSycl<TDim>{work_item}
98  {
99  }
100  };
101 } // namespace alpaka
102 
103 namespace alpaka::trait
104 {
105  //! The SYCL accelerator type trait specialization.
106  template<concepts::Tag TTag, typename TDim, typename TIdx>
107  struct AccType<AccGenericSycl<TTag, TDim, TIdx>>
108  {
109  using type = AccGenericSycl<TTag, TDim, TIdx>;
110  };
111 
112  //! The SYCL single thread accelerator type trait specialization.
113  template<concepts::Tag TTag, typename TDim, typename TIdx>
114  struct IsSingleThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::false_type
115  {
116  };
117 
118  //! The SYCL multi thread accelerator type trait specialization.
119  template<concepts::Tag TTag, typename TDim, typename TIdx>
120  struct IsMultiThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::true_type
121  {
122  };
123 
124  //! The SYCL accelerator device properties get trait specialization.
125  template<concepts::Tag TTag, typename TDim, typename TIdx>
126  struct GetAccDevProps<AccGenericSycl<TTag, TDim, TIdx>>
127  {
128  static auto getAccDevProps(DevGenericSycl<TTag> const& dev) -> AccDevProps<TDim, TIdx>
129  {
130  auto const device = dev.getNativeHandle().first;
131  auto const max_threads_dim
132  = device.template get_info<sycl::info::device::max_work_item_sizes<TDim::value>>();
133  Vec<TDim, TIdx> max_threads_dim_vec{};
134  for(int i = 0; i < static_cast<int>(TDim::value); i++)
135  max_threads_dim_vec[i] = alpaka::core::clipCast<TIdx>(max_threads_dim[i]);
136  return {// m_multiProcessorCount
137  alpaka::core::clipCast<TIdx>(device.template get_info<sycl::info::device::max_compute_units>()),
138  // m_gridBlockExtentMax
139  getExtentVecEnd<TDim>(Vec<DimInt<3u>, TIdx>(
140  // WARNING: There is no SYCL way to determine these values
144  // m_gridBlockCountMax
146  // m_blockThreadExtentMax
147  max_threads_dim_vec,
148  // m_blockThreadCountMax
149  alpaka::core::clipCast<TIdx>(device.template get_info<sycl::info::device::max_work_group_size>()),
150  // m_threadElemExtentMax
152  // m_threadElemCountMax
154  // m_sharedMemSizeBytes
155  device.template get_info<sycl::info::device::local_mem_size>(),
156  // m_globalMemSizeBytes
157  getMemBytes(dev)};
158  }
159  };
160 
161  //! The SYCL accelerator name trait specialization.
162  template<concepts::Tag TTag, typename TDim, typename TIdx>
163  struct GetAccName<AccGenericSycl<TTag, TDim, TIdx>>
164  {
165  static auto getAccName() -> std::string
166  {
167  return std::string("Acc") + core::demangled<TTag>.substr(__builtin_strlen("alpaka::Tag")) + "<"
168  + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
169  }
170  };
171 
172  //! The SYCL accelerator device type trait specialization.
173  template<concepts::Tag TTag, typename TDim, typename TIdx>
174  struct DevType<AccGenericSycl<TTag, TDim, TIdx>>
175  {
176  using type = DevGenericSycl<TTag>;
177  };
178 
179  //! The SYCL accelerator dimension getter trait specialization.
180  template<concepts::Tag TTag, typename TDim, typename TIdx>
181  struct DimType<AccGenericSycl<TTag, TDim, TIdx>>
182  {
183  using type = TDim;
184  };
185 
186  //! The SYCL accelerator execution task type trait specialization.
187  template<
188  concepts::Tag TTag,
189  typename TDim,
190  typename TIdx,
191  typename TWorkDiv,
192  typename TKernelFnObj,
193  typename... TArgs>
194  struct CreateTaskKernel<AccGenericSycl<TTag, TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
195  {
196  static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
197  {
198  return TaskKernelGenericSycl<TTag, AccGenericSycl<TTag, TDim, TIdx>, TDim, TIdx, TKernelFnObj, TArgs...>{
199  workDiv,
200  kernelFnObj,
201  std::forward<TArgs>(args)...};
202  }
203  };
204 
205  //! The SYCL execution task platform type trait specialization.
206  template<concepts::Tag TTag, typename TDim, typename TIdx>
207  struct PlatformType<AccGenericSycl<TTag, TDim, TIdx>>
208  {
209  using type = PlatformGenericSycl<TTag>;
210  };
211 
212  //! The SYCL accelerator idx type trait specialization.
213  template<concepts::Tag TTag, typename TDim, typename TIdx>
214  struct IdxType<AccGenericSycl<TTag, TDim, TIdx>>
215  {
216  using type = TIdx;
217  };
218 } // namespace alpaka::trait
219 
220 #endif
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto all(TVal const &val) -> Vec< TDim, TVal >
Single value constructor.
Definition: Vec.hpp:116
concept Tag
Definition: Tag.hpp:46
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
Definition: Traits.hpp:1263
The accelerator traits.
The alpaka accelerator library.
ALPAKA_FN_HOST auto getAccDevProps(TDev const &dev) -> AccDevProps< Dim< TAcc >, Idx< TAcc >>
Definition: Traits.hpp:90
ALPAKA_FN_HOST auto createTaskKernel(TWorkDiv const &workDiv, TKernelFnObj const &kernelFnObj, TArgs &&... args)
Creates a kernel execution task.
Definition: Traits.hpp:332
ALPAKA_FN_HOST auto getMemBytes(TDev const &dev) -> std::size_t
Definition: Traits.hpp:95
ALPAKA_FN_HOST_ACC Vec(TFirstIndex &&, TRestIndices &&...) -> Vec< DimInt< 1+sizeof...(TRestIndices)>, std::decay_t< TFirstIndex >>
alpaka::meta::InheritFromList< alpaka::meta::Unique< std::tuple< TGridAtomic, TBlockAtomic, TThreadAtomic, interface::Implements< ConceptAtomicGrids, TGridAtomic >, interface::Implements< ConceptAtomicBlocks, TBlockAtomic >, interface::Implements< ConceptAtomicThreads, TThreadAtomic > >> > AtomicHierarchy
build a single class to inherit from different atomic implementations
static ALPAKA_FN_HOST auto getAccName() -> std::string
Definition: Traits.hpp:69