@@ -423,6 +423,20 @@ pi_result _pi_device::initialize() {
423
423
return PI_SUCCESS;
424
424
}
425
425
426
+ pi_result _pi_context::initialize () {
427
+ // Create the immediate command list to be used for initializations
428
+ // Created as synchronous so level-zero performs implicit synchronization and
429
+ // there is no need to query for completion in the plugin
430
+ ze_command_queue_desc_t ZeCommandQueueDesc = {};
431
+ ZeCommandQueueDesc.ordinal = Devices[0 ]->ZeComputeQueueGroupIndex ;
432
+ ZeCommandQueueDesc.index = 0 ;
433
+ ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
434
+ ZE_CALL (zeCommandListCreateImmediate (ZeContext, Devices[0 ]->ZeDevice ,
435
+ &ZeCommandQueueDesc,
436
+ &ZeCommandListInit));
437
+ return PI_SUCCESS;
438
+ }
439
+
426
440
pi_result
427
441
_pi_queue::resetCommandListFenceEntry (ze_command_list_handle_t ZeCommandList,
428
442
bool MakeAvailable) {
@@ -1703,29 +1717,19 @@ pi_result piContextCreate(const pi_context_properties *Properties,
1703
1717
1704
1718
assert (RetContext);
1705
1719
1720
+ ze_context_desc_t ContextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr , 0 };
1721
+ ze_context_handle_t ZeContext;
1722
+ ZE_CALL (zeContextCreate ((*Devices)->Platform ->ZeDriver , &ContextDesc,
1723
+ &ZeContext));
1706
1724
try {
1707
- *RetContext = new _pi_context (NumDevices, Devices);
1725
+ *RetContext = new _pi_context (ZeContext, NumDevices, Devices);
1726
+ (*RetContext)->initialize ();
1708
1727
} catch (const std::bad_alloc &) {
1709
1728
return PI_OUT_OF_HOST_MEMORY;
1710
1729
} catch (...) {
1711
1730
return PI_ERROR_UNKNOWN;
1712
1731
}
1713
1732
1714
- ze_context_desc_t ContextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr , 0 };
1715
- ZE_CALL (zeContextCreate ((*Devices)->Platform ->ZeDriver , &ContextDesc,
1716
- &((*RetContext)->ZeContext )));
1717
-
1718
- // Create the immediate command list to be used for initializations
1719
- // Created as synchronous so level-zero performs implicit synchronization and
1720
- // there is no need to query for completion in the plugin
1721
- ze_command_queue_desc_t ZeCommandQueueDesc = {};
1722
- ZeCommandQueueDesc.ordinal = (*Devices)->ZeComputeQueueGroupIndex ;
1723
- ZeCommandQueueDesc.index = 0 ;
1724
- ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
1725
- ZE_CALL (zeCommandListCreateImmediate (
1726
- (*RetContext)->ZeContext , (*Devices)->ZeDevice , &ZeCommandQueueDesc,
1727
- (&(*RetContext)->ZeCommandListInit )));
1728
-
1729
1733
return PI_SUCCESS;
1730
1734
}
1731
1735
@@ -1772,8 +1776,26 @@ pi_result piextContextGetNativeHandle(pi_context Context,
1772
1776
}
1773
1777
1774
1778
pi_result piextContextCreateWithNativeHandle (pi_native_handle NativeHandle,
1775
- pi_context *Context) {
1776
- die (" piextContextCreateWithNativeHandle: not supported" );
1779
+ pi_uint32 NumDevices,
1780
+ const pi_device *Devices,
1781
+ pi_context *RetContext) {
1782
+ assert (NativeHandle);
1783
+ assert (RetContext);
1784
+
1785
+ if (!Devices || !NumDevices) {
1786
+ return PI_INVALID_VALUE;
1787
+ }
1788
+
1789
+ try {
1790
+ *RetContext = new _pi_context (pi_cast<ze_context_handle_t >(NativeHandle),
1791
+ NumDevices, Devices);
1792
+ (*RetContext)->initialize ();
1793
+ } catch (const std::bad_alloc &) {
1794
+ return PI_OUT_OF_HOST_MEMORY;
1795
+ } catch (...) {
1796
+ return PI_ERROR_UNKNOWN;
1797
+ }
1798
+
1777
1799
return PI_SUCCESS;
1778
1800
}
1779
1801
0 commit comments