Skip to content

Commit c96c50d

Browse files
author
Diptorup Deb
committed
Make the queue backend discoverable in sycl_core.
- Rename SyclQueueManager to SyclRTManager - Minor stylistic changes: -- reorder functions alphabetically. -- Move all enums into separate file. - Add C API to get backend from queue, and also add a way to check if a queue is the current queue. - Update sycl_core to match C API.
1 parent 5823125 commit c96c50d

12 files changed

+375
-145
lines changed

Diff for: backends/include/dppl_sycl_device_interface.h

+1-18
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,14 @@
2828
#pragma once
2929

3030
#include "dppl_data_types.h"
31+
#include "dppl_sycl_enum_types.h"
3132
#include "dppl_sycl_types.h"
3233
#include "Support/DllExport.h"
3334
#include "Support/ExternC.h"
3435
#include "Support/MemOwnershipAttrs.h"
3536

3637
DPPL_C_EXTERN_C_BEGIN
3738

38-
/*!
39-
* @brief Redefinition of Sycl's device_type so that we do not have to include
40-
* sycl.hpp here and in the Python bindings.
41-
*
42-
*/
43-
enum DPPLSyclDeviceType
44-
{
45-
DPPL_CPU = 1 << 0,
46-
DPPL_GPU = 1 << 1,
47-
DPPL_ACCELERATOR = 1 << 2,
48-
DPPL_CUSTOM = 1 << 3,
49-
DPPL_AUTOMATIC = 1 << 4,
50-
DPPL_HOST_DEVICE = 1 << 5,
51-
DPPL_ALL = 1 << 6
52-
// IMP: before adding new values here look at DPPLSyclBEType enum. The
53-
// values should not overlap.
54-
};
55-
5639
/*!
5740
* @brief Prints out some of the info::deivice attributes for the device.
5841
*

Diff for: backends/include/dppl_sycl_enum_types.h

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//===--- dppl_sycl_enum_types.h - DPPL-SYCL interface ---*---C++ -----*----===//
2+
//
3+
// Python Data Parallel Processing Library (PyDPPL)
4+
//
5+
// Copyright 2020 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This header defines DPPL specficif enum types that wrap corresponding Sycl
23+
/// enum classes. These enums are defined primarily so that Python extensions
24+
/// that use DPPL do not have to include Sycl headers directly.
25+
///
26+
//===----------------------------------------------------------------------===//
27+
28+
#pragma once
29+
30+
#include "Support/ExternC.h"
31+
32+
DPPL_C_EXTERN_C_BEGIN
33+
34+
/*!
35+
* @brief Redefinition of DPC++-specific Sycl backend types.
36+
*
37+
*/
38+
enum DPPLSyclBEType
39+
{
40+
DPPL_UNKNOWN_BACKEND = 0x0,
41+
DPPL_OPENCL = 1 << 16,
42+
DPPL_HOST = 1 << 15,
43+
DPPL_LEVEL_ZERO = 1 << 14,
44+
DPPL_CUDA = 1 << 13
45+
};
46+
47+
/*!
48+
* @brief DPPL device types that are equivalent to Sycl's device_type.
49+
*
50+
*/
51+
enum DPPLSyclDeviceType
52+
{
53+
DPPL_CPU = 1 << 0,
54+
DPPL_GPU = 1 << 1,
55+
DPPL_ACCELERATOR = 1 << 2,
56+
DPPL_CUSTOM = 1 << 3,
57+
DPPL_AUTOMATIC = 1 << 4,
58+
DPPL_HOST_DEVICE = 1 << 5,
59+
DPPL_ALL = 1 << 6
60+
// IMP: before adding new values here look at DPPLSyclBEType enum. The
61+
// values should not overlap.
62+
};
63+
64+
/*!
65+
* @brief Supported types for kernel arguments to be passed to a Sycl kernel
66+
* using DPPL.
67+
*
68+
* \todo Add support for sycl::buffer
69+
*
70+
*/
71+
typedef enum
72+
{
73+
DPPL_CHAR,
74+
DPPL_SIGNED_CHAR,
75+
DPPL_UNSIGNED_CHAR,
76+
DPPL_SHORT,
77+
DPPL_INT,
78+
DPPL_UNSIGNED_INT,
79+
DPPL_LONG,
80+
DPPL_UNSIGNED_LONG,
81+
DPPL_LONG_LONG,
82+
DPPL_UNSIGNED_LONG_LONG,
83+
DPPL_SIZE_T,
84+
DPPL_FLOAT,
85+
DPPL_DOUBLE,
86+
DPPL_LONG_DOUBLE,
87+
DPPL_VOID_PTR
88+
} DPPLKernelArgType;
89+
90+
DPPL_C_EXTERN_C_END

Diff for: backends/include/dppl_sycl_platform_interface.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,13 @@
2626
#pragma once
2727

2828
#include "dppl_data_types.h"
29+
#include "dppl_sycl_enum_types.h"
2930
#include "Support/DllExport.h"
3031
#include "Support/ExternC.h"
3132
#include "Support/MemOwnershipAttrs.h"
3233

3334
DPPL_C_EXTERN_C_BEGIN
3435

35-
/*!
36-
* @brief Redefinition of DPC++'s backend types. We have this wrapper so that
37-
* the sycl header is not exposed to Python extensions.
38-
*
39-
*/
40-
enum DPPLSyclBEType
41-
{
42-
DPPL_UNKNOWN_BACKEND = 0x0,
43-
DPPL_OPENCL = 1 << 16,
44-
DPPL_HOST = 1 << 15,
45-
DPPL_LEVEL_ZERO = 1 << 14,
46-
DPPL_CUDA = 1 << 13
47-
};
48-
4936
/*!
5037
* @brief Returns the number of sycl::platform available on the system.
5138
*

Diff for: backends/include/dppl_sycl_queue_interface.h

+9-24
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#pragma once
2929

3030
#include "dppl_data_types.h"
31+
#include "dppl_sycl_enum_types.h"
3132
#include "dppl_sycl_types.h"
3233
#include "Support/DllExport.h"
3334
#include "Support/ExternC.h"
@@ -36,37 +37,21 @@
3637
DPPL_C_EXTERN_C_BEGIN
3738

3839
/*!
39-
* @brief Supported types for kernel arguments to be passed to a Sycl kernel.
40-
*
41-
* \todo Add support for sycl::buffer
40+
* @brief Delete the pointer after casting it to sycl::queue.
4241
*
42+
* @param QRef A DPPLSyclQueueRef pointer that gets deleted.
4343
*/
44-
typedef enum
45-
{
46-
DPPL_CHAR,
47-
DPPL_SIGNED_CHAR,
48-
DPPL_UNSIGNED_CHAR,
49-
DPPL_SHORT,
50-
DPPL_INT,
51-
DPPL_UNSIGNED_INT,
52-
DPPL_LONG,
53-
DPPL_UNSIGNED_LONG,
54-
DPPL_LONG_LONG,
55-
DPPL_UNSIGNED_LONG_LONG,
56-
DPPL_SIZE_T,
57-
DPPL_FLOAT,
58-
DPPL_DOUBLE,
59-
DPPL_LONG_DOUBLE,
60-
DPPL_VOID_PTR
61-
} DPPLKernelArgType;
44+
DPPL_API
45+
void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef);
6246

6347
/*!
64-
* @brief Delete the pointer after casting it to sycl::queue.
48+
* @brief Returns the Sycl backend for the provided sycl::queue.
6549
*
66-
* @param QRef A DPPLSyclQueueRef pointer that gets deleted.
50+
* @param QRef An opaque pointer to the sycl queue.
51+
* @return A enum DPPLSyclBEType corresponding to the backed for the queue.
6752
*/
6853
DPPL_API
69-
void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef);
54+
enum DPPLSyclBEType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef);
7055

7156
/*!
7257
* @brief Returns the Sycl context for the queue.

Diff for: backends/include/dppl_sycl_queue_manager.h

+11
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ DPPL_API
9191
size_t DPPLQueueMgr_GetNumQueues (enum DPPLSyclBEType BETy,
9292
enum DPPLSyclDeviceType DeviceTy);
9393

94+
/*!
95+
* @brief Returns True if the passed in queue and the current queue are the
96+
* same, else returns False.
97+
*
98+
* @param QRef An opaque pointer to a sycl::queue.
99+
* @return True or False depending on whether the QRef argument is the same as
100+
* the currently activated queue.
101+
*/
102+
DPPL_API
103+
bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef);
104+
94105
/*!
95106
* @brief Set the default DPPL queue to the sycl::queue for the given backend
96107
* and device type combination.

Diff for: backends/include/dppl_sycl_types.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#pragma once
2727

28+
#include "Support/ExternC.h"
29+
30+
DPPL_C_EXTERN_C_BEGIN
31+
2832
/*!
2933
* @brief Opaque pointer to a sycl::context
3034
*
@@ -74,3 +78,5 @@ typedef struct DPPLOpaqueSyclQueue *DPPLSyclQueueRef;
7478
* @see sycl::usm
7579
*/
7680
typedef struct DPPLOpaqueSyclUSM *DPPLSyclUSMRef;
81+
82+
DPPL_C_EXTERN_C_END

Diff for: backends/source/dppl_sycl_queue_interface.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//===----------------------------------------------------------------------===//
2626

2727
#include "dppl_sycl_queue_interface.h"
28+
#include "dppl_sycl_context_interface.h"
2829
#include "Support/CBindingWrapping.h"
2930

3031
#include <CL/sycl.hpp> /* SYCL headers */
@@ -117,6 +118,13 @@ void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef)
117118
delete unwrap(QRef);
118119
}
119120

121+
enum DPPLSyclBEType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef)
122+
{
123+
auto Q = unwrap(QRef);
124+
auto C = Q->get_context();
125+
return DPPLContext_GetBackend(wrap(&C));
126+
}
127+
120128
__dppl_give DPPLSyclDeviceRef
121129
DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef)
122130
{

Diff for: backends/source/dppl_sycl_queue_manager.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class QMgrHelper
121121
static __dppl_give DPPLSyclQueueRef
122122
getCurrentQueue ();
123123

124+
static bool isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef);
125+
124126
static void
125127
setAsDefaultQueue (enum DPPLSyclBEType BETy,
126128
enum DPPLSyclDeviceType DeviceTy,
@@ -144,13 +146,14 @@ class QMgrHelper
144146
*/
145147
DPPLSyclQueueRef QMgrHelper::getCurrentQueue ()
146148
{
147-
if(get_active_queues().empty()) {
149+
auto activated_q = get_active_queues();
150+
if(activated_q.empty()) {
148151
// \todo handle error
149152
std::cerr << "No currently active queues.\n";
150153
return nullptr;
151154
}
152-
auto last = QMgrHelper::get_active_queues().size() - 1;
153-
return wrap(new queue(QMgrHelper::get_active_queues()[last]));
155+
auto last = activated_q.size() - 1;
156+
return wrap(new queue(activated_q[last]));
154157
}
155158

156159
/*!
@@ -212,6 +215,28 @@ QMgrHelper::getQueue (enum DPPLSyclBEType BETy,
212215
return wrap(QRef);
213216
}
214217

218+
/*!
219+
* Compares the context and device of the current queue to the context and
220+
* device of the queue passed as input. Return true if both queues have the
221+
* same context and device.
222+
*/
223+
bool QMgrHelper::isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef)
224+
{
225+
auto activated_q = get_active_queues();
226+
if(activated_q.empty()) {
227+
// \todo handle error
228+
std::cerr << "No currently active queues.\n";
229+
return false;
230+
}
231+
auto last = activated_q.size() - 1;
232+
auto currQ = activated_q[last];
233+
auto currCtx = currQ.get_context();
234+
auto currD = currQ.get_device();
235+
auto InD = unwrap(QRef)->get_device();
236+
auto InCtx = unwrap(QRef)->get_context();
237+
return (currCtx == InCtx && currD == InD);
238+
}
239+
215240
/*!
216241
* Changes the first entry into the stack, i.e., the default queue to a new
217242
* sycl::queue corresponding to the device type and device number.
@@ -420,6 +445,13 @@ DPPLSyclQueueRef DPPLQueueMgr_GetQueue (enum DPPLSyclBEType BETy,
420445
return QMgrHelper::getQueue(BETy, DeviceTy, DNum);
421446
}
422447

448+
/*!
449+
450+
* */
451+
bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef)
452+
{
453+
return QMgrHelper::isCurrentQueue(QRef);
454+
}
423455
/*!
424456
* The function sets the global queue, i.e., the sycl::queue object at
425457
* QMgrHelper::active_queues[0] vector to the sycl::queue corresponding to the

0 commit comments

Comments
 (0)