@@ -52,6 +52,36 @@ void destroy_n(ForwardIt first, Size n) {
5252class buffer_recycler {
5353 // Public interface
5454public:
55+ #if defined(CPPUDDLE_DEACTIVATE_BUFFER_RECYCLING)
56+
57+ // Warn about suboptimal performance without recycling
58+ #pragma message \
59+ " Warning: Building without buffer recycling! Use only for performance testing! \
60+ For better performance configure CPPuddle with CPPUDDLE_WITH_BUFFER_RECYCLING=ON!"
61+
62+ template <typename T, typename Host_Allocator>
63+ static T *get (size_t number_elements, bool manage_content_lifetime = false ,
64+ std::optional<size_t > location_hint = std::nullopt ,
65+ std::optional<size_t > device_id = std::nullopt ) {
66+
67+ return Host_Allocator{}.allocate (number_elements);
68+ }
69+ // / Marks an buffer as unused and fit for reusage
70+ template <typename T, typename Host_Allocator>
71+ static void mark_unused (T *p, size_t number_elements,
72+ std::optional<size_t > location_hint = std::nullopt ,
73+ std::optional<size_t > device_id = std::nullopt ) {
74+ return Host_Allocator{}.deallocate (p, number_elements);
75+ }
76+ // / Fail when internal reference counting is used but recylcing is turned off
77+ template <typename T, typename Host_Allocator>
78+ static void increase_usage_counter (T *p, size_t number_elements) noexcept {
79+ std::cerr << " ERROR: CPPuddle v0.2.1 does not support internal reference counting "
80+ " with CPPUDDLE_WITH_BUFFER_RECYCLING=OFF. Please re-enable buffer recycling! Aborting..."
81+ << std::endl;
82+ abort ();
83+ }
84+ #else
5585 // / Returns and allocated buffer of the requested size - this may be a reused
5686 // / buffer
5787 template <typename T, typename Host_Allocator>
@@ -79,13 +109,6 @@ class buffer_recycler {
79109 return buffer_manager<T, Host_Allocator>::mark_unused (p, number_elements);
80110 }
81111 }
82-
83- template <typename T, typename Host_Allocator>
84- static void register_allocator_counters_with_hpx (void ) {
85- std::cerr << " Warning: CPPuddle v0.2.1 does not yet support HPX counters "
86- " -- this operation will be ignored!"
87- << std::endl;
88- }
89112 // / Increase the reference coutner of a buffer
90113 template <typename T, typename Host_Allocator>
91114 static void increase_usage_counter (T *p, size_t number_elements) noexcept {
@@ -96,6 +119,14 @@ class buffer_recycler {
96119 p, number_elements);
97120 }
98121 }
122+ #endif
123+
124+ template <typename T, typename Host_Allocator>
125+ static void register_allocator_counters_with_hpx (void ) {
126+ std::cerr << " Warning: CPPuddle v0.2.1 does not yet support HPX counters "
127+ " -- this operation will be ignored!"
128+ << std::endl;
129+ }
99130 // / Deallocate all buffers, no matter whether they are marked as used or not
100131 static void clean_all () {
101132 std::lock_guard<std::mutex> guard (mut);
@@ -661,6 +692,11 @@ struct aggressive_recycle_allocator {
661692 void deallocate (T *p, std::size_t n) {
662693 buffer_recycler::mark_unused<T, Host_Allocator>(p, n);
663694 }
695+ void increase_usage_counter (T *p, size_t n) {
696+ buffer_recycler::increase_usage_counter<T, Host_Allocator>(p, n);
697+ }
698+
699+ #ifndef CPPUDDLE_DEACTIVATE_AGGRESSIVE_ALLOCATORS
664700 template <typename ... Args>
665701 inline void construct (T *p, Args... args) noexcept {
666702 // Do nothing here - we reuse the content of the last owner
@@ -669,9 +705,17 @@ struct aggressive_recycle_allocator {
669705 // Do nothing here - Contents will be destroyed when the buffer manager is
670706 // destroyed, not before
671707 }
672- void increase_usage_counter (T *p, size_t n) {
673- buffer_recycler::increase_usage_counter<T, Host_Allocator>(p, n);
708+ #else
709+ // Warn about suboptimal performance without recycling
710+ #pragma message \
711+ " Warning: Building without content reusage for aggressive allocators! \
712+ For better performance configure with CPPUDDLE_WITH_AGGRESSIVE_CONTENT_RECYCLING=ON !"
713+ template <typename ... Args>
714+ inline void construct (T *p, Args... args) noexcept {
715+ ::new (static_cast <void *>(p)) T (std::forward<Args>(args)...);
674716 }
717+ void destroy (T *p) { p->~T (); }
718+ #endif
675719};
676720template <typename T, typename U, typename Host_Allocator>
677721constexpr bool
0 commit comments