DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
DeviceStorageHelper.hpp
Go to the documentation of this file.
1#pragma once
2/// @file DeviceStorageHelper.hpp
3/// @brief Helpers for shipping an array-of-views (e.g., `ArrayDeviceView`)
4/// to the device in one contiguous buffer.
5
6#include "DeviceStorage.hpp"
7#include <type_traits>
8#include "Vector.hpp"
9
10namespace DNDS
11{
12 /**
13 * @brief Contiguous #host_device_vector of non-owning views, mirrored on a device.
14 *
15 * @details Many CUDA kernels need "a vector of array views" -- e.g., the
16 * per-cell adjacency views for a mesh, bundled into one flat array on the
17 * GPU. This helper takes a factory callback that produces the `i`-th view,
18 * stores all views in a `host_device_vector`, and pushes the result to
19 * the chosen backend in one call.
20 *
21 * @tparam TView View type to store (must be trivially copyable).
22 * @tparam B Target device backend.
23 */
24 template <class TView, DeviceBackend B>
26 {
27 static_assert(std::is_trivially_copyable_v<TView> && std::is_default_constructible_v<TView>,
28 "view elements must be trivially_copyable and default_constructible");
29 /// @brief Vector of per-entry views, with a device mirror.
31
32 /// @brief Build `nViews` views via `GetView(i)` and transfer them to device.
33 template <class TGetView>
34 deviceViewVector(int32_t nViews, TGetView &&GetView)
35 {
36 views.resize(nViews);
37 for (int32_t i = 0; i < nViews; i++)
38 views[i] = GetView(i);
39 views.to_device(B);
40 }
41
42 /// @brief Device-side span over the stored views.
44 {
45 return views.template deviceView<B>();
46 }
47 };
48}
Device memory abstraction layer with backend-specific storage and factory creation.
Host-device vector types with optional GPU storage and device-side views.
Host + optional device vector of trivially copyable T.
Definition Vector.hpp:217
the host side operators are provided as implemented
Contiguous host_device_vector of non-owning views, mirrored on a device.
host_device_vector< TView > views
Vector of per-entry views, with a device mirror.
deviceViewVector(int32_t nViews, TGetView &&GetView)
Build nViews views via GetView(i) and transfer them to device.
auto deviceView()
Device-side span over the stored views.