Skip to content

Commit 2922ae7

Browse files
author
Jaime Arteaga
committed
Port [SYCL] [L0] Remove unneeded backwards compatibility of 2023.2 make_queue and get_native
intel#8871 Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent cd11f35 commit 2922ae7

File tree

5 files changed

+150
-116
lines changed

5 files changed

+150
-116
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,6 @@ pi_result piextQueueCreate(pi_context Context, pi_device Device,
179179
return pi2ur::piextQueueCreate(Context, Device, Properties, Queue);
180180
}
181181

182-
pi_result piextQueueCreate2(pi_context Context, pi_device Device,
183-
pi_queue_properties *Properties, pi_queue *Queue) {
184-
return pi2ur::piextQueueCreate(Context, Device, Properties, Queue);
185-
}
186-
187-
pi_result piextQueueGetNativeHandle2(pi_queue Queue,
188-
pi_native_handle *NativeHandle,
189-
int32_t *NativeHandleDesc) {
190-
std::ignore = NativeHandleDesc;
191-
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle);
192-
}
193-
194-
pi_result piextQueueCreateWithNativeHandle2(
195-
pi_native_handle NativeHandle, int32_t NativeHandleDesc, pi_context Context,
196-
pi_device Device, bool OwnNativeHandle, pi_queue_properties *Properties,
197-
pi_queue *Queue) {
198-
std::ignore = NativeHandleDesc;
199-
std::ignore = Properties;
200-
return pi2ur::piextQueueCreateWithNativeHandle(NativeHandle, Context, Device,
201-
OwnNativeHandle, Queue);
202-
}
203-
204182
pi_result piQueueGetInfo(pi_queue Queue, pi_queue_info ParamName,
205183
size_t ParamValueSize, void *ParamValue,
206184
size_t *ParamValueSizeRet) {
@@ -220,18 +198,23 @@ pi_result piQueueFinish(pi_queue Queue) { return pi2ur::piQueueFinish(Queue); }
220198
pi_result piQueueFlush(pi_queue Queue) { return pi2ur::piQueueFlush(Queue); }
221199

222200
pi_result piextQueueGetNativeHandle(pi_queue Queue,
223-
pi_native_handle *NativeHandle) {
201+
pi_native_handle *NativeHandle,
202+
int32_t *NativeHandleDesc) {
224203

225-
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle);
204+
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle,
205+
NativeHandleDesc);
226206
}
227207

228208
pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle,
209+
int32_t NativeHandleDesc,
229210
pi_context Context, pi_device Device,
230211
bool OwnNativeHandle,
212+
pi_queue_properties *Properties,
231213
pi_queue *Queue) {
232214

233-
return pi2ur::piextQueueCreateWithNativeHandle(NativeHandle, Context, Device,
234-
OwnNativeHandle, Queue);
215+
return pi2ur::piextQueueCreateWithNativeHandle(
216+
NativeHandle, NativeHandleDesc, Context, Device, OwnNativeHandle,
217+
Properties, Queue);
235218
}
236219

237220
pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,17 +1326,10 @@ inline pi_result piQueueCreate(pi_context Context, pi_device Device,
13261326
return pi2ur::piextQueueCreate(Context, Device, Properties, Queue);
13271327
}
13281328

1329-
inline pi_result piextQueueCreate2(pi_context context, pi_device device,
1330-
pi_queue_properties *properties,
1331-
pi_queue *queue) {
1332-
return pi2ur::piextQueueCreate(context, device, properties, queue);
1333-
}
1334-
1335-
inline pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle,
1336-
pi_context Context,
1337-
pi_device Device,
1338-
bool OwnNativeHandle,
1339-
pi_queue *Queue) {
1329+
inline pi_result piextQueueCreateWithNativeHandle(
1330+
pi_native_handle NativeHandle, int32_t NativeHandleDesc, pi_context Context,
1331+
pi_device Device, bool OwnNativeHandle, pi_queue_properties *Properties,
1332+
pi_queue *Queue) {
13401333
PI_ASSERT(Context, PI_ERROR_INVALID_CONTEXT);
13411334
PI_ASSERT(NativeHandle, PI_ERROR_INVALID_VALUE);
13421335
PI_ASSERT(Queue, PI_ERROR_INVALID_QUEUE);
@@ -1348,29 +1341,45 @@ inline pi_result piextQueueCreateWithNativeHandle(pi_native_handle NativeHandle,
13481341
ur_native_handle_t UrNativeHandle =
13491342
reinterpret_cast<ur_native_handle_t>(NativeHandle);
13501343
ur_queue_handle_t *UrQueue = reinterpret_cast<ur_queue_handle_t *>(Queue);
1351-
ur_queue_native_properties_t Properties{};
1352-
Properties.isNativeHandleOwned = OwnNativeHandle;
1353-
HANDLE_ERRORS(urQueueCreateWithNativeHandle(UrNativeHandle, UrContext,
1354-
UrDevice, &Properties, UrQueue));
1355-
return PI_SUCCESS;
1356-
}
1344+
ur_queue_native_properties_t UrNativeProperties{};
1345+
UrNativeProperties.isNativeHandleOwned = OwnNativeHandle;
13571346

1358-
inline pi_result piextQueueCreateWithNativeHandle2(
1359-
pi_native_handle nativeHandle, int32_t nativeHandleDesc, pi_context context,
1360-
pi_device device, bool pluginOwnsNativeHandle,
1361-
pi_queue_properties *Properties, pi_queue *queue) {
1362-
(void)nativeHandleDesc;
1363-
(void)Properties;
1364-
return pi2ur::piextQueueCreateWithNativeHandle(nativeHandle, context, device,
1365-
pluginOwnsNativeHandle, queue);
1347+
ur_queue_properties_t UrProperties{};
1348+
UrProperties.stype = UR_STRUCTURE_TYPE_QUEUE_PROPERTIES;
1349+
if (Properties[1] & PI_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE)
1350+
UrProperties.flags |= UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE;
1351+
if (Properties[1] & PI_QUEUE_FLAG_PROFILING_ENABLE)
1352+
UrProperties.flags |= UR_QUEUE_FLAG_PROFILING_ENABLE;
1353+
if (Properties[1] & PI_QUEUE_FLAG_ON_DEVICE)
1354+
UrProperties.flags |= UR_QUEUE_FLAG_ON_DEVICE;
1355+
if (Properties[1] & PI_QUEUE_FLAG_ON_DEVICE_DEFAULT)
1356+
UrProperties.flags |= UR_QUEUE_FLAG_ON_DEVICE_DEFAULT;
1357+
if (Properties[1] & PI_EXT_ONEAPI_QUEUE_FLAG_DISCARD_EVENTS)
1358+
UrProperties.flags |= UR_QUEUE_FLAG_DISCARD_EVENTS;
1359+
if (Properties[1] & PI_EXT_ONEAPI_QUEUE_FLAG_PRIORITY_LOW)
1360+
UrProperties.flags |= UR_QUEUE_FLAG_PRIORITY_LOW;
1361+
if (Properties[1] & PI_EXT_ONEAPI_QUEUE_FLAG_PRIORITY_HIGH)
1362+
UrProperties.flags |= UR_QUEUE_FLAG_PRIORITY_HIGH;
1363+
1364+
UrNativeProperties.pNext = &UrProperties;
1365+
1366+
// TODO: How to pass this up in the urQueueCreateWithNativeHandle interface?
1367+
std::ignore = NativeHandleDesc;
1368+
HANDLE_ERRORS(urQueueCreateWithNativeHandle(
1369+
UrNativeHandle, UrContext, UrDevice, &UrNativeProperties, UrQueue));
1370+
return PI_SUCCESS;
13661371
}
13671372

13681373
inline pi_result piextQueueGetNativeHandle(pi_queue Queue,
1369-
pi_native_handle *NativeHandle) {
1374+
pi_native_handle *NativeHandle,
1375+
int32_t *NativeHandleDesc) {
13701376

13711377
PI_ASSERT(Queue, PI_ERROR_INVALID_QUEUE);
13721378
PI_ASSERT(NativeHandle, PI_ERROR_INVALID_VALUE);
13731379

1380+
// TODO: How to pass this up in the urQueueGetNativeHandle interface?
1381+
std::ignore = NativeHandleDesc;
1382+
13741383
ur_queue_handle_t UrQueue = reinterpret_cast<ur_queue_handle_t>(Queue);
13751384

13761385
ur_native_handle_t UrNativeQueue{};
@@ -1381,14 +1390,6 @@ inline pi_result piextQueueGetNativeHandle(pi_queue Queue,
13811390
return PI_SUCCESS;
13821391
}
13831392

1384-
inline pi_result piextQueueGetNativeHandle2(pi_queue Queue,
1385-
pi_native_handle *NativeHandle,
1386-
int32_t *NativeHandleDesc) {
1387-
1388-
(void)NativeHandleDesc;
1389-
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle);
1390-
}
1391-
13921393
inline pi_result piQueueRelease(pi_queue Queue) {
13931394
PI_ASSERT(Queue, PI_ERROR_INVALID_QUEUE);
13941395

sycl/plugins/unified_runtime/pi_unified_runtime.cpp

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,6 @@ __SYCL_EXPORT pi_result piextQueueCreate(pi_context Context, pi_device Device,
109109
return pi2ur::piextQueueCreate(Context, Device, Properties, Queue);
110110
}
111111

112-
__SYCL_EXPORT pi_result piextQueueCreate2(pi_context Context, pi_device Device,
113-
pi_queue_properties *Properties,
114-
pi_queue *Queue) {
115-
return pi2ur::piextQueueCreate(Context, Device, Properties, Queue);
116-
}
117-
118-
__SYCL_EXPORT pi_result piextQueueGetNativeHandle2(
119-
pi_queue Queue, pi_native_handle *NativeHandle, int32_t *NativeHandleDesc) {
120-
std::ignore = NativeHandleDesc;
121-
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle);
122-
}
123-
124-
__SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle2(
125-
pi_native_handle NativeHandle, int32_t NativeHandleDesc, pi_context Context,
126-
pi_device Device, bool OwnNativeHandle, pi_queue_properties *Properties,
127-
pi_queue *Queue) {
128-
std::ignore = NativeHandleDesc;
129-
std::ignore = Properties;
130-
return pi2ur::piextQueueCreateWithNativeHandle(NativeHandle, Context, Device,
131-
OwnNativeHandle, Queue);
132-
}
133-
134112
__SYCL_EXPORT pi_result piQueueRelease(pi_queue Queue) {
135113
return pi2ur::piQueueRelease(Queue);
136114
}
@@ -724,16 +702,19 @@ __SYCL_EXPORT pi_result piextContextCreateWithNativeHandle(
724702
NativeHandle, NumDevices, Devices, OwnNativeHandle, RetContext);
725703
}
726704

727-
__SYCL_EXPORT pi_result
728-
piextQueueGetNativeHandle(pi_queue Queue, pi_native_handle *NativeHandle) {
729-
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle);
705+
__SYCL_EXPORT pi_result piextQueueGetNativeHandle(
706+
pi_queue Queue, pi_native_handle *NativeHandle, int32_t *NativeHandleDesc) {
707+
return pi2ur::piextQueueGetNativeHandle(Queue, NativeHandle,
708+
NativeHandleDesc);
730709
}
731710

732711
__SYCL_EXPORT pi_result piextQueueCreateWithNativeHandle(
733-
pi_native_handle NativeHandle, pi_context Context, pi_device Device,
734-
bool OwnNativeHandle, pi_queue *Queue) {
735-
return pi2ur::piextQueueCreateWithNativeHandle(NativeHandle, Context, Device,
736-
OwnNativeHandle, Queue);
712+
pi_native_handle NativeHandle, int32_t NativeHandleDesc, pi_context Context,
713+
pi_device Device, bool OwnNativeHandle, pi_queue_properties *Properties,
714+
pi_queue *Queue) {
715+
return pi2ur::piextQueueCreateWithNativeHandle(
716+
NativeHandle, NativeHandleDesc, Context, Device, OwnNativeHandle,
717+
Properties, Queue);
737718
}
738719

739720
__SYCL_EXPORT pi_result piMemRelease(pi_mem Mem) {
@@ -1068,9 +1049,6 @@ __SYCL_EXPORT pi_result piPluginInit(pi_plugin *PluginInit) {
10681049
_PI_API(piQueueFlush)
10691050
_PI_API(piextQueueGetNativeHandle)
10701051
_PI_API(piextQueueCreateWithNativeHandle)
1071-
_PI_API(piextQueueCreate2)
1072-
_PI_API(piextQueueGetNativeHandle2)
1073-
_PI_API(piextQueueCreateWithNativeHandle2)
10741052

10751053
_PI_API(piProgramCreate)
10761054
_PI_API(piProgramBuild)

sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero_queue.cpp

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -463,32 +463,66 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetNativeHandle(
463463
// Lock automatically releases when this goes out of scope.
464464
std::shared_lock<ur_shared_mutex> lock(Queue->Mutex);
465465

466-
auto ZeQueue = ur_cast<ze_command_queue_handle_t *>(NativeQueue);
467-
468-
// Extract a Level Zero compute queue handle from the given PI queue
466+
// Get handle to this thread's queue group.
469467
auto &QueueGroup = Queue->getQueueGroup(false /*compute*/);
470-
uint32_t QueueGroupOrdinalUnused;
471-
*ZeQueue = QueueGroup.getZeQueue(&QueueGroupOrdinalUnused);
468+
469+
if (Queue->UsingImmCmdLists) {
470+
auto ZeCmdList = ur_cast<ze_command_list_handle_t *>(NativeQueue);
471+
// Extract the Level Zero command list handle from the given PI queue
472+
*ZeCmdList = QueueGroup.getImmCmdList()->first;
473+
// TODO: How to pass this up in the urQueueGetNativeHandle interface?
474+
// *NativeHandleDesc = true;
475+
} else {
476+
auto ZeQueue = ur_cast<ze_command_queue_handle_t *>(NativeQueue);
477+
478+
// Extract a Level Zero compute queue handle from the given PI queue
479+
auto &QueueGroup = Queue->getQueueGroup(false /*compute*/);
480+
uint32_t QueueGroupOrdinalUnused;
481+
*ZeQueue = QueueGroup.getZeQueue(&QueueGroupOrdinalUnused);
482+
// TODO: How to pass this up in the urQueueGetNativeHandle interface?
483+
// *NativeHandleDesc = false;
484+
}
472485

473486
return UR_RESULT_SUCCESS;
474487
}
475488

489+
void ur_queue_handle_t_::pi_queue_group_t::setImmCmdList(
490+
ze_command_list_handle_t ZeCommandList) {
491+
ImmCmdLists = std::vector<ur_command_list_ptr_t>(
492+
1,
493+
Queue->CommandListMap
494+
.insert(std::pair<ze_command_list_handle_t, pi_command_list_info_t>{
495+
ZeCommandList, {nullptr, true, false, nullptr, 0}})
496+
.first);
497+
}
498+
476499
UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
477500
ur_native_handle_t NativeQueue, ///< [in] the native handle of the queue.
478501
ur_context_handle_t Context, ///< [in] handle of the context object
479502
ur_device_handle_t Device, ///
480-
const ur_queue_native_properties_t *Properties, ///
503+
const ur_queue_native_properties_t *NativeProperties, ///
481504
ur_queue_handle_t
482505
*RetQueue ///< [out] pointer to the handle of the queue object created.
483506
) {
484-
auto ZeQueue = ur_cast<ze_command_queue_handle_t>(NativeQueue);
485-
// Assume this is the "0" index queue in the compute command-group.
486-
std::vector<ze_command_queue_handle_t> ZeQueues{ZeQueue};
507+
bool OwnNativeHandle = false;
508+
ur_queue_flags_t Flags{};
487509

488-
// TODO: see what we can do to correctly initialize PI queue for
489-
// compute vs. copy Level-Zero queue. Currently we will send
490-
// all commands to the "ZeQueue".
491-
std::vector<ze_command_queue_handle_t> ZeroCopyQueues;
510+
if (NativeProperties) {
511+
OwnNativeHandle = NativeProperties->isNativeHandleOwned;
512+
if (NativeProperties->pNext) {
513+
const ur_base_properties_t *extendedProperties =
514+
reinterpret_cast<const ur_base_properties_t *>(
515+
NativeProperties->pNext);
516+
if (extendedProperties->stype == UR_STRUCTURE_TYPE_QUEUE_PROPERTIES) {
517+
const ur_queue_properties_t *UrProperties =
518+
reinterpret_cast<const ur_queue_properties_t *>(extendedProperties);
519+
Flags = UrProperties->flags;
520+
}
521+
}
522+
}
523+
524+
// TODO: How to pass this up in the urQueueCreateWithNativeHandle interface?
525+
int32_t NativeHandleDesc = 0;
492526

493527
// Get the device handle from first device in the platform
494528
// Maybe this is not completely correct.
@@ -502,15 +536,42 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
502536
nullptr));
503537
}
504538

505-
try {
506-
ur_queue_handle_t_ *Queue =
507-
new ur_queue_handle_t_(ZeQueues, ZeroCopyQueues, Context, UrDevice,
508-
Properties->isNativeHandleOwned);
509-
*RetQueue = reinterpret_cast<ur_queue_handle_t>(Queue);
510-
} catch (const std::bad_alloc &) {
511-
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
512-
} catch (...) {
513-
return UR_RESULT_ERROR_UNKNOWN;
539+
// The NativeHandleDesc has value if if the native handle is an immediate
540+
// command list.
541+
if (NativeHandleDesc == 1) {
542+
std::vector<ze_command_queue_handle_t> ComputeQueues{nullptr};
543+
std::vector<ze_command_queue_handle_t> CopyQueues;
544+
545+
try {
546+
ur_queue_handle_t_ *Queue = new ur_queue_handle_t_(
547+
ComputeQueues, CopyQueues, Context, UrDevice, OwnNativeHandle, Flags);
548+
*RetQueue = reinterpret_cast<ur_queue_handle_t>(Queue);
549+
} catch (const std::bad_alloc &) {
550+
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
551+
} catch (...) {
552+
return UR_RESULT_ERROR_UNKNOWN;
553+
}
554+
auto &InitialGroup = (*RetQueue)->ComputeQueueGroupsByTID.begin()->second;
555+
InitialGroup.setImmCmdList(ur_cast<ze_command_list_handle_t>(NativeQueue));
556+
} else {
557+
auto ZeQueue = ur_cast<ze_command_queue_handle_t>(NativeQueue);
558+
// Assume this is the "0" index queue in the compute command-group.
559+
std::vector<ze_command_queue_handle_t> ZeQueues{ZeQueue};
560+
561+
// TODO: see what we can do to correctly initialize PI queue for
562+
// compute vs. copy Level-Zero queue. Currently we will send
563+
// all commands to the "ZeQueue".
564+
std::vector<ze_command_queue_handle_t> ZeroCopyQueues;
565+
566+
try {
567+
ur_queue_handle_t_ *Queue = new ur_queue_handle_t_(
568+
ZeQueues, ZeroCopyQueues, Context, UrDevice, OwnNativeHandle, Flags);
569+
*RetQueue = reinterpret_cast<ur_queue_handle_t>(Queue);
570+
} catch (const std::bad_alloc &) {
571+
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
572+
} catch (...) {
573+
return UR_RESULT_ERROR_UNKNOWN;
574+
}
514575
}
515576

516577
return UR_RESULT_SUCCESS;
@@ -757,6 +818,8 @@ ur_queue_handle_t_::ur_queue_handle_t_(
757818
bool OwnZeCommandQueue, ur_queue_flags_t Properties, int ForceComputeIndex)
758819
: Context{Context}, Device{Device}, OwnZeCommandQueue{OwnZeCommandQueue},
759820
Properties(Properties) {
821+
// Set the type of commandlists the queue will use.
822+
UsingImmCmdLists = Device->useImmediateCommandLists();
760823
// Compute group initialization.
761824
// First, see if the queue's device allows for round-robin or it is
762825
// fixed to one particular compute CCS (it is so for sub-sub-devices).
@@ -766,7 +829,7 @@ ur_queue_handle_t_::ur_queue_handle_t_(
766829
ComputeQueueGroup.ZeQueues = ComputeQueues;
767830
// Create space to hold immediate commandlists corresponding to the
768831
// ZeQueues
769-
if (Device->ImmCommandListUsed) {
832+
if (UsingImmCmdLists) {
770833
ComputeQueueGroup.ImmCmdLists = std::vector<ur_command_list_ptr_t>(
771834
ComputeQueueGroup.ZeQueues.size(), CommandListMap.end());
772835
}
@@ -798,7 +861,7 @@ ur_queue_handle_t_::ur_queue_handle_t_(
798861
die("No compute queue available/allowed.");
799862
}
800863
}
801-
if (Device->ImmCommandListUsed) {
864+
if (UsingImmCmdLists) {
802865
// Create space to hold immediate commandlists corresponding to the
803866
// ZeQueues
804867
ComputeQueueGroup.ImmCmdLists = std::vector<ur_command_list_ptr_t>(

0 commit comments

Comments
 (0)