6#ifndef RECYCLING_KOKKOS_VIEW_HPP
7#define RECYCLING_KOKKOS_VIEW_HPP
8#include <Kokkos_Core.hpp>
20namespace memory_recycling {
24template<
typename element_type,
typename alloc_type>
40template <
typename kokkos_type,
typename alloc_type,
typename element_type>
44 size_t total_elements{0};
45 std::shared_ptr<element_type> data_ref_counter;
46 static_assert(std::is_same_v<element_type, typename alloc_type::value_type>);
50 template <
class... Args>
53 alloc.allocate(kokkos_type::required_allocation_size(args...) /
54 sizeof(element_type)),
56 total_elements(kokkos_type::required_allocation_size(args...) /
57 sizeof(element_type)),
59 data_ref_counter(this->data(),
view_deleter<element_type, alloc_type>(
60 alloc, total_elements)) {}
64 : kokkos_type(other), allocator(other.allocator) {
65 data_ref_counter = other.data_ref_counter;
66 total_elements = other.total_elements;
71 data_ref_counter = other.data_ref_counter;
72 allocator = other.allocator;
73 kokkos_type::operator=(other);
74 total_elements = other.total_elements;
80 : kokkos_type(other), allocator(other.allocator) {
81 data_ref_counter = other.data_ref_counter;
82 total_elements = other.total_elements;
87 data_ref_counter = other.data_ref_counter;
88 allocator = other.allocator;
89 kokkos_type::operator=(other);
90 total_elements = other.total_elements;
102template <
typename kokkos_type,
typename alloc_type,
typename element_type>
105 size_t total_elements{0};
106 std::shared_ptr<element_type> data_ref_counter;
110 static_assert(std::is_same_v<element_type, typename alloc_type::value_type>);
111 template <
typename... Args,
112 std::enable_if_t<
sizeof...(Args) == kokkos_type::rank,
bool> =
true>
115 alloc_type{}.allocate(kokkos_type::required_allocation_size(args...) /
116 sizeof(element_type)),
118 total_elements(kokkos_type::required_allocation_size(args...) /
119 sizeof(element_type)),
121 alloc_type{}, total_elements)) {}
123 template <
typename... Args,
124 std::enable_if_t<
sizeof...(Args) == kokkos_type::rank,
bool> =
true>
127 alloc_type{device_id}.allocate(kokkos_type::required_allocation_size(args...) /
128 sizeof(element_type)),
130 total_elements(kokkos_type::required_allocation_size(args...) /
131 sizeof(element_type)),
133 alloc_type{device_id}, total_elements)) {}
137 std::enable_if_t<Kokkos::is_array_layout<layout_t>::value,
bool> =
true>
140 alloc_type{device_id}.allocate(kokkos_type::required_allocation_size(layout) /
141 sizeof(element_type)),
143 total_elements(kokkos_type::required_allocation_size(layout) /
144 sizeof(element_type)),
145 data_ref_counter(this->data(),
view_deleter<element_type, alloc_type>(
146 alloc_type{device_id}, total_elements)) {}
150 : kokkos_type(other) {
151 total_elements = other.total_elements;
152 data_ref_counter = other.data_ref_counter;
158 data_ref_counter = other.data_ref_counter;
159 kokkos_type::operator=(other);
160 total_elements = other.total_elements;
166 : kokkos_type(other) {
167 data_ref_counter = other.data_ref_counter;
168 total_elements = other.total_elements;
173 data_ref_counter = other.data_ref_counter;
174 kokkos_type::operator=(other);
175 total_elements = other.total_elements;
Definition recycling_kokkos_view.hpp:41
aggregated_recycling_view(aggregated_recycling_view< kokkos_type, alloc_type, element_type > &&other) noexcept
Definition recycling_kokkos_view.hpp:78
aggregated_recycling_view< kokkos_type, alloc_type, element_type > & operator=(aggregated_recycling_view< kokkos_type, alloc_type, element_type > &&other) noexcept
Definition recycling_kokkos_view.hpp:85
~aggregated_recycling_view()
Definition recycling_kokkos_view.hpp:94
aggregated_recycling_view< kokkos_type, alloc_type, element_type > & operator=(const aggregated_recycling_view< kokkos_type, alloc_type, element_type > &other)
Definition recycling_kokkos_view.hpp:70
aggregated_recycling_view(const aggregated_recycling_view< kokkos_type, alloc_type, element_type > &other)
Definition recycling_kokkos_view.hpp:62
aggregated_recycling_view(alloc_type &alloc, Args... args)
Definition recycling_kokkos_view.hpp:51
kokkos_type view_type
Definition recycling_kokkos_view.hpp:49
Definition recycling_kokkos_view.hpp:103
kokkos_type view_type
Definition recycling_kokkos_view.hpp:109
recycling_view(recycling_view< kokkos_type, alloc_type, element_type > &&other) noexcept
Definition recycling_kokkos_view.hpp:164
~recycling_view()
Definition recycling_kokkos_view.hpp:179
recycling_view< kokkos_type, alloc_type, element_type > & operator=(recycling_view< kokkos_type, alloc_type, element_type > &&other) noexcept
Definition recycling_kokkos_view.hpp:171
recycling_view(const recycling_view< kokkos_type, alloc_type, element_type > &other)
Definition recycling_kokkos_view.hpp:148
recycling_view(const size_t device_id, Args... args)
Definition recycling_kokkos_view.hpp:125
recycling_view(Args... args)
Definition recycling_kokkos_view.hpp:113
recycling_view< kokkos_type, alloc_type, element_type > & operator=(const recycling_view< kokkos_type, alloc_type, element_type > &other)
Definition recycling_kokkos_view.hpp:157
recycling_view(std::size_t device_id, layout_t layout)
Definition recycling_kokkos_view.hpp:138
Definition recycling_kokkos_view.hpp:25
size_t total_elements
Definition recycling_kokkos_view.hpp:27
view_deleter(alloc_type alloc, size_t total_elements)
Definition recycling_kokkos_view.hpp:28
void operator()(element_type *p)
Definition recycling_kokkos_view.hpp:30
alloc_type allocator
Definition recycling_kokkos_view.hpp:26