Skip to content

Commit 576598a

Browse files
diptorupdDiptorup Deb
authored andcommitted
Change the QueueManager API to require backend type.
1 parent c338842 commit 576598a

File tree

5 files changed

+260
-126
lines changed

5 files changed

+260
-126
lines changed

backends/include/dppl_sycl_context_interface.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,38 @@
3434

3535
DPPL_C_EXTERN_C_BEGIN
3636

37+
/*!
38+
* @brief Redefinition of DPC++'s backend types. We have this wrapper so that
39+
* the sycl header is not exposed to Python extensions.
40+
*
41+
*/
42+
typedef enum
43+
{
44+
DPPL_OPENCL = 1 << 16,
45+
DPPL_HOST = 1 << 15,
46+
DPPL_LEVEL_ZERO = 1 << 14,
47+
DPPL_CUDA = 1 << 13
48+
} DPPLSyclBEType;
49+
3750
/*!
3851
* @brief Returns true if this SYCL context is a host context.
3952
*
40-
* @param CtxRef A opaque pointer to a sycl::context.
53+
* @param CtxRef An opaque pointer to a sycl::context.
4154
* @return True if the SYCL context is a host context, else False.
4255
*/
4356
DPPL_API
4457
bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef);
4558

59+
/*!
60+
* @brief
61+
*
62+
* @param CtxRef An opaque pointer to a sycl::context.
63+
* @return {return} My Param doc
64+
*/
65+
DPPL_API
66+
DPPLSyclBackendType
67+
DPPLContext_GetBackend (__dppl_keep const DPPLSyclContextRef CtxRef);
68+
4669
/*!
4770
* @brief Delete the pointer after casting it to sycl::context
4871
*

backends/include/dppl_sycl_device_interface.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ DPPL_C_EXTERN_C_BEGIN
4242
*/
4343
typedef enum
4444
{
45-
DPPL_CPU,
46-
DPPL_GPU,
47-
DPPL_ACCELERATOR,
48-
DPPL_CUSTOM,
49-
DPPL_AUTOMATIC,
50-
DPPL_HOST,
51-
DPPL_ALL
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 = 1 << 5,
51+
DPPL_ALL = 1 << 6
52+
// IMP: before adding new values here look at DPPLSyclBEType enum. The
53+
// values should not overlap.
5254
} DPPLSyclDeviceType;
5355

5456
/*!

backends/include/dppl_sycl_queue_manager.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "dppl_data_types.h"
3737
#include "dppl_sycl_types.h"
38+
#include "dppl_sycl_context_interface.h"
3839
#include "dppl_sycl_device_interface.h"
3940
#include "Support/DllExport.h"
4041
#include "Support/ExternC.h"
@@ -63,7 +64,8 @@ __dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue ();
6364
* raised if no such device exists.
6465
*/
6566
DPPL_API
66-
__dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclDeviceType DeviceTy,
67+
__dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclBEType BETy,
68+
DPPLSyclDeviceType DeviceTy,
6769
size_t DNum);
6870

6971
/*!
@@ -75,56 +77,59 @@ __dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclDeviceType DeviceTy,
7577
DPPL_API
7678
size_t DPPLQueueMgr_GetNumActivatedQueues ();
7779

78-
/*!
79-
* @brief Get the number of GPU queues available on the system.
80-
*
81-
* @return The number of available GPU queues.
82-
*/
83-
DPPL_API
84-
size_t DPPLQueueMgr_GetNumGPUQueues ();
8580

8681
/*!
87-
* @brief Get the number of CPU queues available on the system.
82+
* @brief Get the number of available queues for given backend and device type
83+
* combination.
8884
*
89-
* @return The number of available CPU queues.
85+
* @param BETy Type of Sycl backend.
86+
* @param DeviceTy Type of Sycl device.
87+
* @return The number of available queues.
9088
*/
9189
DPPL_API
92-
size_t DPPLQueueMgr_GetNumCPUQueues ();
90+
size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBEType BETy,
91+
DPPLSyclDeviceType DeviceTy);
9392

9493
/*!
95-
* @brief Set the default DPPL queue to the sycl::queue for the given device.
94+
* @brief Set the default DPPL queue to the sycl::queue for the given backend
95+
* and device type combination.
9696
*
9797
* If no such device is found the a runtime_error exception is thrown.
9898
*
99+
* @param BETy Type of Sycl backend.
99100
* @param DeviceTy The type of Sycl device (sycl_device_type)
100101
* @param DNum Device id for the device (defaults to 0)
101102
*/
102103
DPPL_API
103-
void DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclDeviceType DeviceTy,
104+
void DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclBEType BETy,
105+
DPPLSyclDeviceType DeviceTy,
104106
size_t DNum);
105107

106108
/*!
107109
* @brief Pushes a new sycl::queue object to the top of DPPL's thread-local
108110
* stack of a "activated" queues, and returns a copy of the queue to caller.
109111
*
110-
* DPPL maintains a thread-local stack of sycl::queue objects to facilitate
111-
* nested parallelism. The sycl::queue at the top of the stack is termed as the
112-
* currently activated queue, and is always the one returned by
112+
* The DPPL queue manager maintains a thread-local stack of sycl::queue objects
113+
* to facilitate nested parallelism. The sycl::queue at the top of the stack is
114+
* termed as the currently activated queue, and is always the one returned by
113115
* DPPLQueueMgr_GetCurrentQueue(). DPPLPushSyclQueueToStack creates a new
114116
* sycl::queue corresponding to the specified device and pushes it to the top
115117
* of the stack. A copy of the sycl::queue is returned to the caller wrapped
116118
* inside the opaque DPPLSyclQueueRef pointer. A runtime_error exception is
117119
* thrown when a new sycl::queue could not be created for the specified device.
118120
*
121+
* @param BETy Type of Sycl backend.
119122
* @param DeviceTy The type of Sycl device (sycl_device_type)
120123
* @param DNum Device id for the device (defaults to 0)
121124
*
122125
* @return A copy of the sycl::queue that was pushed to the top of DPPL's
123-
* stack of sycl::queue objects.
126+
* stack of sycl::queue objects. Nullptr is returned if no such device exists.
124127
*/
125128
DPPL_API
126129
__dppl_give DPPLSyclQueueRef
127-
DPPLQueueMgr_PushQueue (DPPLSyclDeviceType DeviceTy, size_t DNum);
130+
DPPLQueueMgr_PushQueue (DPPLSyclBEType BETy,
131+
DPPLSyclDeviceType DeviceTy,
132+
size_t DNum);
128133

129134
/*!
130135
* @brief Pops the top of stack element from DPPL's stack of activated

backends/source/dppl_sycl_context_interface.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,23 @@ void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef)
4646
{
4747
delete unwrap(CtxRef);
4848
}
49+
50+
DPPLSyclBackendType
51+
DPPLContext_GetBackend (__dppl_keep const DPPLSyclContextRef CtxRef)
52+
{
53+
auto BE = unwrap(CtxRef)->get_platform().get_backend();
54+
55+
switch(BE)
56+
{
57+
case backend::host:
58+
return DPPL_HOST;
59+
case backend::opencl:
60+
return DPPL_OPENCL;
61+
case backend::level_zero:
62+
return DPPL_LEVEL_ZERO;
63+
case backend::cuda:
64+
return DPPL_CUDA;
65+
default:
66+
return DPPL_UNKNOWN_BACKEND;
67+
}
68+
}

0 commit comments

Comments
 (0)