From a3e95e9d8bc6c69e300e8632a9ae14df76112a2c Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Mon, 16 Sep 2024 19:12:17 -0500 Subject: [PATCH] Factoring out allocator cache --- libs/core/allocator_support/CMakeLists.txt | 2 +- .../thread_local_caching_allocator.hpp | 130 +++++++----------- .../src/thread_local_caching_allocator.cpp | 111 +++++++++++++++ libs/core/async_base/CMakeLists.txt | 4 +- .../include/hpx/async_base/dataflow.hpp | 9 +- libs/core/async_combinators/CMakeLists.txt | 3 +- .../hpx/async_combinators/when_all.hpp | 4 +- .../include/hpx/concurrency/stack.hpp | 8 +- libs/core/concurrency/tests/unit/stack.cpp | 8 +- libs/core/execution/CMakeLists.txt | 3 +- .../hpx/execution/detail/future_exec.hpp | 9 +- libs/core/executors/CMakeLists.txt | 3 +- .../hpx/executors/parallel_executor.hpp | 9 +- libs/core/futures/CMakeLists.txt | 3 +- .../futures/include/hpx/futures/future.hpp | 37 ++--- .../include/hpx/futures/futures_factory.hpp | 7 +- .../hpx/futures/packaged_continuation.hpp | 4 +- libs/core/lcos_local/CMakeLists.txt | 3 +- .../include/hpx/lcos_local/and_gate.hpp | 7 +- libs/full/async_distributed/CMakeLists.txt | 2 +- .../detail/async_implementations.hpp | 48 +++---- 21 files changed, 226 insertions(+), 188 deletions(-) create mode 100644 libs/core/allocator_support/src/thread_local_caching_allocator.cpp diff --git a/libs/core/allocator_support/CMakeLists.txt b/libs/core/allocator_support/CMakeLists.txt index 1e5bcb0f10ab..07f9bb77f40e 100644 --- a/libs/core/allocator_support/CMakeLists.txt +++ b/libs/core/allocator_support/CMakeLists.txt @@ -42,7 +42,7 @@ set(allocator_support_compat_headers ) # cmake-format: on -set(allocator_support_sources) +set(allocator_support_sources thread_local_caching_allocator.cpp) include(HPX_AddModule) add_hpx_module( diff --git a/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp b/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp index 0afd89a7c3fe..af8759a7e708 100644 --- a/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp +++ b/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -21,9 +22,18 @@ namespace hpx::util { !((defined(HPX_HAVE_CUDA) && defined(__CUDACC__)) || \ defined(HPX_HAVE_HIP)) + namespace detail { + + HPX_CORE_EXPORT void init_allocator_cache( + std::function&& clear_cache); + HPX_CORE_EXPORT std::pair + allocate_from_cache() noexcept; + HPX_CORE_EXPORT [[nodiscard]] bool cache_empty() noexcept; + HPX_CORE_EXPORT void return_to_cache(void* p, std::size_t n) noexcept; + } // namespace detail + /////////////////////////////////////////////////////////////////////////// - template