CPPuddle
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. \
24 For 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 
31 namespace cppuddle {
32 
33 #if defined(CPPUDDLE_HAVE_HPX) && defined(CPPUDDLE_HAVE_HPX_MUTEX)
34 using mutex_t = hpx::spinlock_no_backoff;
35 #else
36 using 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 //
50 constexpr size_t number_instances = CPPUDDLE_HAVE_NUMBER_BUCKETS;
51 static_assert(number_instances >= 1);
52 constexpr size_t max_number_gpus = CPPUDDLE_HAVE_MAX_NUMBER_GPUS;
53 #ifndef CPPUDDLE_HAVE_HPX
54 static_assert(max_number_gpus == 1, "Non HPX builds do not support multigpu");
55 #endif
56 static_assert(max_number_gpus > 0);
57 
59 inline 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 #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