Skip to content

Commit

Permalink
Specify numa policy in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
maikel committed Nov 2, 2023
1 parent b496f23 commit bb39d12
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/benchmark/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct numa_deleter {
};

template <class Pool, class RunThread>
void my_main(int argc, char** argv) {
void my_main(int argc, char** argv, exec::numa_policy* policy = exec::get_numa_policy()) {
int nthreads = std::thread::hardware_concurrency();
if (argc > 1) {
nthreads = std::atoi(argv[1]);
Expand All @@ -112,7 +112,6 @@ void my_main(int argc, char** argv) {
std::atomic<bool> stop{false};
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::size_t buffer_size = 1000 << 20;
exec::numa_policy* policy = exec::get_numa_policy();
for (std::size_t i = 0; i < static_cast<std::size_t>(nthreads); ++i) {
exec::numa_allocator<char> alloc(policy->thread_index_to_node(i));
buffers.push_back(std::unique_ptr<char, numa_deleter>{alloc.allocate(buffer_size), numa_deleter{buffer_size, alloc}});
Expand All @@ -128,7 +127,8 @@ void my_main(int argc, char** argv) {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char>{buffers[i].get(), buffer_size},
#endif
std::ref(stop));
std::ref(stop),
policy);
}
std::size_t nRuns = 100;
std::size_t warmup = 1;
Expand Down
13 changes: 11 additions & 2 deletions examples/benchmark/static_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down Expand Up @@ -80,7 +83,13 @@ struct RunThread {
}
};

struct my_numa_distribution : public exec::default_numa_policy {
std::size_t thread_index_to_node(std::size_t index) override {
return default_numa_policy::thread_index_to_node(2 * index);
}
};

int main(int argc, char** argv) {
my_main<exec::static_thread_pool, RunThread>(argc, argv);
my_numa_distribution numa{};
my_main<exec::static_thread_pool, RunThread>(argc, argv, &numa);
}
5 changes: 4 additions & 1 deletion examples/benchmark/static_thread_pool_bulk_enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
while (true) {
barrier.arrive_and_wait();
if (stop.load()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
while (true) {
barrier.arrive_and_wait();
Expand Down
5 changes: 4 additions & 1 deletion examples/benchmark/static_thread_pool_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down
5 changes: 4 additions & 1 deletion examples/benchmark/static_thread_pool_nested_old.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down
5 changes: 4 additions & 1 deletion examples/benchmark/static_thread_pool_old.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down
5 changes: 4 additions & 1 deletion examples/benchmark/tbb_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down
5 changes: 4 additions & 1 deletion examples/benchmark/tbb_thread_pool_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ struct RunThread {
#ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE
[[maybe_unused]] std::span<char> buffer,
#endif
std::atomic<bool>& stop) {
std::atomic<bool>& stop,
exec::numa_policy* numa) {
std::size_t numa_node = numa->thread_index_to_node(tid);
numa->bind_to_node(numa_node);
auto scheduler = pool.get_scheduler();
std::mutex mut;
std::condition_variable cv;
Expand Down

0 comments on commit bb39d12

Please sign in to comment.