alpaka
Abstraction Library for Parallel Kernel Acceleration
IdxGbGenericSycl.hpp
Go to the documentation of this file.
1 /* Copyright 2023 Jan Stephan, Aurora Perego
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 #include "alpaka/core/Sycl.hpp"
10 #include "alpaka/idx/Traits.hpp"
11 #include "alpaka/vec/Vec.hpp"
12 
13 #ifdef ALPAKA_ACC_SYCL_ENABLED
14 
15 # include <sycl/sycl.hpp>
16 
17 namespace alpaka::gb
18 {
19  //! The SYCL accelerator ND index provider.
20  template<typename TDim, typename TIdx>
21  class IdxGbGenericSycl : public interface::Implements<ConceptIdxGb, IdxGbGenericSycl<TDim, TIdx>>
22  {
23  public:
24  using IdxGbBase = IdxGbGenericSycl;
25 
26  explicit IdxGbGenericSycl(sycl::nd_item<TDim::value> work_item) : m_item_gb{work_item}
27  {
28  }
29 
30  sycl::nd_item<TDim::value> m_item_gb;
31  };
32 } // namespace alpaka::gb
33 
34 namespace alpaka::trait
35 {
36  //! The SYCL accelerator index dimension get trait specialization.
37  template<typename TDim, typename TIdx>
38  struct DimType<gb::IdxGbGenericSycl<TDim, TIdx>>
39  {
40  using type = TDim;
41  };
42 
43  //! The SYCL accelerator grid block index get trait specialization.
44  template<typename TDim, typename TIdx>
45  struct GetIdx<gb::IdxGbGenericSycl<TDim, TIdx>, origin::Grid, unit::Blocks>
46  {
47  //! \return The index of the current block in the grid.
48  template<typename TWorkDiv>
49  static auto getIdx(gb::IdxGbGenericSycl<TDim, TIdx> const& idx, TWorkDiv const&)
50  {
51  if constexpr(TDim::value == 1)
52  return Vec<TDim, TIdx>(static_cast<TIdx>(idx.m_item_gb.get_group(0)));
53  else if constexpr(TDim::value == 2)
54  {
55  return Vec<TDim, TIdx>(
56  static_cast<TIdx>(idx.m_item_gb.get_group(1)),
57  static_cast<TIdx>(idx.m_item_gb.get_group(0)));
58  }
59  else
60  {
61  return Vec<TDim, TIdx>(
62  static_cast<TIdx>(idx.m_item_gb.get_group(2)),
63  static_cast<TIdx>(idx.m_item_gb.get_group(1)),
64  static_cast<TIdx>(idx.m_item_gb.get_group(0)));
65  }
66  }
67  };
68 
69  //! The SYCL accelerator grid block index idx type trait specialization.
70  template<typename TDim, typename TIdx>
71  struct IdxType<gb::IdxGbGenericSycl<TDim, TIdx>>
72  {
73  using type = TIdx;
74  };
75 } // namespace alpaka::trait
76 
77 #endif
The accelerator traits.
ALPAKA_FN_HOST_ACC Vec(TFirstIndex &&, TRestIndices &&...) -> Vec< DimInt< 1+sizeof...(TRestIndices)>, std::decay_t< TFirstIndex >>
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getIdx(TIdx const &idx, TWorkDiv const &workDiv) -> Vec< Dim< TWorkDiv >, Idx< TIdx >>
Get the indices requested.
Definition: Accessors.hpp:23