Skip to content

Commit b51100f

Browse files
Replace use of queue mgr (#1735)
* Remove use of deprecated DPCTLQueueMgr_* functions This is done by reverting to DPNP_LOCAL_QUEUE=1 behavior. The ultimate goal is to get rid of DPNP_QUEUE throughout dpnp codebase * Removed setting DPNP_LOCAL_QUEUE in tests Since DPNP_LOCAL_QUEUE has been removed. * Removed uses of device_context * Removed trailing whitespace * Replaced tab with spaces * Use backend_sycl_singleton, remove backend_sycl * Removed pre-preprocessor fenced out dead code Renamed backend_sycl_singleton back to backend_sycl Removed dpnp_queue_initialize_c function and QueueOptions enum as no longer used. Removed uses of these from examples and code base * Formatting suggested by pre-commit hooks * Addressed issues raised by @diptorupd --------- Co-authored-by: Anton <[email protected]>
1 parent 668e7ef commit b51100f

File tree

18 files changed

+72
-327
lines changed

18 files changed

+72
-327
lines changed

doc/dpctl.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ Interplay with the Data Parallel Control Library
1010
An example below demonstrates how the Data Parallel Extension for NumPy* can be
1111
easily combined with the device management interface provided by dpctl package.
1212

13-
Literally, the SYCL* queue manager interface from the dpctl package allows
14-
to set an input queue as the currently usable queue inside the context
15-
manager's scope. This way an array creation function from the dpnp package
16-
which is defined inside the context will allocate the data using that queue.
17-
1813
.. code-block:: python
1914
:linenos:
2015
21-
import dpctl
22-
import dpnp as np
16+
import dpctl
17+
import dpnp
18+
19+
d = dpctl.select_cpu_device()
20+
x = dpnp.array([1, 2, 3], device=d)
21+
s = dpnp.sum(x)
22+
23+
y = dpnp.linspace(0, dpnp.pi, num=10**6, device="gpu")
24+
f = 1 + y * dpnp.sin(y)
25+
26+
# locate argument where function attains global maximum
27+
max_arg = x[dpnp.argmax(f)]
28+
max_val = dpnp.max(f)
2329
24-
with dpctl.device_context("opencl:gpu"):
25-
x = np.array([1, 2, 3])
26-
s = np.sum(x)
2730
2831
For more information please refer to `Data Parallel Control Library`_
2932
documentation.

dpnp/backend/examples/example10.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ void test_dpnp_random_normal(const size_t size,
5050
double dev_time_used = 0.0;
5151
double sum_dev_time_used = 0.0;
5252

53-
dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);
54-
5553
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));
5654

5755
dpnp_rng_srand_c(seed); // TODO: will move

dpnp/backend/examples/example3.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ int main(int, char **)
4444
{
4545
const size_t size = 256;
4646

47-
dpnp_queue_initialize_c();
4847
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;
4948

5049
int *array1 = (int *)dpnp_memory_alloc_c(size * sizeof(int));

dpnp/backend/examples/example5.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ int main(int, char **)
5252
{
5353
const size_t size = 256;
5454

55-
dpnp_queue_initialize_c(QueueOptions::CPU_SELECTOR);
56-
5755
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));
5856

5957
size_t seed = 10;

dpnp/backend/examples/example7.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ int main(int, char **)
4545
const size_t size = 2;
4646
size_t len = size * size;
4747

48-
dpnp_queue_initialize_c(QueueOptions::CPU_SELECTOR);
49-
5048
float *array = (float *)dpnp_memory_alloc_c(len * sizeof(float));
5149
float *result1 = (float *)dpnp_memory_alloc_c(size * sizeof(float));
5250
float *result2 = (float *)dpnp_memory_alloc_c(len * sizeof(float));

dpnp/backend/examples/example8.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ int main(int, char **)
4242
{
4343
const size_t size = 16;
4444

45-
dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);
46-
4745
double *array = (double *)dpnp_memory_alloc_c(size * sizeof(double));
4846
long *result = (long *)dpnp_memory_alloc_c(size * sizeof(long));
4947

dpnp/backend/examples/example9.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ int main(int, char **)
4646
long result = 0;
4747
long result_verification = 0;
4848

49-
dpnp_queue_initialize_c(QueueOptions::CPU_SELECTOR);
50-
5149
long *array =
5250
reinterpret_cast<long *>(dpnp_memory_alloc_c(size * sizeof(long)));
5351

dpnp/backend/examples/example_bs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ int main(int, char **)
229229
const double RISK_FREE = 0.1;
230230
const double VOLATILITY = 0.2;
231231

232-
dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);
233232
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;
234233

235234
double *price = (double *)dpnp_memory_alloc_c(SIZE * sizeof(double));

dpnp/backend/include/dpnp_iface.hpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,6 @@ typedef ssize_t shape_elem_type;
6868
* @}
6969
*/
7070

71-
/**
72-
* @ingroup BACKEND_API
73-
* @brief SYCL queue initialization selector.
74-
*
75-
* The structure defines the parameters that are used for the library
76-
* initialization by @ref dpnp_queue_initialize_c "dpnp_queue_initialize".
77-
*/
78-
enum class QueueOptions : uint32_t
79-
{
80-
CPU_SELECTOR, /**< CPU side execution mode */
81-
GPU_SELECTOR, /**< Intel GPU side execution mode */
82-
AUTO_SELECTOR /**< Automatic selection based on environment variable with
83-
@ref CPU_SELECTOR default */
84-
};
85-
86-
/**
87-
* @ingroup BACKEND_API
88-
* @brief SYCL queue initialization.
89-
*
90-
* Global SYCL queue initialization.
91-
*
92-
* @param [in] selector Select type @ref QueueOptions of the SYCL queue.
93-
* Default @ref AUTO_SELECTOR
94-
*/
95-
INP_DLLEXPORT void dpnp_queue_initialize_c(
96-
QueueOptions selector = QueueOptions::AUTO_SELECTOR);
97-
9871
/**
9972
* @ingroup BACKEND_API
10073
* @brief SYCL queue device status.
@@ -112,8 +85,7 @@ INP_DLLEXPORT size_t dpnp_queue_is_cpu_c();
11285
* @param [in] size_in_bytes Number of bytes for requested memory allocation.
11386
* @param [in] q_ref Reference to SYCL queue.
11487
*
115-
* @return A pointer to newly created memory on @ref dpnp_queue_initialize_c
116-
* "initialized SYCL device".
88+
* @return A pointer to newly created memory on SYCL device.
11789
*/
11890
INP_DLLEXPORT char *dpnp_memory_alloc_c(DPCTLSyclQueueRef q_ref,
11991
size_t size_in_bytes);

dpnp/backend/kernels/dpnp_krnl_random.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static VSLStreamStatePtr get_rng_stream()
7070

7171
void dpnp_rng_srand_c(size_t seed)
7272
{
73-
backend_sycl::backend_sycl_rng_engine_init(seed);
73+
auto &be = backend_sycl::get();
74+
be.set_rng_engines_seed(seed);
7475
set_rng_stream(seed);
7576
}
7677

dpnp/backend/src/queue_sycl.cpp

Lines changed: 5 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@
3131
#include "dpnp_utils.hpp"
3232
#include "queue_sycl.hpp"
3333

34-
#if defined(DPNP_LOCAL_QUEUE)
35-
sycl::queue *backend_sycl::queue = nullptr;
36-
#endif
37-
mkl_rng::mt19937 *backend_sycl::rng_engine = nullptr;
38-
mkl_rng::mcg59 *backend_sycl::rng_mcg59_engine = nullptr;
39-
40-
static void dpnpc_show_mathlib_version()
34+
[[maybe_unused]] static void dpnpc_show_mathlib_version()
4135
{
4236
#if 1
4337
const int len = 256;
@@ -61,8 +55,8 @@ static void dpnpc_show_mathlib_version()
6155
#endif
6256
}
6357

64-
#if (not defined(NDEBUG)) && defined(DPNP_LOCAL_QUEUE)
65-
static void show_available_sycl_devices()
58+
#if (not defined(NDEBUG))
59+
[[maybe_unused]] static void show_available_sycl_devices()
6660
{
6761
const std::vector<sycl::device> devices = sycl::device::get_devices();
6862

@@ -86,25 +80,6 @@ static void show_available_sycl_devices()
8680
}
8781
#endif
8882

89-
#if defined(DPNP_LOCAL_QUEUE)
90-
static sycl::device get_default_sycl_device()
91-
{
92-
int dpnpc_queue_gpu = 0;
93-
sycl::device dev = sycl::device(sycl::cpu_selector());
94-
95-
const char *dpnpc_queue_gpu_var = getenv("DPNPC_QUEUE_GPU");
96-
if (dpnpc_queue_gpu_var != NULL) {
97-
dpnpc_queue_gpu = atoi(dpnpc_queue_gpu_var);
98-
}
99-
100-
if (dpnpc_queue_gpu) {
101-
dev = sycl::device(sycl::gpu_selector());
102-
}
103-
104-
return dev;
105-
}
106-
#endif
107-
10883
#if defined(DPNPC_TOUCH_KERNEL_TO_LINK)
10984
/**
11085
* Function push the SYCL kernels to be linked (final stage of the compilation)
@@ -135,117 +110,8 @@ static long dpnp_kernels_link()
135110
}
136111
#endif
137112

138-
#if defined(DPNP_LOCAL_QUEUE)
139-
// Catch asynchronous exceptions
140-
static void exception_handler(sycl::exception_list exceptions)
141-
{
142-
for (std::exception_ptr const &e : exceptions) {
143-
try {
144-
std::rethrow_exception(e);
145-
} catch (sycl::exception const &e) {
146-
std::cout << "DPNP. Caught asynchronous SYCL exception:\n"
147-
<< e.what() << std::endl;
148-
}
149-
}
150-
};
151-
#endif
152-
153-
void backend_sycl::backend_sycl_queue_init(QueueOptions selector)
154-
{
155-
#if defined(DPNP_LOCAL_QUEUE)
156-
std::chrono::high_resolution_clock::time_point t1 =
157-
std::chrono::high_resolution_clock::now();
158-
159-
if (queue) {
160-
backend_sycl::destroy();
161-
}
162-
163-
sycl::device dev;
164-
165-
#if not defined(NDEBUG)
166-
show_available_sycl_devices();
167-
#endif
168-
169-
if (QueueOptions::CPU_SELECTOR == selector) {
170-
dev = sycl::device(sycl::cpu_selector());
171-
}
172-
else if (QueueOptions::GPU_SELECTOR == selector) {
173-
dev = sycl::device(sycl::gpu_selector());
174-
}
175-
else {
176-
dev = get_default_sycl_device();
177-
}
178-
179-
if (is_verbose_mode()) {
180-
sycl::property_list properties{
181-
sycl::property::queue::enable_profiling()};
182-
queue = new sycl::queue(dev, exception_handler, properties);
183-
}
184-
else {
185-
queue = new sycl::queue(dev, exception_handler);
186-
}
187-
188-
std::chrono::high_resolution_clock::time_point t2 =
189-
std::chrono::high_resolution_clock::now();
190-
std::chrono::duration<double> time_queue_init =
191-
std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
192-
#else
193-
(void)selector;
194-
#endif
195-
196-
std::chrono::high_resolution_clock::time_point t3 =
197-
std::chrono::high_resolution_clock::now();
198-
#if defined(DPNPC_TOUCH_KERNEL_TO_LINK)
199-
// Remove pre-link kernel library at startup time
200-
dpnp_kernels_link();
201-
#endif
202-
std::chrono::high_resolution_clock::time_point t4 =
203-
std::chrono::high_resolution_clock::now();
204-
std::chrono::duration<double> time_kernels_link =
205-
std::chrono::duration_cast<std::chrono::duration<double>>(t4 - t3);
206-
207-
std::cout << "Running on: "
208-
<< DPNP_QUEUE.get_device().get_info<sycl::info::device::name>()
209-
<< "\n";
210-
#if defined(DPNP_LOCAL_QUEUE)
211-
std::cout << "queue initialization time: " << time_queue_init.count()
212-
<< " (sec.)\n";
213-
#else
214-
std::cout << "DPCtrl SYCL queue used\n";
215-
#endif
216-
std::cout << "SYCL kernels link time: " << time_kernels_link.count()
217-
<< " (sec.)\n";
218-
dpnpc_show_mathlib_version();
219-
220-
std::cout << std::endl;
221-
}
222-
223-
bool backend_sycl::backend_sycl_is_cpu()
224-
{
225-
sycl::queue &qptr = get_queue();
226-
227-
if (qptr.get_device().is_cpu()) {
228-
return true;
229-
}
230-
231-
return false;
232-
}
233-
234-
void backend_sycl::backend_sycl_rng_engine_init(size_t seed)
235-
{
236-
if (rng_engine) {
237-
backend_sycl::destroy_rng_engine();
238-
}
239-
rng_engine = new mkl_rng::mt19937(DPNP_QUEUE, seed);
240-
rng_mcg59_engine = new mkl_rng::mcg59(DPNP_QUEUE, seed);
241-
}
242-
243-
void dpnp_queue_initialize_c(QueueOptions selector)
244-
{
245-
backend_sycl::backend_sycl_queue_init(selector);
246-
}
247-
248113
size_t dpnp_queue_is_cpu_c()
249114
{
250-
return backend_sycl::backend_sycl_is_cpu();
115+
const auto &be = backend_sycl::get();
116+
return be.backend_sycl_is_cpu();
251117
}

0 commit comments

Comments
 (0)