alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
AccGenericSycl.hpp
Go to the documentation of this file.
1/* Copyright 2025 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"
31#include "alpaka/vec/Vec.hpp"
32
33// Implementation details.
37#include "alpaka/core/Sycl.hpp"
38
39#include <cstddef>
40#ifdef __cpp_lib_format
41# include <format>
42#endif
43#include <string>
44#include <type_traits>
45
46#ifdef ALPAKA_ACC_SYCL_ENABLED
47
48# include <sycl/sycl.hpp>
49
50namespace alpaka
51{
52 template<concepts::Tag TTag, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
53 class TaskKernelGenericSycl;
54
55 //! The SYCL accelerator.
56 //!
57 //! This accelerator allows parallel kernel execution on SYCL devices.
58 template<concepts::Tag TTag, typename TDim, typename TIdx>
59 class AccGenericSycl
60 : public WorkDivGenericSycl<TDim, TIdx>
61 , public gb::IdxGbGenericSycl<TDim, TIdx>
62 , public bt::IdxBtGenericSycl<TDim, TIdx>
63 , public AtomicHierarchy<AtomicGenericSycl, AtomicGenericSycl, AtomicGenericSycl>
64 , public math::MathGenericSycl
65 , public BlockSharedMemDynGenericSycl
66 , public BlockSharedMemStGenericSycl
67 , public BlockSyncGenericSycl<TDim>
68 , public IntrinsicGenericSycl
69 , public MemFenceGenericSycl
70# ifdef ALPAKA_DISABLE_VENDOR_RNG
71 , public rand::RandDefault
72# else
73 , public rand::RandGenericSycl<TDim>
74# endif
75 , public warp::WarpGenericSycl<TDim>
76 , public interface::Implements<ConceptAcc, AccGenericSycl<TTag, TDim, TIdx>>
77 {
78 static_assert(TDim::value > 0, "The SYCL accelerator must have a dimension greater than zero.");
79
80 public:
81 AccGenericSycl(AccGenericSycl const&) = delete;
82 AccGenericSycl(AccGenericSycl&&) = delete;
83 auto operator=(AccGenericSycl const&) -> AccGenericSycl& = delete;
84 auto operator=(AccGenericSycl&&) -> AccGenericSycl& = delete;
85
86 AccGenericSycl(
87 Vec<TDim, TIdx> const& threadElemExtent,
88 sycl::nd_item<TDim::value> work_item,
89 sycl::local_accessor<std::byte> dyn_shared_acc,
90 sycl::local_accessor<std::byte> st_shared_acc)
91 : WorkDivGenericSycl<TDim, TIdx>{threadElemExtent, work_item}
92 , gb::IdxGbGenericSycl<TDim, TIdx>{work_item}
93 , bt::IdxBtGenericSycl<TDim, TIdx>{work_item}
94 , BlockSharedMemDynGenericSycl{dyn_shared_acc}
95 , BlockSharedMemStGenericSycl{st_shared_acc}
96 , BlockSyncGenericSycl<TDim>{work_item}
97# ifndef ALPAKA_DISABLE_VENDOR_RNG
98 , rand::RandGenericSycl<TDim>{work_item}
99# endif
100 , warp::WarpGenericSycl<TDim>{work_item}
101 {
102 }
103 };
104} // namespace alpaka
105
106namespace alpaka::trait
107{
108 //! The SYCL accelerator type trait specialization.
109 template<concepts::Tag TTag, typename TDim, typename TIdx>
110 struct AccType<AccGenericSycl<TTag, TDim, TIdx>>
111 {
112 using type = AccGenericSycl<TTag, TDim, TIdx>;
113 };
114
115 //! The SYCL single thread accelerator type trait specialization.
116 template<concepts::Tag TTag, typename TDim, typename TIdx>
117 struct IsSingleThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::false_type
118 {
119 };
120
121 //! The SYCL multi thread accelerator type trait specialization.
122 template<concepts::Tag TTag, typename TDim, typename TIdx>
123 struct IsMultiThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::true_type
124 {
125 };
126
127 //! The SYCL accelerator device properties get trait specialization.
128 template<concepts::Tag TTag, typename TDim, typename TIdx>
129 struct GetAccDevProps<AccGenericSycl<TTag, TDim, TIdx>>
130 {
131 static auto getAccDevProps(DevGenericSycl<TTag> const& dev) -> AccDevProps<TDim, TIdx>
132 {
133 auto const device = dev.getNativeHandle().first;
134 auto const max_threads_dim
135 = device.template get_info<sycl::info::device::max_work_item_sizes<TDim::value>>();
136 Vec<TDim, TIdx> max_threads_dim_vec{};
137 for(int i = 0; i < static_cast<int>(TDim::value); i++)
138 max_threads_dim_vec[i] = alpaka::core::clipCast<TIdx>(max_threads_dim[i]);
139 return {// m_multiProcessorCount
140 alpaka::core::clipCast<TIdx>(device.template get_info<sycl::info::device::max_compute_units>()),
141 // m_gridBlockExtentMax
142 getExtentVecEnd<TDim>(Vec<DimInt<3u>, TIdx>(
143 // WARNING: There is no SYCL way to determine these values
144 std::numeric_limits<TIdx>::max(),
145 std::numeric_limits<TIdx>::max(),
146 std::numeric_limits<TIdx>::max())),
147 // m_gridBlockCountMax
148 std::numeric_limits<TIdx>::max(),
149 // m_blockThreadExtentMax
150 max_threads_dim_vec,
151 // m_blockThreadCountMax
152 alpaka::core::clipCast<TIdx>(device.template get_info<sycl::info::device::max_work_group_size>()),
153 // m_threadElemExtentMax
154 Vec<TDim, TIdx>::all(std::numeric_limits<TIdx>::max()),
155 // m_threadElemCountMax
156 std::numeric_limits<TIdx>::max(),
157 // m_sharedMemSizeBytes
158 device.template get_info<sycl::info::device::local_mem_size>(),
159 // m_globalMemSizeBytes
160 getMemBytes(dev)};
161 }
162 };
163
164 //! The SYCL accelerator name trait specialization.
165 template<concepts::Tag TTag, typename TDim, typename TIdx>
166 struct GetAccName<AccGenericSycl<TTag, TDim, TIdx>>
167 {
168 static auto getAccName() -> std::string
169 {
170# if ALPAKA_COMP_CLANG
171# pragma clang diagnostic push
172# pragma clang diagnostic ignored "-Wexit-time-destructors"
173# endif
174 using namespace std::literals;
175 static std::string const accName =
176# ifdef __cpp_lib_format
177 std::format(
178 "Acc{}<{},{}>",
179 core::demangled<TTag>.substr(std::string_view("alpaka::Tag").size()),
180 TDim::value,
182# else
183 "Acc"s + std::string(core::demangled<TTag>.substr(std::string_view("alpaka::Tag").size())) + "<"s
184 + std::to_string(TDim::value) + ","s + std::string(core::demangled<TIdx>) + ">"s;
185# endif
186 return accName;
187# if ALPAKA_COMP_CLANG
188# pragma clang diagnostic pop
189# endif
190 }
191 };
192
193 //! The SYCL accelerator device type trait specialization.
194 template<concepts::Tag TTag, typename TDim, typename TIdx>
195 struct DevType<AccGenericSycl<TTag, TDim, TIdx>>
196 {
197 using type = DevGenericSycl<TTag>;
198 };
199
200 //! The SYCL accelerator dimension getter trait specialization.
201 template<concepts::Tag TTag, typename TDim, typename TIdx>
202 struct DimType<AccGenericSycl<TTag, TDim, TIdx>>
203 {
204 using type = TDim;
205 };
206
207 //! The SYCL accelerator execution task type trait specialization.
208 template<
209 concepts::Tag TTag,
210 typename TDim,
211 typename TIdx,
212 typename TWorkDiv,
213 typename TKernelFnObj,
214 typename... TArgs>
215 struct CreateTaskKernel<AccGenericSycl<TTag, TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
216 {
217 static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
218 {
219 return TaskKernelGenericSycl<TTag, AccGenericSycl<TTag, TDim, TIdx>, TDim, TIdx, TKernelFnObj, TArgs...>{
220 workDiv,
221 kernelFnObj,
222 std::forward<TArgs>(args)...};
223 }
224 };
225
226 //! The SYCL execution task platform type trait specialization.
227 template<concepts::Tag TTag, typename TDim, typename TIdx>
228 struct PlatformType<AccGenericSycl<TTag, TDim, TIdx>>
229 {
230 using type = PlatformGenericSycl<TTag>;
231 };
232
233 //! The SYCL accelerator idx type trait specialization.
234 template<concepts::Tag TTag, typename TDim, typename TIdx>
235 struct IdxType<AccGenericSycl<TTag, TDim, TIdx>>
236 {
237 using type = TIdx;
238 };
239} // namespace alpaka::trait
240
241#endif
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto all(TVal const &val) -> Vec< TDim, TVal >
Single value constructor.
Definition Vec.hpp:89
auto clipCast(V const &val) -> T
Definition ClipCast.hpp:16
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::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