@@ -1190,41 +1190,130 @@ ur_result_t urBindlessImagesImportExternalSemaphoreExp(
11901190 ur_exp_external_semaphore_type_t semHandleType,
11911191 ur_exp_external_semaphore_desc_t *pExternalSemaphoreDesc,
11921192 ur_exp_external_semaphore_handle_t *phExternalSemaphoreHandle) {
1193- std::ignore = hContext;
1194- std::ignore = hDevice;
1195- std::ignore = semHandleType;
1196- std::ignore = pExternalSemaphoreDesc;
1197- std::ignore = phExternalSemaphoreHandle;
1198- logger::error (logger::LegacyMessage (" [UR][L0] {} function not implemented!" ),
1199- " {} function not implemented!" , __FUNCTION__);
1200- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1193+
1194+ auto UrPlatform = hContext->getPlatform ();
1195+ if (UrPlatform->ZeExternalSemaphoreExt .Supported == false ) {
1196+ logger::error (logger::LegacyMessage (" [UR][L0] " ),
1197+ " {} function not supported!" , __FUNCTION__);
1198+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1199+ }
1200+ ze_intel_external_semaphore_exp_desc_t SemDesc = {
1201+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXP_DESC, nullptr ,
1202+ ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD};
1203+ ze_intel_external_semaphore_exp_handle_t ExtSemaphoreHandle;
1204+ ze_intel_external_semaphore_desc_fd_exp_desc_t FDExpDesc = {
1205+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXP_DESC, nullptr , 0 };
1206+ _ze_intel_external_semaphore_win32_exp_desc_t Win32ExpDesc = {
1207+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXP_DESC, nullptr ,
1208+ nullptr , nullptr };
1209+ void *pNext = const_cast <void *>(pExternalSemaphoreDesc->pNext );
1210+ while (pNext != nullptr ) {
1211+ const ur_base_desc_t *BaseDesc = static_cast <const ur_base_desc_t *>(pNext);
1212+ if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
1213+ auto FileDescriptor =
1214+ static_cast <const ur_exp_file_descriptor_t *>(pNext);
1215+ FDExpDesc.fd = FileDescriptor->fd ;
1216+ SemDesc.pNext = &FDExpDesc;
1217+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
1218+ } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
1219+ SemDesc.pNext = &Win32ExpDesc;
1220+ auto Win32Handle = static_cast <const ur_exp_win32_handle_t *>(pNext);
1221+ switch (semHandleType) {
1222+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
1223+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_WIN32;
1224+ break ;
1225+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
1226+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_D3D12_FENCE;
1227+ break ;
1228+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
1229+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
1230+ break ;
1231+ default :
1232+ return UR_RESULT_ERROR_INVALID_VALUE;
1233+ }
1234+ Win32ExpDesc.handle = Win32Handle->handle ;
1235+ }
1236+ pNext = const_cast <void *>(BaseDesc->pNext );
1237+ }
1238+
1239+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt .zexImportExternalSemaphoreExp ,
1240+ (hDevice->ZeDevice , &ExtSemaphoreHandle, &SemDesc));
1241+ *phExternalSemaphoreHandle =
1242+ (ur_exp_external_semaphore_handle_t )ExtSemaphoreHandle;
1243+
1244+ return UR_RESULT_SUCCESS;
12011245}
12021246
12031247ur_result_t urBindlessImagesReleaseExternalSemaphoreExp (
12041248 ur_context_handle_t hContext, ur_device_handle_t hDevice,
12051249 ur_exp_external_semaphore_handle_t hExternalSemaphore) {
1206- std::ignore = hContext;
12071250 std::ignore = hDevice;
1208- std::ignore = hExternalSemaphore;
1209- logger::error (logger::LegacyMessage (" [UR][L0] {} function not implemented!" ),
1210- " {} function not implemented!" , __FUNCTION__);
1211- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1251+ auto UrPlatform = hContext->getPlatform ();
1252+ if (UrPlatform->ZeExternalSemaphoreExt .Supported == false ) {
1253+ logger::error (logger::LegacyMessage (" [UR][L0] " ),
1254+ " {} function not supported!" , __FUNCTION__);
1255+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1256+ }
1257+ ZE2UR_CALL (
1258+ UrPlatform->ZeExternalSemaphoreExt .zexDeviceReleaseExternalSemaphoreExp ,
1259+ ((ze_intel_external_semaphore_exp_handle_t )hExternalSemaphore));
1260+
1261+ return UR_RESULT_SUCCESS;
12121262}
12131263
12141264ur_result_t urBindlessImagesWaitExternalSemaphoreExp (
12151265 ur_queue_handle_t hQueue, ur_exp_external_semaphore_handle_t hSemaphore,
12161266 bool hasValue, uint64_t waitValue, uint32_t numEventsInWaitList,
12171267 const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
1218- std::ignore = hQueue;
1219- std::ignore = hSemaphore;
1220- std::ignore = hasValue;
1221- std::ignore = waitValue;
1222- std::ignore = numEventsInWaitList;
1223- std::ignore = phEventWaitList;
1224- std::ignore = phEvent;
1225- logger::error (logger::LegacyMessage (" [UR][L0] " ),
1226- " {} function not implemented!" , __FUNCTION__);
1227- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1268+ auto UrPlatform = hQueue->Context ->getPlatform ();
1269+ if (UrPlatform->ZeExternalSemaphoreExt .Supported == false ) {
1270+ logger::error (logger::LegacyMessage (" [UR][L0] " ),
1271+ " {} function not supported!" , __FUNCTION__);
1272+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1273+ }
1274+
1275+ bool UseCopyEngine = false ;
1276+
1277+ // We want to batch these commands to avoid extra submissions (costly)
1278+ bool OkToBatch = true ;
1279+
1280+ _ur_ze_event_list_t TmpWaitList;
1281+ UR_CALL (TmpWaitList.createAndRetainUrZeEventList (
1282+ numEventsInWaitList, phEventWaitList, hQueue, UseCopyEngine));
1283+
1284+ // Get a new command list to be used on this call
1285+ ur_command_list_ptr_t CommandList{};
1286+ UR_CALL (hQueue->Context ->getAvailableCommandList (
1287+ hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
1288+ OkToBatch, nullptr /* ForcedCmdQueue*/ ));
1289+
1290+ ze_event_handle_t ZeEvent = nullptr ;
1291+ ur_event_handle_t InternalEvent;
1292+ bool IsInternal = phEvent == nullptr ;
1293+ ur_event_handle_t *Event = phEvent ? phEvent : &InternalEvent;
1294+ UR_CALL (createEventAndAssociateQueue (hQueue, Event,
1295+ UR_COMMAND_EXTERNAL_SEMAPHORE_WAIT_EXP,
1296+ CommandList, IsInternal,
1297+ /* IsMultiDevice*/ false ));
1298+ UR_CALL (setSignalEvent (hQueue, UseCopyEngine, &ZeEvent, Event,
1299+ numEventsInWaitList, phEventWaitList,
1300+ CommandList->second .ZeQueue ));
1301+ (*Event)->WaitList = TmpWaitList;
1302+
1303+ const auto &ZeCommandList = CommandList->first ;
1304+ const auto &WaitList = (*Event)->WaitList ;
1305+
1306+ ze_intel_external_semaphore_wait_exp_params_t WaitParams = {
1307+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXP, nullptr , 0 };
1308+ WaitParams.value = hasValue ? waitValue : 0 ;
1309+ const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
1310+ reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
1311+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
1312+ .zexCommandListAppendWaitExternalSemaphoresExp ,
1313+ (ZeCommandList, &hExtSemaphore, &WaitParams, 1 , ZeEvent,
1314+ WaitList.Length , WaitList.ZeEventList ));
1315+
1316+ return UR_RESULT_SUCCESS;
12281317}
12291318
12301319ur_result_t urBindlessImagesSignalExternalSemaphoreExp (
@@ -1238,9 +1327,56 @@ ur_result_t urBindlessImagesSignalExternalSemaphoreExp(
12381327 std::ignore = numEventsInWaitList;
12391328 std::ignore = phEventWaitList;
12401329 std::ignore = phEvent;
1241- logger::error (logger::LegacyMessage (" [UR][L0] {} function not implemented!" ),
1242- " {} function not implemented!" , __FUNCTION__);
1243- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1330+ auto UrPlatform = hQueue->Context ->getPlatform ();
1331+ if (UrPlatform->ZeExternalSemaphoreExt .Supported == false ) {
1332+ logger::error (logger::LegacyMessage (" [UR][L0] " ),
1333+ " {} function not supported!" , __FUNCTION__);
1334+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1335+ }
1336+
1337+ bool UseCopyEngine = false ;
1338+
1339+ // We want to batch these commands to avoid extra submissions (costly)
1340+ bool OkToBatch = true ;
1341+
1342+ _ur_ze_event_list_t TmpWaitList;
1343+ UR_CALL (TmpWaitList.createAndRetainUrZeEventList (
1344+ numEventsInWaitList, phEventWaitList, hQueue, UseCopyEngine));
1345+
1346+ // Get a new command list to be used on this call
1347+ ur_command_list_ptr_t CommandList{};
1348+ UR_CALL (hQueue->Context ->getAvailableCommandList (
1349+ hQueue, CommandList, UseCopyEngine, numEventsInWaitList, phEventWaitList,
1350+ OkToBatch, nullptr /* ForcedCmdQueue*/ ));
1351+
1352+ ze_event_handle_t ZeEvent = nullptr ;
1353+ ur_event_handle_t InternalEvent;
1354+ bool IsInternal = phEvent == nullptr ;
1355+ ur_event_handle_t *Event = phEvent ? phEvent : &InternalEvent;
1356+ UR_CALL (createEventAndAssociateQueue (hQueue, Event,
1357+ UR_COMMAND_EXTERNAL_SEMAPHORE_SIGNAL_EXP,
1358+ CommandList, IsInternal,
1359+ /* IsMultiDevice*/ false ));
1360+ UR_CALL (setSignalEvent (hQueue, UseCopyEngine, &ZeEvent, Event,
1361+ numEventsInWaitList, phEventWaitList,
1362+ CommandList->second .ZeQueue ));
1363+ (*Event)->WaitList = TmpWaitList;
1364+
1365+ const auto &ZeCommandList = CommandList->first ;
1366+ const auto &WaitList = (*Event)->WaitList ;
1367+
1368+ ze_intel_external_semaphore_signal_exp_params_t SignalParams = {
1369+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXP, nullptr , 0 };
1370+ SignalParams.value = hasValue ? signalValue : 0 ;
1371+ const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
1372+ reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
1373+
1374+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
1375+ .zexCommandListAppendSignalExternalSemaphoresExp ,
1376+ (ZeCommandList, &hExtSemaphore, &SignalParams, 1 , ZeEvent,
1377+ WaitList.Length , WaitList.ZeEventList ));
1378+
1379+ return UR_RESULT_SUCCESS;
12441380}
12451381
12461382} // namespace ur::level_zero
0 commit comments