44#pragma once
55
66#include " gprat/detail/config.hpp"
7- #include " gprat/performance_counters.hpp"
87
98#include < hpx/serialization/serialize_buffer.hpp>
109#include < span>
1110
1211GPRAT_NS_BEGIN
1312
13+ namespace detail
14+ {
15+ void *allocate_tile_data (std::size_t num_bytes);
16+ void deallocate_tile_data (void *p, std::size_t num_bytes);
17+
18+ template <class T >
19+ struct tile_data_allocator
20+ {
21+ typedef T value_type;
22+
23+ tile_data_allocator () = default ;
24+
25+ template <class U >
26+ constexpr tile_data_allocator (const tile_data_allocator<U> &) noexcept
27+ { }
28+
29+ [[nodiscard]] T *allocate (std::size_t n)
30+ {
31+ if (n > (std::numeric_limits<std::size_t >::max)() / sizeof (T))
32+ {
33+ throw std::bad_array_new_length ();
34+ }
35+
36+ if (auto p = static_cast <T *>(allocate_tile_data (n * sizeof (T))))
37+ {
38+ return p;
39+ }
40+
41+ throw std::bad_alloc ();
42+ }
43+
44+ void deallocate (T *p, std::size_t n) noexcept { deallocate_tile_data (p, n * sizeof (T)); }
45+ };
46+
47+ template <class T , class U >
48+ bool operator ==(const tile_data_allocator<T> &, const tile_data_allocator<U> &)
49+ {
50+ return true ;
51+ }
52+
53+ template <class T , class U >
54+ bool operator !=(const tile_data_allocator<T> &, const tile_data_allocator<U> &)
55+ {
56+ return false ;
57+ }
58+ } // namespace detail
59+
1460/* *
1561 * @brief Non-mutable reference-counted dynamic array of a given type T.
1662 * This class represents a simple reference-counted non-resizeable buffer with elements of type T.
@@ -25,7 +71,7 @@ template <typename T>
2571class const_tile_data
2672{
2773 protected:
28- typedef hpx::serialization::serialize_buffer<T> cpu_buffer_type;
74+ typedef hpx::serialization::serialize_buffer<T, detail::tile_data_allocator<T> > cpu_buffer_type;
2975
3076 struct hold_reference
3177 {
@@ -38,25 +84,12 @@ class const_tile_data
3884 cpu_buffer_type data_;
3985 };
4086
41- // In case we want pooling down the road...
42- static T *allocate (std::size_t n)
43- {
44- track_tile_data_allocation (n);
45- return new T[n];
46- }
47-
48- static void deallocate (T *p) noexcept
49- {
50- track_tile_data_deallocation (0 ); // we don't know here
51- delete[] p;
52- }
53-
5487 public:
5588 const_tile_data () = default ;
5689
5790 // Create a new (uninitialized) tile_data of the given size.
5891 explicit const_tile_data (std::size_t size) :
59- cpu_data_(allocate( size), size, cpu_buffer_type::take, &const_tile_data::deallocate )
92+ cpu_data_(size)
6093 { }
6194
6295 // Create a tile_data which acts as a proxy to a part of the embedded array.
@@ -85,10 +118,12 @@ class const_tile_data
85118 return { cpu_data_.data (), cpu_data_.size () };
86119 }
87120
121+ friend bool operator ==(const const_tile_data &a, const const_tile_data &b) noexcept
122+ {
123+ return a.cpu_data_ == b.cpu_data_ ;
124+ }
125+
88126 protected:
89- // Serialization support: even if all of the code below runs on one
90- // locality only, we need to provide an (empty) implementation for the
91- // serialization as all arguments passed to actions have to support this.
92127 friend class hpx ::serialization::access;
93128
94129 template <typename Archive>
0 commit comments