Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion thrust/thrust/system/hpx/detail/execution_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/detail/any_system_tag.h>
#include <thrust/system/cpp/detail/execution_policy.h>
#include <thrust/system/hpx/detail/runtime.h>

#include <hpx/execution.hpp>

Expand Down Expand Up @@ -235,7 +236,7 @@ auto to_hpx_execution_policy(const execution_policy<Derived>& exec) noexcept
else
{
(void) exec;
return ::hpx::execution::par;
return ::hpx::execution::par.on(runtime.default_executor);
}
}

Expand Down
16 changes: 12 additions & 4 deletions thrust/thrust/system/hpx/detail/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# pragma system_header
#endif // no system header

#include <hpx/executors/fork_join_executor.hpp>
#include <hpx/manage_runtime.hpp>

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -111,18 +112,24 @@ struct init_runtime
{
(void) runtime.stop();
}
};

struct manage_runtime
{
init_runtime init;
::hpx::execution::experimental::fork_join_executor default_executor;

static init_runtime& get()
static manage_runtime& get()
{
// The HPX runtime implicitly depends on thread-local storage, making this object thread_local ensures the correct
// sequencing of destructors. Since this function is only called from initialization of a global variable, only one
// instance of the runtime will be created.
static thread_local init_runtime m;
static thread_local manage_runtime m;
return m;
}
};

inline init_runtime& runtime = init_runtime::get();
inline manage_runtime& runtime = manage_runtime::get();

template <typename F>
inline decltype(auto) run_as_hpx_thread(const F& f)
Expand All @@ -132,7 +139,8 @@ inline decltype(auto) run_as_hpx_thread(const F& f)
return f();
}

return ::hpx::run_as_hpx_thread(f);
constexpr ::hpx::launch::async_policy policy(::hpx::threads::thread_priority::bound);
return ::hpx::run_as_hpx_thread(policy, f);
}

} // end namespace detail
Expand Down
8 changes: 5 additions & 3 deletions thrust/thrust/system/hpx/memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif // no system header
#include <thrust/mr/fancy_pointer_resource.h>
#include <thrust/mr/new.h>
#include <thrust/system/hpx/detail/runtime.h>
#include <thrust/system/hpx/pointer.h>

#include <hpx/parallel/algorithms/for_loop.hpp>
Expand All @@ -54,9 +55,10 @@ class topology_resource final : public mr::memory_resource<>

// touch first byte of every page
const auto page_size = ::hpx::threads::get_memory_page_size();
::hpx::experimental::for_loop_strided(::hpx::execution::par, ptr, ptr + bytes, page_size, [](std::byte* it) {
*it = {};
});
::hpx::experimental::for_loop_strided(
::hpx::execution::par.on(runtime.default_executor), ptr, ptr + bytes, page_size, [](std::byte* it) {
*it = {};
});

return ptr;
}
Expand Down