MUDA
Loading...
Searching...
No Matches
kernel_destruct.inl
1#include <muda/type_traits/type_label.h>
4#include <muda/buffer/buffer_2d_view.h>
5#include <muda/buffer/buffer_3d_view.h>
6
7namespace muda::details::buffer
8{
9// destruct 0D
10template <typename T>
11MUDA_INLINE MUDA_HOST void kernel_destruct(cudaStream_t stream, VarView<T> view)
12{
13 // no need to destruct trivially destructible types
14 if constexpr(muda::is_trivially_destructible_v<T>)
15 return;
16
17 ParallelFor(1, 1, 0, stream)
18 .apply(1, [view] __device__(int i) mutable { view.data()->~T(); });
19}
20
21// destruct 1D
22template <typename T>
23MUDA_INLINE MUDA_HOST void kernel_destruct(int grid_dim,
24 int block_dim,
25 cudaStream_t stream,
26 BufferView<T> buffer_view)
27{
28 // no need to destruct trivially destructible types
29 if constexpr(muda::is_trivially_destructible_v<T>)
30 return;
31
32 ParallelFor(grid_dim, block_dim, size_t{0}, stream)
33 .apply(static_cast<int>(buffer_view.size()),
34 [buffer_view] __device__(int i) mutable
35 { buffer_view.data(i)->~T(); });
36}
37
38// destruct 2D
39template <typename T>
40MUDA_INLINE MUDA_HOST void kernel_destruct(int grid_dim,
41 int block_dim,
42 cudaStream_t stream,
43 Buffer2DView<T> buffer_view)
44{
45 // no need to destruct trivially destructible types
46 if constexpr(muda::is_trivially_destructible_v<T>)
47 return;
48
49 ParallelFor(grid_dim, block_dim, 0, stream)
50 .apply(buffer_view.total_size(),
51 [buffer_view] __device__(int i) mutable
52 { buffer_view.data(i)->~T(); });
53}
54
55// destruct 3D
56template <typename T>
57MUDA_INLINE MUDA_HOST void kernel_destruct(int grid_dim,
58 int block_dim,
59 cudaStream_t stream,
60 Buffer3DView<T> buffer_view)
61{
62 // no need to destruct trivially destructible types
63 if constexpr(muda::is_trivially_destructible_v<T>)
64 return;
65
66 ParallelFor(grid_dim, block_dim, 0, stream)
67 .apply(buffer_view.total_size(),
68 [buffer_view] __device__(int i) mutable
69 { buffer_view.data(i)->~T(); });
70}
71} // namespace muda::details::buffer
A view interface for any array-like liner memory, which can be constructed from DeviceBuffer/DeviceVe...
A frequently used parallel for loop, DynamicBlockDim and GridStrideLoop strategy are provided,...