alpaka
Abstraction Library for Parallel Kernel Acceleration
DeviceGlobalCpu.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 
10 
11 #include <type_traits>
12 
13 // memcpy specialization for device global variables
14 namespace alpaka
15 {
16 
17  namespace detail
18  {
19  template<typename T>
21  {
23  };
24 
25  template<typename T>
27  {
29  };
30 
31  template<typename T>
33  {
35  };
36 
37  template<typename T>
39  {
41  };
42 
43  template<typename T>
45  {
47  };
48  } // namespace detail
49 
50  template<
51  concepts::Tag TTag,
52  typename TViewSrc,
53  typename TTypeDst,
54  typename TQueue,
55  typename std::enable_if_t<
56  std::is_same_v<TTag, TagCpuOmp2Blocks> || std::is_same_v<TTag, TagCpuOmp2Threads>
57  || std::is_same_v<TTag, TagCpuSerial> || std::is_same_v<TTag, TagCpuTbbBlocks>
58  || std::is_same_v<TTag, TagCpuThreads>,
59  int>
60  = 0>
62  TQueue& queue,
64  TViewSrc const& viewSrc) -> void
65  {
66  using Type = std::remove_const_t<std::remove_all_extents_t<TTypeDst>>;
67  auto extent = getExtents(viewSrc);
68  auto view = alpaka::ViewPlainPtr<DevCpu, Type, alpaka::Dim<decltype(extent)>, alpaka::Idx<decltype(extent)>>(
69  reinterpret_cast<Type*>(const_cast<std::remove_const_t<TTypeDst>*>(&viewDst)),
70  alpaka::getDev(queue),
71  extent);
72  enqueue(queue, createTaskMemcpy(std::forward<decltype(view)>(view), viewSrc, extent));
73  }
74 
75  template<
76  concepts::Tag TTag,
77  typename TTypeSrc,
78  typename TViewDstFwd,
79  typename TQueue,
80  typename std::enable_if_t<
81  std::is_same_v<TTag, TagCpuOmp2Blocks> || std::is_same_v<TTag, TagCpuOmp2Threads>
82  || std::is_same_v<TTag, TagCpuSerial> || std::is_same_v<TTag, TagCpuTbbBlocks>
83  || std::is_same_v<TTag, TagCpuThreads>,
84  int>
85  = 0>
87  TQueue& queue,
88  TViewDstFwd&& viewDst,
90  {
91  using Type = std::remove_all_extents_t<TTypeSrc>;
92  auto extent = getExtents(viewDst);
93  auto view = alpaka::ViewPlainPtr<DevCpu, Type, alpaka::Dim<decltype(extent)>, alpaka::Idx<decltype(extent)>>(
94  reinterpret_cast<Type*>(&viewSrc),
95  alpaka::getDev(queue),
96  extent);
97  enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), view, extent));
98  }
99 
100  template<
101  concepts::Tag TTag,
102  typename TExtent,
103  typename TViewSrc,
104  typename TTypeDst,
105  typename TQueue,
106  typename std::enable_if_t<
107  std::is_same_v<TTag, TagCpuOmp2Blocks> || std::is_same_v<TTag, TagCpuOmp2Threads>
108  || std::is_same_v<TTag, TagCpuSerial> || std::is_same_v<TTag, TagCpuTbbBlocks>
109  || std::is_same_v<TTag, TagCpuThreads>,
110  int>
111  = 0>
113  TQueue& queue,
115  TViewSrc const& viewSrc,
116  TExtent const& extent) -> void
117  {
118  using Type = std::remove_const_t<std::remove_all_extents_t<TTypeDst>>;
120  reinterpret_cast<Type*>(const_cast<std::remove_const_t<TTypeDst>*>(&viewDst)),
121  alpaka::getDev(queue),
122  extent);
123  enqueue(queue, createTaskMemcpy(std::forward<decltype(view)>(view), viewSrc, extent));
124  }
125 
126  template<
127  concepts::Tag TTag,
128  typename TExtent,
129  typename TTypeSrc,
130  typename TViewDstFwd,
131  typename TQueue,
132  typename std::enable_if_t<
133  std::is_same_v<TTag, TagCpuOmp2Blocks> || std::is_same_v<TTag, TagCpuOmp2Threads>
134  || std::is_same_v<TTag, TagCpuSerial> || std::is_same_v<TTag, TagCpuTbbBlocks>
135  || std::is_same_v<TTag, TagCpuThreads>,
136  int>
137  = 0>
139  TQueue& queue,
140  TViewDstFwd&& viewDst,
142  TExtent const& extent) -> void
143  {
144  using Type = std::remove_all_extents_t<TTypeSrc>;
146  reinterpret_cast<Type*>(&viewSrc),
147  alpaka::getDev(queue),
148  extent);
149  enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), view, extent));
150  }
151 } // namespace alpaka
The CPU device handle.
Definition: DevCpu.hpp:56
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
concept Tag
Definition: Tag.hpp:46
The alpaka accelerator library.
typename trait::IdxType< T >::type Idx
Definition: Traits.hpp:29
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd &&viewDst, TViewSrc const &viewSrc, TExtent const &extent)
Creates a memory copy task.
Definition: Traits.hpp:253
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T >>
Definition: Traits.hpp:59
ALPAKA_FN_HOST auto getDev(T const &t)
Definition: Traits.hpp:68
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
Definition: Traits.hpp:47
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition: Traits.hpp:19
The memory view to wrap plain pointers.