Skip to content

Commit b7ab952

Browse files
Added DPPLQueueMgr_GetQueueFromContextAndDevice to backend
1 parent 5479b54 commit b7ab952

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

backends/include/dppl_sycl_queue_manager.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,20 @@ DPPLQueueMgr_PushQueue (DPPLSyclBackendType BETy,
158158
DPPL_API
159159
void DPPLQueueMgr_PopQueue ();
160160

161+
162+
/*!
163+
* @brief Creates a new instance of SYCL queue from SYCL context and
164+
* SYCL device.
165+
*
166+
* The instance is not placed into queue manager. The user assumes
167+
* ownership of the queue reference and should deallocate it using
168+
* DPPLQueue_Delete.
169+
*
170+
*/
171+
DPPL_API
172+
__dppl_give DPPLSyclQueueRef
173+
DPPLQueueMgr_GetQueueFromContextAndDevice(__dppl_keep DPPLSyclContextRef CRef,
174+
__dppl_keep DPPLSyclDeviceRef DRef);
175+
176+
161177
DPPL_C_EXTERN_C_END

backends/source/dppl_sycl_queue_manager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace
4040

4141
// Create wrappers for C Binding types (see CBindingWrapping.h).
4242
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPPLSyclQueueRef)
43+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPPLSyclDeviceRef)
44+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef)
4345

4446
/*!
4547
* @brief A helper class to support the DPPLSyclQueuemanager.
@@ -534,3 +536,18 @@ void DPPLQueueMgr_PopQueue ()
534536
{
535537
QMgrHelper::popSyclQueue();
536538
}
539+
540+
/*!
541+
* The function constructs a new SYCL queue instance from SYCL conext and
542+
* SYCL device.
543+
*/
544+
DPPLSyclQueueRef
545+
DPPLQueueMgr_GetQueueFromContextAndDevice(__dppl_keep DPPLSyclContextRef CRef,
546+
__dppl_keep DPPLSyclDeviceRef DRef)
547+
{
548+
auto dev = unwrap(DRef);
549+
auto ctx = unwrap(CRef);
550+
auto q = queue(*ctx, *dev);
551+
552+
return wrap(new queue(q));
553+
}

backends/tests/test_sycl_queue_manager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ TEST_F (TestDPPLSyclQueueManager, CheckIsCurrentQueue2)
244244
DPPLQueueMgr_PopQueue();
245245
}
246246

247+
TEST_F (TestDPPLSyclQueueManager, CreateQueueFromDeviceAndContext)
248+
{
249+
auto Q = DPPLQueueMgr_GetCurrentQueue();
250+
auto D = DPPLQueue_GetDevice(Q);
251+
auto C = DPPLQueue_GetContext(Q);
252+
253+
auto Q2 = DPPLQueueMgr_GetQueueFromContextAndDevice(C, D);
254+
auto D2 = DPPLQueue_GetDevice(Q2);
255+
auto C2 = DPPLQueue_GetContext(Q2);
256+
257+
EXPECT_TRUE(DPPLDevice_AreEq(D, D2));
258+
EXPECT_TRUE(DPPLContext_AreEq(C, C2));
259+
260+
DPPLQueue_Delete(Q2);
261+
}
262+
247263
int
248264
main (int argc, char** argv)
249265
{

0 commit comments

Comments
 (0)