Peano
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
1#include "tarch/Assertions.h"
2#include "Core.h"
4
9
10#ifdef CompilerHasSysinfo
11#include <sched.h>
12#endif
13
14#include <map>
15
16#if defined(SharedSYCL)
17#include <sstream>
18#include "config.h"
19
20#pragma push_macro("Dimensions")
21#pragma push_macro("assertion")
22#undef Dimensions
23#undef assertion
24#include <CL/sycl.hpp>
25#pragma pop_macro("Dimensions")
26#pragma pop_macro("assertion")
27
28tarch::logging::Log tarch::multicore::Core::_log( "tarch::multicore::Core" );
29
30namespace {
34 sycl::queue hostSyclQueue( sycl::cpu_selector_v );
35}
36
37
38sycl::queue& tarch::multicore::getHostSYCLQueue() {
39 return hostSyclQueue;
40}
41
42
47 _numberOfThreads( -1 ) {
48
49 sycl::device cpuDevice;
50 try {
51 cpuDevice = sycl::device( sycl::cpu_selector_v );
52 } catch (...) {
53 std::cerr << "Warning, failed at selecting cpu device" << std::endl;
54 std::abort();
55 }
56
57 sycl::queue cpuQueue( cpuDevice );
58 hostSyclQueue = cpuQueue;
59
60 _numberOfThreads = hostSyclQueue.get_device().get_info<sycl::info::device::max_compute_units>();
61 assertion(_numberOfThreads>0);
62
63 #if PeanoDebug>0
64 std::cout << "host (CPU) device queue:" << hostSyclQueue.get_device().get_info<sycl::info::device::name>()
65 << " with " << _numberOfThreads << " threads" << std::endl;
66 #endif
67}
68
69
71}
72
73
75 static Core instance;
76 return instance;
77}
78
79
80void tarch::multicore::Core::configure( int numberOfThreads ) {
82 if ( numberOfThreads!=_numberOfThreads ) {
83 logWarning( "configure(int)", "can not reconfigure number of threads within SYCL queue. Will work with " << numberOfThreads << " logical threads within host queue having " << _numberOfThreads << " threads" );
84 }
85 _numberOfThreads = numberOfThreads;
86 }
87}
88
89
91
92
94 return true;
95}
96
97
99 assertion(_numberOfThreads>0);
100 return _numberOfThreads;
101}
102
103
105 #ifdef CompilerHasSysinfo
106 return sched_getcpu();
107 #else
108 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
109 return -1;
110 #endif
111}
112
113
115 return 0;
116}
117
118
119
122 // @todo It would be nice to have the opportunity to tell the queue to do
123 // only a few tasks and then to return.
124 hostSyclQueue.wait();
125}
126#endif
#define assertion(expr)
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
Log Device.
Definition Log.h:516
static constexpr int UseDefaultNumberOfThreads
The default is what the system management typically gives you.
Definition Core.h:69
bool isInitialised() const
Definition Core.cpp:65
~Core()
Destructor.
Definition Core.cpp:54
int getCoreNumber() const
Definition Core.cpp:69
static Core & getInstance()
Definition Core.cpp:56
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:67
static tarch::logging::Log _log
Logging device.
Definition Core.h:55
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:61
void shutdown()
Shutdown parallel environment.
Definition Core.cpp:63
int getThreadNumber() const
Definition Core.cpp:78
void yield()
Wrapper around backend-specific yield.
Definition Core.cpp:80