alpaka
Abstraction Library for Parallel Kernel Acceleration
DeviceGlobalGenericSycl.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Aurora Perego
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/elem/Traits.hpp"
10 
11 #ifdef ALPAKA_ACC_SYCL_ENABLED
12 
13 # include <sycl/sycl.hpp>
14 
15 namespace alpaka
16 {
17  namespace detail
18  {
19  template<typename T>
20  struct DevGlobalTrait<TagCpuSycl, T>
21  {
22  // SYCL CPU implementation
23  using Type = sycl::ext::oneapi::experimental::device_global<T>;
24  };
25 
26  template<typename T>
27  struct DevGlobalTrait<TagGpuSyclIntel, T>
28  {
29  // SYCL GPU implementation
30  using Type = sycl::ext::oneapi::experimental::device_global<T>;
31  };
32 
33  template<typename T>
34  struct DevGlobalTrait<TagFpgaSyclIntel, T>
35  {
36  // SYCL FPGA implementation
37  using Type = sycl::ext::oneapi::experimental::device_global<T>;
38  };
39 
40  template<typename T>
41  struct DevGlobalTrait<TagGenericSycl, T>
42  {
43  // generic SYCL implementation
44  using Type = sycl::ext::oneapi::experimental::device_global<T>;
45  };
46  } // namespace detail
47 
48  // from device to host
49  template<typename TDev, bool TBlocking, typename TViewDst, typename TTypeSrc>
51  detail::QueueGenericSyclBase<TDev, TBlocking>& queue,
52  TViewDst&& viewDst,
53  sycl::ext::oneapi::experimental::device_global<TTypeSrc> const& viewSrc)
54  {
55  queue.getNativeHandle().memcpy(reinterpret_cast<void*>(getPtrNative(viewDst)), viewSrc);
56  }
57 
58  // from host to device
59  template<typename TDev, bool TBlocking, typename TTypeDst, typename TViewSrc>
61  detail::QueueGenericSyclBase<TDev, TBlocking>& queue,
62  sycl::ext::oneapi::experimental::device_global<TTypeDst>& viewDst,
63  TViewSrc const& viewSrc)
64  {
65  queue.getNativeHandle().memcpy(viewDst, reinterpret_cast<void const*>(getPtrNative(viewSrc)));
66  }
67 
68  // from device to host
69  template<typename TDev, bool TBlocking, typename TViewDst, typename TTypeSrc, typename TExtent>
71  detail::QueueGenericSyclBase<TDev, TBlocking>& queue,
72  TViewDst&& viewDst,
73  sycl::ext::oneapi::experimental::device_global<TTypeSrc> const& viewSrc,
74  TExtent extent)
75  {
77  auto size = static_cast<std::size_t>(getHeight(extent)) * static_cast<std::size_t>(getDepth(extent))
78  * static_cast<std::size_t>(getWidth(extent)) * sizeof(Elem);
79  queue.getNativeHandle().memcpy(reinterpret_cast<void*>(getPtrNative(viewDst)), viewSrc, size);
80  }
81 
82  // from host to device
83  template<typename TDev, bool TBlocking, typename TTypeDst, typename TViewSrc, typename TExtent>
85  detail::QueueGenericSyclBase<TDev, TBlocking>& queue,
86  sycl::ext::oneapi::experimental::device_global<TTypeDst>& viewDst,
87  TViewSrc const& viewSrc,
88  TExtent extent)
89  {
91  auto size = static_cast<std::size_t>(getHeight(extent)) * static_cast<std::size_t>(getDepth(extent))
92  * static_cast<std::size_t>(getWidth(extent)) * sizeof(Elem);
93  queue.getNativeHandle().memcpy(viewDst, reinterpret_cast<void const*>(getPtrNative(viewSrc)), size);
94  }
95 } // namespace alpaka
96 #endif
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
The alpaka accelerator library.
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getHeight(TExtent const &extent=TExtent()) -> Idx< TExtent >
Definition: Traits.hpp:108
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
Definition: Traits.hpp:136
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
Definition: Traits.hpp:21
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