alpaka
Abstraction Library for Parallel Kernel Acceleration
IdxBtGenericSycl.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::bt
18 {
19  //! The SYCL accelerator ND index provider.
20  template<typename TDim, typename TIdx>
21  class IdxBtGenericSycl : public interface::Implements<ConceptIdxBt, IdxBtGenericSycl<TDim, TIdx>>
22  {
23  public:
24  using IdxBtBase = IdxBtGenericSycl;
25 
26  explicit IdxBtGenericSycl(sycl::nd_item<TDim::value> work_item) : m_item_bt{work_item}
27  {
28  }
29 
30  sycl::nd_item<TDim::value> m_item_bt;
31  };
32 } // namespace alpaka::bt
33 
34 namespace alpaka::trait
35 {
36  //! The SYCL accelerator index dimension get trait specialization.
37  template<typename TDim, typename TIdx>
38  struct DimType<bt::IdxBtGenericSycl<TDim, TIdx>>
39  {
40  using type = TDim;
41  };
42 
43  //! The SYCL accelerator block thread index get trait specialization.
44  template<typename TDim, typename TIdx>
45  struct GetIdx<bt::IdxBtGenericSycl<TDim, TIdx>, origin::Block, unit::Threads>
46  {
47  //! \return The index of the current thread in the block.
48  template<typename TWorkDiv>
49  static auto getIdx(bt::IdxBtGenericSycl<TDim, TIdx> const& idx, TWorkDiv const&) -> Vec<TDim, TIdx>
50  {
51  if constexpr(TDim::value == 1)
52  return Vec<TDim, TIdx>{static_cast<TIdx>(idx.m_item_bt.get_local_id(0))};
53  else if constexpr(TDim::value == 2)
54  {
55  return Vec<TDim, TIdx>{
56  static_cast<TIdx>(idx.m_item_bt.get_local_id(1)),
57  static_cast<TIdx>(idx.m_item_bt.get_local_id(0))};
58  }
59  else
60  {
61  return Vec<TDim, TIdx>{
62  static_cast<TIdx>(idx.m_item_bt.get_local_id(2)),
63  static_cast<TIdx>(idx.m_item_bt.get_local_id(1)),
64  static_cast<TIdx>(idx.m_item_bt.get_local_id(0))};
65  }
66  }
67  };
68 
69  //! The SYCL accelerator block thread index idx type trait specialization.
70  template<typename TDim, typename TIdx>
71  struct IdxType<bt::IdxBtGenericSycl<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