CPPuddle
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1// Copyright (c) 2023-2024 Gregor Daiß
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef CPPUDDLE_CONFIG_HPP
7#define CPPUDDLE_CONFIG_HPP
8
9
10// Mutex configuration
11//
12#if defined(CPPUDDLE_HAVE_HPX) && defined(CPPUDDLE_HAVE_HPX_MUTEX)
13#include <hpx/mutex.hpp>
14#else
15#include <mutex>
16#endif
17
18// HPX-aware configuration
19//
20#ifdef CPPUDDLE_HAVE_HPX
21#ifndef CPPUDDLE_HAVE_HPX_AWARE_ALLOCATORS
22#pragma message \
23"Warning: CPPuddle build with HPX support but without HPX-aware allocators enabled. \
24For better performance configure CPPuddle with CPPUDDLE_WITH_HPX_AWARE_ALLOCATORS=ON!"
25#else
26// include runtime to get HPX thread IDs required for the HPX-aware allocators
27#include <hpx/include/runtime.hpp>
28#endif
29#endif
30
31namespace cppuddle {
32
33#if defined(CPPUDDLE_HAVE_HPX) && defined(CPPUDDLE_HAVE_HPX_MUTEX)
34using mutex_t = hpx::spinlock_no_backoff;
35#else
36using mutex_t = std::mutex;
37#endif
38
39// Recycling configuration
40// TODO Add warnings here
41
42// Aggressive recycling configuration
43// TODO Add warning here
44
45// Aggregation Debug configuration
46// TODO Add warning here
47
48// Thread and MultiGPU configuration
49//
50constexpr size_t number_instances = CPPUDDLE_HAVE_NUMBER_BUCKETS;
51static_assert(number_instances >= 1);
52constexpr size_t max_number_gpus = CPPUDDLE_HAVE_MAX_NUMBER_GPUS;
53#ifndef CPPUDDLE_HAVE_HPX
54static_assert(max_number_gpus == 1, "Non HPX builds do not support multigpu");
55#endif
56static_assert(max_number_gpus > 0);
57
59inline size_t get_device_id(const size_t number_gpus) {
60#if defined(CPPUDDLE_HAVE_HPX)
61 assert(number_gpus <= max_number_gpus);
62 return hpx::get_worker_thread_num() % number_gpus;
63#else
64 return 0;
65#endif
66}
67
68} // end namespace cppuddle
69
70#if HPX_VERSION_FULL >= 0x011100
71#define CPPUDDLE_HPX_EXECUTOR_SPECIALIZATION_NS hpx::execution::experimental
72#else
73#define CPPUDDLE_HPX_EXECUTOR_SPECIALIZATION_NS hpx::parallel::execution
74#endif
75
76#endif
Definition config.hpp:31
size_t get_device_id(const size_t number_gpus)
Uses HPX thread information to determine which GPU should be used.
Definition config.hpp:59
constexpr size_t max_number_gpus
Definition config.hpp:52
std::mutex mutex_t
Definition config.hpp:36
constexpr size_t number_instances
Definition config.hpp:50