Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 19 additions & 79 deletions unified-runtime/source/adapters/level_zero/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,15 @@ ur_result_t urBindlessImagesWaitExternalSemaphoreExp(
const auto &ZeCommandList = CommandList->first;
const auto &WaitList = (*Event)->WaitList;

if (UrPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
ze_external_semaphore_wait_params_ext_t WaitParams = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXT, nullptr, 0};
WaitParams.value = hasValue ? waitValue : 0;
ze_external_semaphore_ext_handle_t hExtSemaphore =
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexCommandListAppendWaitExternalSemaphoresExp,
(ZeCommandList, 1, &hExtSemaphore, &WaitParams, ZeEvent,
WaitList.Length, WaitList.ZeEventList));
} else {
ze_command_list_handle_t translatedCommandList;
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_COMMAND_LIST, ZeCommandList,
(void **)&translatedCommandList));
ze_event_handle_t translatedEvent = ZeEvent;
if (ZeEvent) {
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_EVENT, ZeEvent, (void **)&translatedEvent));
}
std::vector<ze_event_handle_t> EventHandles(WaitList.Length + 1, nullptr);
if (WaitList.Length > 0) {
for (size_t i = 0; i < WaitList.Length; i++) {
ze_event_handle_t ZeEvent = WaitList.ZeEventList[i];
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_EVENT, ZeEvent, (void **)&EventHandles[i + 1]));
}
}
ze_intel_external_semaphore_wait_params_exp_t WaitParams = {
ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXP, nullptr, 0};
WaitParams.value = hasValue ? waitValue : 0;
const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
reinterpret_cast<ze_intel_external_semaphore_exp_handle_t>(hSemaphore);
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexExpCommandListAppendWaitExternalSemaphoresExp,
(translatedCommandList, 1, &hExtSemaphore, &WaitParams,
translatedEvent, WaitList.Length, EventHandles.data()));
}
ze_external_semaphore_wait_params_ext_t WaitParams = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXT, nullptr, 0};
WaitParams.value = hasValue ? waitValue : 0;
ze_external_semaphore_ext_handle_t hExtSemaphore =
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexCommandListAppendWaitExternalSemaphoresExp,
(ZeCommandList, 1, &hExtSemaphore, &WaitParams, ZeEvent,
WaitList.Length, WaitList.ZeEventList));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -221,47 +192,16 @@ ur_result_t urBindlessImagesSignalExternalSemaphoreExp(
const auto &ZeCommandList = CommandList->first;
const auto &WaitList = (*Event)->WaitList;

if (UrPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
ze_external_semaphore_signal_params_ext_t SignalParams = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXT, nullptr, 0};
SignalParams.value = hasValue ? signalValue : 0;
ze_external_semaphore_ext_handle_t hExtSemaphore =
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);

ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexCommandListAppendSignalExternalSemaphoresExp,
(ZeCommandList, 1, &hExtSemaphore, &SignalParams, ZeEvent,
WaitList.Length, WaitList.ZeEventList));
} else {
ze_intel_external_semaphore_signal_params_exp_t SignalParams = {
ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXP, nullptr,
0};
SignalParams.value = hasValue ? signalValue : 0;
const ze_intel_external_semaphore_exp_handle_t hExtSemaphore =
reinterpret_cast<ze_intel_external_semaphore_exp_handle_t>(hSemaphore);

ze_command_list_handle_t translatedCommandList;
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_COMMAND_LIST, ZeCommandList,
(void **)&translatedCommandList));
ze_event_handle_t translatedEvent = ZeEvent;
if (ZeEvent) {
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_EVENT, ZeEvent, (void **)&translatedEvent));
}
std::vector<ze_event_handle_t> EventHandles(WaitList.Length + 1, nullptr);
if (WaitList.Length > 0) {
for (size_t i = 0; i < WaitList.Length; i++) {
ze_event_handle_t ZeEvent = WaitList.ZeEventList[i];
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_EVENT, ZeEvent, (void **)&EventHandles[i + 1]));
}
}
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexExpCommandListAppendSignalExternalSemaphoresExp,
(translatedCommandList, 1, &hExtSemaphore, &SignalParams,
translatedEvent, WaitList.Length, EventHandles.data()));
}
ze_external_semaphore_signal_params_ext_t SignalParams = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXT, nullptr, 0};
SignalParams.value = hasValue ? signalValue : 0;
ze_external_semaphore_ext_handle_t hExtSemaphore =
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);

ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexCommandListAppendSignalExternalSemaphoresExp,
(ZeCommandList, 1, &hExtSemaphore, &SignalParams, ZeEvent,
WaitList.Length, WaitList.ZeEventList));

return UR_RESULT_SUCCESS;
}
Expand Down
176 changes: 52 additions & 124 deletions unified-runtime/source/adapters/level_zero/image_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,126 +1356,60 @@ ur_result_t urBindlessImagesImportExternalSemaphoreExp(
" {} function not supported!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
if (UrPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
ze_external_semaphore_ext_desc_t SemDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXT_DESC, nullptr,
ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD};
ze_external_semaphore_ext_handle_t ExtSemaphoreHandle;
ze_external_semaphore_fd_ext_desc_t FDExpDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXT_DESC, nullptr, 0};
ze_external_semaphore_win32_ext_desc_t Win32ExpDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXT_DESC, nullptr, nullptr,
nullptr};
void *pNext = const_cast<void *>(pExternalSemaphoreDesc->pNext);
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc =
static_cast<const ur_base_desc_t *>(pNext);
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
auto FileDescriptor =
static_cast<const ur_exp_file_descriptor_t *>(pNext);
FDExpDesc.fd = FileDescriptor->fd;
SemDesc.pNext = &FDExpDesc;
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
SemDesc.flags =
ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_FD;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
} else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
SemDesc.pNext = &Win32ExpDesc;
auto Win32Handle = static_cast<const ur_exp_win32_handle_t *>(pNext);
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_WIN32;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_D3D12_FENCE;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
SemDesc.flags =
ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_WIN32;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
Win32ExpDesc.handle = Win32Handle->handle;
ze_external_semaphore_ext_desc_t SemDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXT_DESC, nullptr,
ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD};
ze_external_semaphore_ext_handle_t ExtSemaphoreHandle;
ze_external_semaphore_fd_ext_desc_t FDExpDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXT_DESC, nullptr, 0};
ze_external_semaphore_win32_ext_desc_t Win32ExpDesc = {
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXT_DESC, nullptr, nullptr,
nullptr};
void *pNext = const_cast<void *>(pExternalSemaphoreDesc->pNext);
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
auto FileDescriptor =
static_cast<const ur_exp_file_descriptor_t *>(pNext);
FDExpDesc.fd = FileDescriptor->fd;
SemDesc.pNext = &FDExpDesc;
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_FD;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_FD;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
pNext = const_cast<void *>(BaseDesc->pNext);
}
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp,
(hDevice->ZeDevice, &SemDesc, &ExtSemaphoreHandle));
*phExternalSemaphoreHandle =
(ur_exp_external_semaphore_handle_t)ExtSemaphoreHandle;

} else {
ze_intel_external_semaphore_exp_desc_t SemDesc = {
ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_EXP_DESC, nullptr,
ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD};
ze_intel_external_semaphore_exp_handle_t ExtSemaphoreHandle;
ze_intel_external_semaphore_desc_fd_exp_desc_t FDExpDesc = {
ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_FD_EXP_DESC, nullptr, 0};
_ze_intel_external_semaphore_win32_exp_desc_t Win32ExpDesc = {
ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WIN32_EXP_DESC, nullptr,
nullptr, nullptr};
void *pNext = const_cast<void *>(pExternalSemaphoreDesc->pNext);
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc =
static_cast<const ur_base_desc_t *>(pNext);
if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR) {
auto FileDescriptor =
static_cast<const ur_exp_file_descriptor_t *>(pNext);
FDExpDesc.fd = FileDescriptor->fd;
SemDesc.pNext = &FDExpDesc;
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_OPAQUE_FD:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_FD;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_FD:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_FD;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
} else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
SemDesc.pNext = &Win32ExpDesc;
auto Win32Handle = static_cast<const ur_exp_win32_handle_t *>(pNext);
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_OPAQUE_WIN32;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_D3D12_FENCE;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
SemDesc.flags =
ZE_EXTERNAL_SEMAPHORE_EXP_FLAGS_TIMELINE_SEMAPHORE_WIN32;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
Win32ExpDesc.handle = Win32Handle->handle;
} else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE) {
SemDesc.pNext = &Win32ExpDesc;
auto Win32Handle = static_cast<const ur_exp_win32_handle_t *>(pNext);
switch (semHandleType) {
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_OPAQUE_WIN32;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_WIN32_NT_DX12_FENCE:
SemDesc.flags = ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_D3D12_FENCE;
break;
case UR_EXP_EXTERNAL_SEMAPHORE_TYPE_TIMELINE_WIN32_NT:
SemDesc.flags =
ZE_EXTERNAL_SEMAPHORE_EXT_FLAG_VK_TIMELINE_SEMAPHORE_WIN32;
break;
default:
return UR_RESULT_ERROR_INVALID_VALUE;
}
pNext = const_cast<void *>(BaseDesc->pNext);
Win32ExpDesc.handle = Win32Handle->handle;
}

ze_device_handle_t translatedDevice;
ZE2UR_CALL(zelLoaderTranslateHandle, (ZEL_HANDLE_DEVICE, hDevice->ZeDevice,
(void **)&translatedDevice));
// If the L0 loader is not aware of the extension, the handles need to be
// translated
ZE2UR_CALL(
UrPlatform->ZeExternalSemaphoreExt.zexExpImportExternalSemaphoreExp,
(translatedDevice, &SemDesc, &ExtSemaphoreHandle));

*phExternalSemaphoreHandle =
(ur_exp_external_semaphore_handle_t)ExtSemaphoreHandle;
pNext = const_cast<void *>(BaseDesc->pNext);
}

ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp,
(hDevice->ZeDevice, &SemDesc, &ExtSemaphoreHandle));
*phExternalSemaphoreHandle =
(ur_exp_external_semaphore_handle_t)ExtSemaphoreHandle;

return UR_RESULT_SUCCESS;
}

Expand All @@ -1488,15 +1422,9 @@ ur_result_t urBindlessImagesReleaseExternalSemaphoreExp(
" {} function not supported!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
if (UrPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
ZE2UR_CALL(
UrPlatform->ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp,
((ze_external_semaphore_ext_handle_t)hExternalSemaphore));
} else {
ZE2UR_CALL(UrPlatform->ZeExternalSemaphoreExt
.zexExpDeviceReleaseExternalSemaphoreExp,
((ze_intel_external_semaphore_exp_handle_t)hExternalSemaphore));
}
ZE2UR_CALL(
UrPlatform->ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp,
((ze_external_semaphore_ext_handle_t)hExternalSemaphore));

return UR_RESULT_SUCCESS;
}
Expand Down
40 changes: 0 additions & 40 deletions unified-runtime/source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ ur_result_t ur_platform_handle_t_::initialize() {
(ZeDriver, &Count, ZeExtensions.data()));

bool MutableCommandListSpecExtensionSupported = false;
bool ZeIntelExternalSemaphoreExtensionSupported = false;
bool ZeExternalSemaphoreExtensionSupported = false;
bool ZeImmediateCommandListAppendExtensionFound = false;
for (auto &extension : ZeExtensions) {
Expand Down Expand Up @@ -260,13 +259,6 @@ ur_result_t ur_platform_handle_t_::initialize() {
MutableCommandListSpecExtensionSupported = true;
}
}
// Check if extension is available for Exp External Sempahores
if (strncmp(extension.name, ZE_INTEL_EXTERNAL_SEMAPHORE_EXP_NAME,
strlen(ZE_INTEL_EXTERNAL_SEMAPHORE_EXP_NAME) + 1) == 0) {
if (extension.version == ZE_EXTERNAL_SEMAPHORE_EXP_VERSION_1_0) {
ZeIntelExternalSemaphoreExtensionSupported = true;
}
}
// Check if extension is available for Spec External Sempahores
if (strncmp(extension.name, ZE_EXTERNAL_SEMAPHORES_EXTENSION_NAME,
strlen(ZE_EXTERNAL_SEMAPHORES_EXTENSION_NAME) + 1) == 0) {
Expand Down Expand Up @@ -380,38 +372,6 @@ ur_result_t ur_platform_handle_t_::initialize() {
.zexCommandListAppendSignalExternalSemaphoresExp != nullptr;
ZeExternalSemaphoreExt.Supported |=
ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp != nullptr;
ZeExternalSemaphoreExt.LoaderExtension = true;
} else if (ZeIntelExternalSemaphoreExtensionSupported) {
ZeExternalSemaphoreExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeIntelDeviceImportExternalSemaphoreExp",
reinterpret_cast<void **>(
&ZeExternalSemaphoreExt.zexExpImportExternalSemaphoreExp))) ==
0);
ZeExternalSemaphoreExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeIntelCommandListAppendWaitExternalSemaphoresExp",
reinterpret_cast<void **>(
&ZeExternalSemaphoreExt
.zexExpCommandListAppendWaitExternalSemaphoresExp))) ==
0);
ZeExternalSemaphoreExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeIntelCommandListAppendSignalExternalSemaphoresExp",
reinterpret_cast<void **>(
&ZeExternalSemaphoreExt
.zexExpCommandListAppendSignalExternalSemaphoresExp))) ==
0);
ZeExternalSemaphoreExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeIntelDeviceReleaseExternalSemaphoreExp",
reinterpret_cast<void **>(
&ZeExternalSemaphoreExt
.zexExpDeviceReleaseExternalSemaphoreExp))) == 0);
}

// Check if mutable command list extension is supported and initialize
Expand Down
Loading