DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
DeviceStorage.cpp
Go to the documentation of this file.
1/// @file DeviceStorage.cpp
2/// @brief Host-backend implementation of @ref DNDS::DeviceStorage "DeviceStorage" and the
3/// #deviceStorageBase_deleter helper.
4
5#include "DeviceStorage.hpp"
6#include "DeviceStorage.hxx"
7
8namespace DNDS
9{
11
13 {
14 delete p;
15 }
16
17 // DNDS_DEVICE_STORAGE_BASE_DELETER_INST(int, )
18 // DNDS_DEVICE_STORAGE_BASE_DELETER_INST(double, )
19 // DNDS_DEVICE_STORAGE_BASE_DELETER_INST(rowsize, )
20 // DNDS_DEVICE_STORAGE_BASE_DELETER_INST(real, )
21 // DNDS_DEVICE_STORAGE_BASE_DELETER_INST(index, )
22
23 // * explicit instantiation of device storage
24
25 // DNDS_DEVICE_STORAGE_INST(int, DeviceBackend::Host, )
26 // DNDS_DEVICE_STORAGE_INST(double, DeviceBackend::Host, )
27 //! how to resolve int-rowsize duplicate?
28 // DNDS_DEVICE_STORAGE_INST(rowsize, DeviceBackend::Host, )
29 // DNDS_DEVICE_STORAGE_INST(real, DeviceBackend::Host, )
30 // DNDS_DEVICE_STORAGE_INST(index, DeviceBackend::Host, )
31
32 // 1. specialize DeviceStorage
33 template <>
35 {
37 // std::vector<T> data;
38 size_t _size = 0;
39 uint8_t *data = nullptr;
40
41 public:
42 explicit DeviceStorage(size_t n) : // data(n),
43 _size(n)
44 {
45 }
46
47 uint8_t *raw_ptr() override
48 {
49 // return reinterpret_cast<void *>(data.data());
50 // ! point-back design:
51 return data;
52 }
53 void copy_host_to_device(uint8_t *host_ptr, size_t n_bytes) override
54 {
55 DNDS_assert_info(n_bytes == bytes(), "bytes size mismatch");
56 auto *host_T_ptr = reinterpret_cast<uint8_t *>(host_ptr);
57 // std::copy(host_T_ptr, host_T_ptr + data.size(), data.begin());
58 // ! point-back design:
59 data = host_T_ptr;
60 }
61 void copy_device_to_host(uint8_t *host_ptr, size_t n_bytes) override
62 {
63 DNDS_assert_info(n_bytes == bytes(), "bytes size mismatch");
64 auto *host_T_ptr = reinterpret_cast<uint8_t *>(host_ptr);
65 // std::copy(data.begin(), data.end(), host_T_ptr);
66 // ! point-back design:
67 // do nothing
68 }
69 void copy_to_device(uint8_t *device_ptr_dst, size_t n_bytes) override
70 {
71 DNDS_assert_info(n_bytes == bytes(), "bytes size mismatch");
72 auto *device_T_ptr_dst = reinterpret_cast<uint8_t *>(device_ptr_dst);
73 // ! point-back design:
74 // do nothing
75 }
76
77 [[nodiscard]] size_t bytes() const override
78 {
79 // return data.size() * sizeof(T);
80 // ! point-back design:
81 return _size;
82 }
83 [[nodiscard]] DeviceBackend backend() const override
84 {
86 }
87 };
88
90 {
91 // return std::make_unique<DeviceStorage<T, DeviceBackend::CUDA>>(n_elem);
93 }
95 {
96 // return std::make_shared<DeviceStorage<T, DeviceBackend::CUDA>>(n_elem);
98 }
99}
Device memory abstraction layer with backend-specific storage and factory creation.
Reserved for template implementations of #DeviceStorage primitives.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Definition Errors.hpp:113
Abstract interface to a byte buffer owned by a specific backend.
how to resolve int-rowsize duplicate?
DeviceBackend backend() const override
Which backend the buffer lives on.
uint8_t * raw_ptr() override
Raw byte pointer to the underlying storage.
void copy_to_device(uint8_t *device_ptr_dst, size_t n_bytes) override
Device-to-device copy of n_bytes into device_ptr_dst.
size_t bytes() const override
Buffer size in bytes.
void copy_device_to_host(uint8_t *host_ptr, size_t n_bytes) override
Copy n_bytes from this device buffer into host_ptr.
void copy_host_to_device(uint8_t *host_ptr, size_t n_bytes) override
Copy n_bytes from host_ptr into this device buffer.
Compile-time-specialised storage class; one definition per DeviceBackend.
the host side operators are provided as implemented
void deviceStorageBase_deleter(DeviceStorageBase *p)
Stateless deleter for DeviceStorageBase that works across shared-library boundaries where the vtable ...
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
@ Host
Plain CPU memory.
std::unique_ptr< DeviceStorageBase, std::function< void(DeviceStorageBase *)> > t_supDeviceStorageBase
Owning unique pointer to a DeviceStorageBase with cross-DLL-safe deleter.
std::shared_ptr< DeviceStorageBase > t_sspDeviceStorageBase
Shared pointer equivalent of t_supDeviceStorageBase.
static t_supDeviceStorageBase device_storage_create_unique(DeviceBackend backend, size_t n_bytes)
static t_sspDeviceStorageBase device_storage_create_shared(DeviceBackend backend, size_t n_bytes)
Eigen::Vector3d n(1.0, 0.0, 0.0)