From 5f69e24f89cc536e0393ff5998ad9db7a59f557e 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 | 2 +- .../include/hpx/async_base/dataflow.hpp | 7 +- libs/core/async_combinators/CMakeLists.txt | 1 - .../hpx/async_combinators/when_all.hpp | 4 +- libs/core/execution/CMakeLists.txt | 1 - .../hpx/execution/detail/future_exec.hpp | 7 +- libs/core/executors/CMakeLists.txt | 1 - .../hpx/executors/parallel_executor.hpp | 7 +- libs/core/futures/CMakeLists.txt | 1 - .../futures/include/hpx/futures/future.hpp | 36 ++--- .../include/hpx/futures/futures_factory.hpp | 7 +- .../hpx/futures/packaged_continuation.hpp | 4 +- libs/core/lcos_local/CMakeLists.txt | 1 - .../include/hpx/lcos_local/and_gate.hpp | 7 +- .../detail/async_implementations.hpp | 46 +++---- 18 files changed, 210 insertions(+), 165 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