@@ -782,59 +782,125 @@ ur_result_t urBindlessImagesImportExternalSemaphoreExp(
782
782
" {} function not supported!" , __FUNCTION__);
783
783
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
784
784
}
785
- ze_intel_external_semaphore_exp_desc_t SemDesc = {
786
- ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXP_DESC, nullptr ,
787
- ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD};
788
- ze_intel_external_semaphore_exp_handle_t ExtSemaphoreHandle;
789
- ze_intel_external_semaphore_desc_fd_exp_desc_t FDExpDesc = {
790
- ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXP_DESC, nullptr , 0 };
791
- _ze_intel_external_semaphore_win32_exp_desc_t Win32ExpDesc = {
792
- ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXP_DESC, nullptr ,
793
- nullptr , nullptr };
794
- void *pNext = const_cast <void *>(pExternalSemaphoreDesc->pNext );
795
- while (pNext != nullptr ) {
796
- const ur_base_desc_t *BaseDesc = static_cast <const ur_base_desc_t *>(pNext);
797
- if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
798
- auto FileDescriptor =
799
- static_cast <const ur_exp_file_descriptor_t *>(pNext);
800
- FDExpDesc.fd = FileDescriptor->fd ;
801
- SemDesc.pNext = &FDExpDesc;
802
- switch (semHandleType) {
803
- case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
804
- SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
805
- break ;
806
- case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
807
- SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_FD;
808
- break ;
809
- default :
810
- return UR_RESULT_ERROR_INVALID_VALUE;
785
+ if (UrPlatform->ZeExternalSemaphoreExt .LoaderExtension ) {
786
+ ze_external_semaphore_ext_desc_t SemDesc = {
787
+ ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXT_DESC, nullptr ,
788
+ ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD};
789
+ ze_external_semaphore_ext_handle_t ExtSemaphoreHandle;
790
+ ze_external_semaphore_fd_ext_desc_t FDExpDesc = {
791
+ ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXT_DESC, nullptr , 0 };
792
+ ze_external_semaphore_win32_ext_desc_t Win32ExpDesc = {
793
+ ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXT_DESC, nullptr , nullptr ,
794
+ nullptr };
795
+ void *pNext = const_cast <void *>(pExternalSemaphoreDesc->pNext );
796
+ while (pNext != nullptr ) {
797
+ const ur_base_desc_t *BaseDesc =
798
+ static_cast <const ur_base_desc_t *>(pNext);
799
+ if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
800
+ auto FileDescriptor =
801
+ static_cast <const ur_exp_file_descriptor_t *>(pNext);
802
+ FDExpDesc.fd = FileDescriptor->fd ;
803
+ SemDesc.pNext = &FDExpDesc;
804
+ switch (semHandleType) {
805
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
806
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD;
807
+ break ;
808
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
809
+ SemDesc.flags =
810
+ ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_FD;
811
+ break ;
812
+ default :
813
+ return UR_RESULT_ERROR_INVALID_VALUE;
814
+ }
815
+ } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
816
+ SemDesc.pNext = &Win32ExpDesc;
817
+ auto Win32Handle = static_cast <const ur_exp_win32_handle_t *>(pNext);
818
+ switch (semHandleType) {
819
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
820
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_WIN32;
821
+ break ;
822
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
823
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_D3D12_FENCE;
824
+ break ;
825
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
826
+ SemDesc.flags =
827
+ ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_WIN32;
828
+ break ;
829
+ default :
830
+ return UR_RESULT_ERROR_INVALID_VALUE;
831
+ }
832
+ Win32ExpDesc.handle = Win32Handle->handle ;
811
833
}
812
- } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
813
- SemDesc.pNext = &Win32ExpDesc;
814
- auto Win32Handle = static_cast <const ur_exp_win32_handle_t *>(pNext);
815
- switch (semHandleType) {
816
- case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
817
- SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_WIN32;
818
- break ;
819
- case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
820
- SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_D3D12_FENCE;
821
- break ;
822
- case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
823
- SemDesc.flags =
824
- ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_WIN32;
825
- break ;
826
- default :
827
- return UR_RESULT_ERROR_INVALID_VALUE;
834
+ pNext = const_cast <void *>(BaseDesc->pNext );
835
+ }
836
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt .zexImportExternalSemaphoreExp ,
837
+ (hDevice->ZeDevice , &SemDesc, &ExtSemaphoreHandle));
838
+ *phExternalSemaphoreHandle =
839
+ (ur_exp_external_semaphore_handle_t )ExtSemaphoreHandle;
840
+
841
+ } else {
842
+ ze_intel_external_semaphore_exp_desc_t SemDesc = {
843
+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXP_DESC, nullptr ,
844
+ ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD};
845
+ ze_intel_external_semaphore_exp_handle_t ExtSemaphoreHandle;
846
+ ze_intel_external_semaphore_desc_fd_exp_desc_t FDExpDesc = {
847
+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXP_DESC, nullptr , 0 };
848
+ _ze_intel_external_semaphore_win32_exp_desc_t Win32ExpDesc = {
849
+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXP_DESC, nullptr ,
850
+ nullptr , nullptr };
851
+ void *pNext = const_cast <void *>(pExternalSemaphoreDesc->pNext );
852
+ while (pNext != nullptr ) {
853
+ const ur_base_desc_t *BaseDesc =
854
+ static_cast <const ur_base_desc_t *>(pNext);
855
+ if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
856
+ auto FileDescriptor =
857
+ static_cast <const ur_exp_file_descriptor_t *>(pNext);
858
+ FDExpDesc.fd = FileDescriptor->fd ;
859
+ SemDesc.pNext = &FDExpDesc;
860
+ switch (semHandleType) {
861
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
862
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
863
+ break ;
864
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
865
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_FD;
866
+ break ;
867
+ default :
868
+ return UR_RESULT_ERROR_INVALID_VALUE;
869
+ }
870
+ } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
871
+ SemDesc.pNext = &Win32ExpDesc;
872
+ auto Win32Handle = static_cast <const ur_exp_win32_handle_t *>(pNext);
873
+ switch (semHandleType) {
874
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
875
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_WIN32;
876
+ break ;
877
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
878
+ SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_D3D12_FENCE;
879
+ break ;
880
+ case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
881
+ SemDesc.flags =
882
+ ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_WIN32;
883
+ break ;
884
+ default :
885
+ return UR_RESULT_ERROR_INVALID_VALUE;
886
+ }
887
+ Win32ExpDesc.handle = Win32Handle->handle ;
828
888
}
829
- Win32ExpDesc. handle = Win32Handle-> handle ;
889
+ pNext = const_cast < void *>(BaseDesc-> pNext ) ;
830
890
}
831
- pNext = const_cast <void *>(BaseDesc->pNext );
832
- }
833
891
834
- ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt .zexImportExternalSemaphoreExp ,
835
- (hDevice->ZeDevice , &SemDesc, &ExtSemaphoreHandle));
836
- *phExternalSemaphoreHandle =
837
- (ur_exp_external_semaphore_handle_t )ExtSemaphoreHandle;
892
+ ze_device_handle_t translatedDevice;
893
+ ZE2UR_CALL (zelLoaderTranslateHandle, (ZEL_HANDLE_DEVICE, hDevice->ZeDevice ,
894
+ (void **)&translatedDevice));
895
+ // If the L0 loader is not aware of the extension, the handles need to be
896
+ // translated
897
+ ZE2UR_CALL (
898
+ UrPlatform->ZeExternalSemaphoreExt .zexExpImportExternalSemaphoreExp ,
899
+ (translatedDevice, &SemDesc, &ExtSemaphoreHandle));
900
+
901
+ *phExternalSemaphoreHandle =
902
+ (ur_exp_external_semaphore_handle_t )ExtSemaphoreHandle;
903
+ }
838
904
839
905
return UR_RESULT_SUCCESS;
840
906
}
@@ -849,9 +915,15 @@ ur_result_t urBindlessImagesReleaseExternalSemaphoreExp(
849
915
" {} function not supported!" , __FUNCTION__);
850
916
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
851
917
}
852
- ZE2UR_CALL (
853
- UrPlatform->ZeExternalSemaphoreExt .zexDeviceReleaseExternalSemaphoreExp ,
854
- ((ze_intel_external_semaphore_exp_handle_t )hExternalSemaphore));
918
+ if (UrPlatform->ZeExternalSemaphoreExt .LoaderExtension ) {
919
+ ZE2UR_CALL (
920
+ UrPlatform->ZeExternalSemaphoreExt .zexDeviceReleaseExternalSemaphoreExp ,
921
+ ((ze_external_semaphore_ext_handle_t )hExternalSemaphore));
922
+ } else {
923
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
924
+ .zexExpDeviceReleaseExternalSemaphoreExp ,
925
+ ((ze_intel_external_semaphore_exp_handle_t )hExternalSemaphore));
926
+ }
855
927
856
928
return UR_RESULT_SUCCESS;
857
929
}
@@ -898,15 +970,36 @@ ur_result_t urBindlessImagesWaitExternalSemaphoreExp(
898
970
const auto &ZeCommandList = CommandList->first ;
899
971
const auto &WaitList = (*Event)->WaitList ;
900
972
901
- ze_intel_external_semaphore_wait_params_exp_t WaitParams = {
902
- ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXP, nullptr , 0 };
903
- WaitParams.value = hasValue ? waitValue : 0 ;
904
- const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
905
- reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
906
- ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
907
- .zexCommandListAppendWaitExternalSemaphoresExp ,
908
- (ZeCommandList, 1 , &hExtSemaphore, &WaitParams, ZeEvent,
909
- WaitList.Length , WaitList.ZeEventList ));
973
+ if (UrPlatform->ZeExternalSemaphoreExt .LoaderExtension ) {
974
+ ze_external_semaphore_wait_params_ext_t WaitParams = {
975
+ ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXT, nullptr , 0 };
976
+ WaitParams.value = hasValue ? waitValue : 0 ;
977
+ ze_external_semaphore_ext_handle_t hExtSemaphore =
978
+ reinterpret_cast <ze_external_semaphore_ext_handle_t >(hSemaphore);
979
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
980
+ .zexCommandListAppendWaitExternalSemaphoresExp ,
981
+ (ZeCommandList, 1 , &hExtSemaphore, &WaitParams, ZeEvent,
982
+ WaitList.Length , WaitList.ZeEventList ));
983
+ } else {
984
+ ze_command_list_handle_t translatedCommandList;
985
+ ZE2UR_CALL (zelLoaderTranslateHandle,
986
+ (ZEL_HANDLE_COMMAND_LIST, ZeCommandList,
987
+ (void **)&translatedCommandList));
988
+ ze_event_handle_t translatedEvent = ZeEvent;
989
+ if (ZeEvent) {
990
+ ZE2UR_CALL (zelLoaderTranslateHandle,
991
+ (ZEL_HANDLE_EVENT, ZeEvent, (void **)&translatedEvent));
992
+ }
993
+ ze_intel_external_semaphore_wait_params_exp_t WaitParams = {
994
+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXP, nullptr , 0 };
995
+ WaitParams.value = hasValue ? waitValue : 0 ;
996
+ const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
997
+ reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
998
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
999
+ .zexExpCommandListAppendWaitExternalSemaphoresExp ,
1000
+ (translatedCommandList, 1 , &hExtSemaphore, &WaitParams,
1001
+ translatedEvent, WaitList.Length , WaitList.ZeEventList ));
1002
+ }
910
1003
911
1004
return UR_RESULT_SUCCESS;
912
1005
}
@@ -915,13 +1008,6 @@ ur_result_t urBindlessImagesSignalExternalSemaphoreExp(
915
1008
ur_queue_handle_t hQueue, ur_exp_external_semaphore_handle_t hSemaphore,
916
1009
bool hasValue, uint64_t signalValue, uint32_t numEventsInWaitList,
917
1010
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
918
- std::ignore = hQueue;
919
- std::ignore = hSemaphore;
920
- std::ignore = hasValue;
921
- std::ignore = signalValue;
922
- std::ignore = numEventsInWaitList;
923
- std::ignore = phEventWaitList;
924
- std::ignore = phEvent;
925
1011
auto UrPlatform = hQueue->Context ->getPlatform ();
926
1012
if (UrPlatform->ZeExternalSemaphoreExt .Supported == false ) {
927
1013
logger::error (logger::LegacyMessage (" [UR][L0] " ),
@@ -960,16 +1046,39 @@ ur_result_t urBindlessImagesSignalExternalSemaphoreExp(
960
1046
const auto &ZeCommandList = CommandList->first ;
961
1047
const auto &WaitList = (*Event)->WaitList ;
962
1048
963
- ze_intel_external_semaphore_signal_params_exp_t SignalParams = {
964
- ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXP, nullptr , 0 };
965
- SignalParams.value = hasValue ? signalValue : 0 ;
966
- const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
967
- reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
968
-
969
- ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
970
- .zexCommandListAppendSignalExternalSemaphoresExp ,
971
- (ZeCommandList, 1 , &hExtSemaphore, &SignalParams, ZeEvent,
972
- WaitList.Length , WaitList.ZeEventList ));
1049
+ if (UrPlatform->ZeExternalSemaphoreExt .LoaderExtension ) {
1050
+ ze_external_semaphore_signal_params_ext_t SignalParams = {
1051
+ ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXT, nullptr , 0 };
1052
+ SignalParams.value = hasValue ? signalValue : 0 ;
1053
+ ze_external_semaphore_ext_handle_t hExtSemaphore =
1054
+ reinterpret_cast <ze_external_semaphore_ext_handle_t >(hSemaphore);
1055
+
1056
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
1057
+ .zexCommandListAppendSignalExternalSemaphoresExp ,
1058
+ (ZeCommandList, 1 , &hExtSemaphore, &SignalParams, ZeEvent,
1059
+ WaitList.Length , WaitList.ZeEventList ));
1060
+ } else {
1061
+ ze_intel_external_semaphore_signal_params_exp_t SignalParams = {
1062
+ ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXP, nullptr ,
1063
+ 0 };
1064
+ SignalParams.value = hasValue ? signalValue : 0 ;
1065
+ const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
1066
+ reinterpret_cast <ze_intel_external_semaphore_exp_handle_t >(hSemaphore);
1067
+
1068
+ ze_command_list_handle_t translatedCommandList;
1069
+ ZE2UR_CALL (zelLoaderTranslateHandle,
1070
+ (ZEL_HANDLE_COMMAND_LIST, ZeCommandList,
1071
+ (void **)&translatedCommandList));
1072
+ ze_event_handle_t translatedEvent = ZeEvent;
1073
+ if (ZeEvent) {
1074
+ ZE2UR_CALL (zelLoaderTranslateHandle,
1075
+ (ZEL_HANDLE_EVENT, ZeEvent, (void **)&translatedEvent));
1076
+ }
1077
+ ZE2UR_CALL (UrPlatform->ZeExternalSemaphoreExt
1078
+ .zexExpCommandListAppendSignalExternalSemaphoresExp ,
1079
+ (translatedCommandList, 1 , &hExtSemaphore, &SignalParams,
1080
+ translatedEvent, WaitList.Length , WaitList.ZeEventList ));
1081
+ }
973
1082
974
1083
return UR_RESULT_SUCCESS;
975
1084
}
0 commit comments