alpaka
Abstraction Library for Parallel Kernel Acceleration
Common.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jan Stephan
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/dim/Traits.hpp"
10 
11 #include <cstddef>
12 
13 #ifdef ALPAKA_ACC_SYCL_ENABLED
14 
15 # include <sycl/sycl.hpp>
16 
17 namespace alpaka::detail
18 {
19  template<typename TExtent>
20  inline auto make_sycl_range(TExtent const& ext, std::size_t multiplier = 1)
21  {
22  constexpr auto dim = Dim<TExtent>::value;
23 
24  if constexpr(dim == 0)
25  return sycl::range<1>{multiplier};
26  else
27  {
28  auto const width = getWidth(ext) * multiplier;
29  if constexpr(dim == 1)
30  return sycl::range<1>{width};
31  else if constexpr(dim == 2)
32  return sycl::range<2>{width, getHeight(ext)};
33  else
34  return sycl::range<3>{width, getHeight(ext), getDepth(ext)};
35  }
36  }
37 
38  template<typename TView>
39  inline auto make_sycl_offset(TView const& view)
40  {
41  constexpr auto dim = Dim<TView>::value;
42 
43  if constexpr(dim == 0)
44  return sycl::range<1>{1};
45  else
46  {
47  if constexpr(dim == 1)
48  return sycl::id<1>{getOffsetX(view)};
49  else if constexpr(dim == 2)
50  return sycl::id<2>{getOffsetX(view), getOffsetY(view)};
51  else
52  return sycl::id<3>{getOffsetX(view), getOffsetY(view), getOffsetZ(view)};
53  }
54  }
55 } // namespace alpaka::detail
56 
57 #endif
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getHeight(TExtent const &extent=TExtent()) -> Idx< TExtent >
Definition: Traits.hpp:108
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getOffsetX(TOffsets const &offsets=TOffsets()) -> Idx< TOffsets >
Definition: Traits.hpp:87
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getOffsetZ(TOffsets const &offsets=TOffsets()) -> Idx< TOffsets >
Definition: Traits.hpp:103
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getOffsetY(TOffsets const &offsets=TOffsets()) -> Idx< TOffsets >
Definition: Traits.hpp:95
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getDepth(TExtent const &extent=TExtent()) -> Idx< TExtent >
Definition: Traits.hpp:121
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getWidth(TExtent const &extent=TExtent()) -> Idx< TExtent >
Definition: Traits.hpp:95