29
29
30
30
// #pragma clang diagnostic push
31
31
// #pragma clang diagnostic ignored "-Wpass-failed"
32
- #include < CL /sycl.hpp>
32
+ #include < sycl /sycl.hpp>
33
33
// #pragma clang diagnostic pop
34
+ #include < memory>
34
35
35
36
#pragma clang diagnostic push
36
37
#pragma clang diagnostic ignored "-Wunused-parameter"
46
47
47
48
namespace mkl_rng = oneapi::mkl::rng;
48
49
49
- #define DPNP_QUEUE backend_sycl::get_queue ()
50
- #define DPNP_RNG_ENGINE backend_sycl::get_rng_engine ()
51
- #define DPNP_RNG_MCG59_ENGINE backend_sycl::get_rng_mcg59_engine ()
50
+ #define DPNP_QUEUE backend_sycl_singleton::get_queue ()
51
+ #define DPNP_RNG_ENGINE backend_sycl_singleton::get_rng_engine ()
52
+ #define DPNP_RNG_MCG59_ENGINE backend_sycl_singleton::get_rng_mcg59_engine ()
53
+
54
+ class backend_sycl_singleton {
55
+ public:
56
+ ~backend_sycl_singleton () {}
57
+
58
+ static backend_sycl_singleton& get () {
59
+ static backend_sycl_singleton backend = lookup ();
60
+ return backend;
61
+ }
62
+
63
+ static sycl::queue& get_queue () {
64
+ auto &be = backend_sycl_singleton::get ();
65
+ return *(be.queue_ptr );
66
+ }
67
+
68
+ static mkl_rng::mt19937& get_rng_engine () {
69
+ auto &be = backend_sycl_singleton::get ();
70
+ return *(be.rng_mt19937_engine_ptr );
71
+ }
72
+
73
+ static mkl_rng::mcg59& get_rng_mcg59_engine () {
74
+ auto &be = backend_sycl_singleton::get ();
75
+ return *(be.rng_mcg59_engine_ptr );
76
+ }
77
+
78
+ template <typename SeedT>
79
+ void set_rng_engines_seed (const SeedT &seed) {
80
+ auto rng_eng_mt19937 = std::make_shared<mkl_rng::mt19937>(*queue_ptr, seed);
81
+ if (!rng_eng_mt19937) {
82
+ throw std::runtime_error (
83
+ " Could not create MT19937 engine with given seed"
84
+ );
85
+ }
86
+ auto rng_eng_mcg59 = std::make_shared<mkl_rng::mcg59>(*queue_ptr, seed);
87
+ if (!rng_eng_mcg59) {
88
+ throw std::runtime_error (
89
+ " Could not create MCG59 engine with given seed"
90
+ );
91
+ }
92
+
93
+ rng_mt19937_engine_ptr.swap (rng_eng_mt19937);
94
+ rng_mcg59_engine_ptr.swap (rng_eng_mcg59);
95
+ }
96
+
97
+ bool backend_sycl_is_cpu () const {
98
+ if (queue_ptr) {
99
+ const sycl::queue &q = *queue_ptr;
100
+
101
+ return q.get_device ().is_cpu ();
102
+ }
103
+ return false ;
104
+ }
105
+
106
+ private:
107
+ backend_sycl_singleton () :
108
+ queue_ptr{}, rng_mt19937_engine_ptr{}, rng_mcg59_engine_ptr{}
109
+ {
110
+ const sycl::property_list &prop = (is_verbose_mode ()) ?
111
+ sycl::property_list{sycl::property::queue::enable_profiling ()}
112
+ : sycl::property_list{};
113
+ queue_ptr = std::make_shared<sycl::queue>(sycl::default_selector_v, prop);
114
+
115
+ if (!queue_ptr) {
116
+ throw std::runtime_error (
117
+ " Could not create queue for default-selected device"
118
+ );
119
+ }
120
+
121
+ constexpr std::size_t default_seed = 1 ;
122
+ rng_mt19937_engine_ptr = std::make_shared<mkl_rng::mt19937>(*queue_ptr, default_seed);
123
+ if (!rng_mt19937_engine_ptr) {
124
+ throw std::runtime_error (
125
+ " Could not create MT19937 engine"
126
+ );
127
+ }
128
+
129
+ rng_mcg59_engine_ptr = std::make_shared<mkl_rng::mcg59>(*queue_ptr, default_seed);
130
+ if (!rng_mcg59_engine_ptr) {
131
+ throw std::runtime_error (
132
+ " Could not create MCG59 engine"
133
+ );
134
+ }
135
+ }
136
+
137
+ static backend_sycl_singleton& lookup () {
138
+ static backend_sycl_singleton backend{};
139
+ return backend;
140
+ }
141
+
142
+ std::shared_ptr<sycl::queue> queue_ptr;
143
+ std::shared_ptr<mkl_rng::mt19937> rng_mt19937_engine_ptr;
144
+ std::shared_ptr<mkl_rng::mcg59> rng_mcg59_engine_ptr;
145
+ };
52
146
53
147
/* *
54
148
* This is container for the SYCL queue, random number generation engine and
@@ -57,16 +151,18 @@ namespace mkl_rng = oneapi::mkl::rng;
57
151
* initialization order is undefined. This class postpone initialization of the
58
152
* SYCL queue and mt19937 random number generation engine.
59
153
*/
154
+ #if 0
60
155
class backend_sycl
61
156
{
62
- static sycl::queue *queue; /* *< contains SYCL queue pointer initialized in
63
- @ref backend_sycl_queue_init */
64
- static mkl_rng::mt19937
65
- *rng_engine; /* *< RNG MT19937 engine ptr. initialized in @ref
157
+ /**< contains SYCL queue pointer initialized in
158
+ @ref backend_sycl_queue_init */
159
+ static sycl::queue *queue;
160
+ /**< RNG MT19937 engine ptr. initialized in @ref
66
161
backend_sycl_rng_engine_init */
67
- static mkl_rng::mcg59
68
- *rng_mcg59_engine; /* *< RNG MCG59 engine ptr. initialized in @ref
69
- backend_sycl_rng_engine_init */
162
+ static mkl_rng::mt19937 *rng_engine;
163
+ /**< RNG MCG59 engine ptr. initialized in @ref
164
+ backend_sycl_rng_engine_init */
165
+ static mkl_rng::mcg59 *rng_mcg59_engine;
70
166
71
167
static void destroy()
72
168
{
@@ -106,7 +202,7 @@ class backend_sycl
106
202
* Initialize @ref queue
107
203
*/
108
204
static void backend_sycl_queue_init(
109
- QueueOptions selector = QueueOptions::CPU_SELECTOR );
205
+ QueueOptions selector = QueueOptions::AUTO_SELECTOR );
110
206
111
207
/**
112
208
* Return True if current @ref queue is related to cpu device
@@ -152,5 +248,6 @@ class backend_sycl
152
248
return *rng_mcg59_engine;
153
249
}
154
250
};
251
+ #endif
155
252
156
253
#endif // QUEUE_SYCL_H
0 commit comments