Skip to content

Commit 2a85354

Browse files
committed
Merge branch 'sycl' into review/yang/msan_device_global
2 parents 55de1fb + b2ac58f commit 2a85354

File tree

14 files changed

+502
-66
lines changed

14 files changed

+502
-66
lines changed

include/ur_api.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8508,8 +8508,8 @@ typedef struct ur_exp_command_buffer_command_handle_t_ *ur_exp_command_buffer_co
85088508
/// + `NULL == phCommandBuffer`
85098509
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
85108510
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
8511-
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
8512-
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP.
8511+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
8512+
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` returns 0 for the ::UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP query.
85138513
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
85148514
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
85158515
UR_APIEXPORT ur_result_t UR_APICALL
@@ -9315,11 +9315,17 @@ urCommandBufferReleaseCommandExp(
93159315
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
93169316
/// + `NULL == pUpdateKernelLaunch`
93179317
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
9318-
/// + If update functionality is not supported by the device.
9318+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_ARGUMENTS is not supported by the device, but any of `pUpdateKernelLaunch->numNewMemObjArgs`, `pUpdateKernelLaunch->numNewPointerArgs`, or `pUpdateKernelLaunch->numNewValueArgs` are not zero.
9319+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewLocalWorkSize` is not nullptr.
9320+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewLocalWorkSize` is nullptr and `pUpdateKernelLaunch->pNewGlobalWorkSize` is not nullptr.
9321+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewGlobalWorkSize` is not nullptr
9322+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_OFFSET is not supported by the device but `pUpdateKernelLaunch->pNewGlobalWorkOffset` is not nullptr.
9323+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_HANDLE is not supported by the device but `pUpdateKernelLaunch->hNewKernel` is not nullptr.
93199324
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
93209325
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to.
93219326
/// + If the command-buffer `hCommand` belongs to has not been finalized.
9322-
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP - "If `hCommand` is not a kernel execution command."
9327+
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
9328+
/// + If `hCommand` is not a kernel execution command.
93239329
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
93249330
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
93259331
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE
@@ -9329,7 +9335,7 @@ urCommandBufferReleaseCommandExp(
93299335
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
93309336
/// - ::UR_RESULT_ERROR_INVALID_VALUE
93319337
/// + If `pUpdateKernelLaunch->hNewKernel` was not passed to the `hKernel` or `phKernelAlternatives` parameters of ::urCommandBufferAppendKernelLaunchExp when this command was created.
9332-
/// + If `pUpdateKernelLaunch->newWorkDim` is different from the current workDim in `hCommand` and, pUpdateKernelLaunch->pNewGlobalWorkSize, or pUpdateKernelLaunch->pNewGlobalWorkOffset are nullptr.
9338+
/// + If `pUpdateKernelLaunch->newWorkDim` is different from the current workDim in `hCommand` and, `pUpdateKernelLaunch->pNewGlobalWorkSize`, or `pUpdateKernelLaunch->pNewGlobalWorkOffset` are nullptr.
93339339
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
93349340
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
93359341
UR_APIEXPORT ur_result_t UR_APICALL
@@ -9355,7 +9361,7 @@ urCommandBufferUpdateKernelLaunchExp(
93559361
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
93569362
/// + `NULL == phSignalEvent`
93579363
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
9358-
/// + If UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`.
9364+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`.
93599365
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
93609366
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to.
93619367
/// + If the command-buffer `hCommand` belongs to has not been finalized.
@@ -9382,7 +9388,7 @@ urCommandBufferUpdateSignalEventExp(
93829388
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
93839389
/// + `NULL == hCommand`
93849390
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
9385-
/// + If UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`.
9391+
/// + If ::UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`.
93869392
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
93879393
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to.
93889394
/// + If the command-buffer `hCommand` belongs to has not been finalized.

scripts/core/exp-command-buffer.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ params:
289289
returns:
290290
- $X_RESULT_ERROR_INVALID_CONTEXT
291291
- $X_RESULT_ERROR_INVALID_DEVICE
292-
- $X_RESULT_ERROR_INVALID_OPERATION:
293-
- "If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP."
292+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
293+
- "If `pCommandBufferDesc->isUpdatable` is true and `hDevice` returns 0
294+
for the $X_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP query."
294295
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
295296
- $X_RESULT_ERROR_OUT_OF_RESOURCES
296297
--- #--------------------------------------------------------------------------
@@ -1203,11 +1204,16 @@ params:
12031204
desc: "[in] Struct defining how the kernel command is to be updated."
12041205
returns:
12051206
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
1206-
- "If update functionality is not supported by the device."
1207+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_ARGUMENTS is not supported by the device, but any of `pUpdateKernelLaunch->numNewMemObjArgs`, `pUpdateKernelLaunch->numNewPointerArgs`, or `pUpdateKernelLaunch->numNewValueArgs` are not zero."
1208+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewLocalWorkSize` is not nullptr."
1209+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewLocalWorkSize` is nullptr and `pUpdateKernelLaunch->pNewGlobalWorkSize` is not nullptr."
1210+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_SIZE is not supported by the device but `pUpdateKernelLaunch->pNewGlobalWorkSize` is not nullptr"
1211+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_OFFSET is not supported by the device but `pUpdateKernelLaunch->pNewGlobalWorkOffset` is not nullptr."
1212+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_HANDLE is not supported by the device but `pUpdateKernelLaunch->hNewKernel` is not nullptr."
12071213
- $X_RESULT_ERROR_INVALID_OPERATION:
12081214
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
12091215
- "If the command-buffer `hCommand` belongs to has not been finalized."
1210-
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
1216+
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP:
12111217
- "If `hCommand` is not a kernel execution command."
12121218
- $X_RESULT_ERROR_INVALID_MEM_OBJECT
12131219
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
@@ -1218,7 +1224,7 @@ returns:
12181224
- $X_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
12191225
- $X_RESULT_ERROR_INVALID_VALUE:
12201226
- "If `pUpdateKernelLaunch->hNewKernel` was not passed to the `hKernel` or `phKernelAlternatives` parameters of $xCommandBufferAppendKernelLaunchExp when this command was created."
1221-
- "If `pUpdateKernelLaunch->newWorkDim` is different from the current workDim in `hCommand` and, pUpdateKernelLaunch->pNewGlobalWorkSize, or pUpdateKernelLaunch->pNewGlobalWorkOffset are nullptr."
1227+
- "If `pUpdateKernelLaunch->newWorkDim` is different from the current workDim in `hCommand` and, `pUpdateKernelLaunch->pNewGlobalWorkSize`, or `pUpdateKernelLaunch->pNewGlobalWorkOffset` are nullptr."
12221228
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
12231229
- $X_RESULT_ERROR_OUT_OF_RESOURCES
12241230
--- #--------------------------------------------------------------------------
@@ -1236,7 +1242,7 @@ params:
12361242
desc: "[out] Event to be signaled."
12371243
returns:
12381244
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
1239-
- "If UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
1245+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
12401246
- $X_RESULT_ERROR_INVALID_OPERATION:
12411247
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
12421248
- "If the command-buffer `hCommand` belongs to has not been finalized."
@@ -1262,7 +1268,7 @@ params:
12621268
desc: "[in][optional][range(0, numEventsInWaitList)] pointer to a list of events that must be complete before the command execution. If nullptr, the numEventsInWaitList must be 0, indicating no wait events."
12631269
returns:
12641270
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
1265-
- "If UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
1271+
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
12661272
- $X_RESULT_ERROR_INVALID_OPERATION:
12671273
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
12681274
- "If the command-buffer `hCommand` belongs to has not been finalized."

source/adapters/level_zero/command_buffer.cpp

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -949,41 +949,53 @@ createCommandHandle(ur_exp_command_buffer_handle_t CommandBuffer,
949949

950950
auto Platform = CommandBuffer->Context->getPlatform();
951951
auto ZeDevice = CommandBuffer->Device->ZeDevice;
952+
ze_command_list_handle_t ZeCommandList =
953+
CommandBuffer->ZeComputeCommandListTranslated;
954+
if (Platform->ZeMutableCmdListExt.LoaderExtension) {
955+
ZeCommandList = CommandBuffer->ZeComputeCommandList;
956+
}
952957

953958
if (NumKernelAlternatives > 0) {
954959
ZeMutableCommandDesc.flags |=
955960
ZE_MUTABLE_COMMAND_EXP_FLAG_KERNEL_INSTRUCTION;
956961

957-
std::vector<ze_kernel_handle_t> TranslatedKernelHandles(
958-
NumKernelAlternatives + 1, nullptr);
962+
std::vector<ze_kernel_handle_t> KernelHandles(NumKernelAlternatives + 1,
963+
nullptr);
959964

960965
ze_kernel_handle_t ZeMainKernel{};
961966
UR_CALL(getZeKernel(ZeDevice, Kernel, &ZeMainKernel));
962967

963-
// Translate main kernel first
964-
ZE2UR_CALL(zelLoaderTranslateHandle,
965-
(ZEL_HANDLE_KERNEL, ZeMainKernel,
966-
(void **)&TranslatedKernelHandles[0]));
968+
if (Platform->ZeMutableCmdListExt.LoaderExtension) {
969+
KernelHandles[0] = ZeMainKernel;
970+
} else {
971+
// If the L0 loader is not aware of the MCL extension, the main kernel
972+
// handle needs to be translated.
973+
ZE2UR_CALL(zelLoaderTranslateHandle,
974+
(ZEL_HANDLE_KERNEL, ZeMainKernel, (void **)&KernelHandles[0]));
975+
}
967976

968977
for (size_t i = 0; i < NumKernelAlternatives; i++) {
969978
ze_kernel_handle_t ZeAltKernel{};
970979
UR_CALL(getZeKernel(ZeDevice, KernelAlternatives[i], &ZeAltKernel));
971980

972-
ZE2UR_CALL(zelLoaderTranslateHandle,
973-
(ZEL_HANDLE_KERNEL, ZeAltKernel,
974-
(void **)&TranslatedKernelHandles[i + 1]));
981+
if (Platform->ZeMutableCmdListExt.LoaderExtension) {
982+
KernelHandles[i + 1] = ZeAltKernel;
983+
} else {
984+
// If the L0 loader is not aware of the MCL extension, the kernel
985+
// alternatives need to be translated.
986+
ZE2UR_CALL(zelLoaderTranslateHandle, (ZEL_HANDLE_KERNEL, ZeAltKernel,
987+
(void **)&KernelHandles[i + 1]));
988+
}
975989
}
976990

977991
ZE2UR_CALL(Platform->ZeMutableCmdListExt
978992
.zexCommandListGetNextCommandIdWithKernelsExp,
979-
(CommandBuffer->ZeComputeCommandListTranslated,
980-
&ZeMutableCommandDesc, NumKernelAlternatives + 1,
981-
TranslatedKernelHandles.data(), &CommandId));
993+
(ZeCommandList, &ZeMutableCommandDesc, NumKernelAlternatives + 1,
994+
KernelHandles.data(), &CommandId));
982995

983996
} else {
984997
ZE2UR_CALL(Platform->ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp,
985-
(CommandBuffer->ZeComputeCommandListTranslated,
986-
&ZeMutableCommandDesc, &CommandId));
998+
(ZeCommandList, &ZeMutableCommandDesc, &CommandId));
987999
}
9881000
DEBUG_LOG(CommandId);
9891001

@@ -1863,17 +1875,22 @@ ur_result_t updateKernelCommand(
18631875
ur_kernel_handle_t NewKernel = CommandDesc->hNewKernel;
18641876

18651877
if (NewKernel && Command->Kernel != NewKernel) {
1878+
ze_kernel_handle_t KernelHandle{};
18661879
ze_kernel_handle_t ZeNewKernel{};
18671880
UR_CALL(getZeKernel(ZeDevice, NewKernel, &ZeNewKernel));
18681881

1869-
ze_kernel_handle_t ZeKernelTranslated = nullptr;
1870-
ZE2UR_CALL(zelLoaderTranslateHandle,
1871-
(ZEL_HANDLE_KERNEL, ZeNewKernel, (void **)&ZeKernelTranslated));
1882+
ze_command_list_handle_t ZeCommandList =
1883+
CommandBuffer->ZeComputeCommandList;
1884+
KernelHandle = ZeNewKernel;
1885+
if (!Platform->ZeMutableCmdListExt.LoaderExtension) {
1886+
ZeCommandList = CommandBuffer->ZeComputeCommandListTranslated;
1887+
ZE2UR_CALL(zelLoaderTranslateHandle,
1888+
(ZEL_HANDLE_KERNEL, ZeNewKernel, (void **)&KernelHandle));
1889+
}
18721890

18731891
ZE2UR_CALL(Platform->ZeMutableCmdListExt
18741892
.zexCommandListUpdateMutableCommandKernelsExp,
1875-
(CommandBuffer->ZeComputeCommandListTranslated, 1,
1876-
&Command->CommandId, &ZeKernelTranslated));
1893+
(ZeCommandList, 1, &Command->CommandId, &KernelHandle));
18771894
// Set current kernel to be the new kernel
18781895
Command->Kernel = NewKernel;
18791896
}
@@ -2079,9 +2096,15 @@ ur_result_t updateKernelCommand(
20792096
MutableCommandDesc.pNext = NextDesc;
20802097
MutableCommandDesc.flags = 0;
20812098

2099+
ze_command_list_handle_t ZeCommandList =
2100+
CommandBuffer->ZeComputeCommandListTranslated;
2101+
if (Platform->ZeMutableCmdListExt.LoaderExtension) {
2102+
ZeCommandList = CommandBuffer->ZeComputeCommandList;
2103+
}
2104+
20822105
ZE2UR_CALL(
20832106
Platform->ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp,
2084-
(CommandBuffer->ZeComputeCommandListTranslated, &MutableCommandDesc));
2107+
(ZeCommandList, &MutableCommandDesc));
20852108

20862109
return UR_RESULT_SUCCESS;
20872110
}

source/adapters/level_zero/platform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
386386
ZeMutableCmdListExt.Supported |=
387387
ZeMutableCmdListExt.zexCommandListGetNextCommandIdWithKernelsExp !=
388388
nullptr;
389+
ZeMutableCmdListExt.LoaderExtension = true;
389390
} else {
390391
ZeMutableCmdListExt.Supported |=
391392
(ZE_CALL_NOCHECK(

source/adapters/level_zero/platform.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ struct ur_platform_handle_t_ : public _ur_platform {
9696
// associated with particular Level Zero driver, store this extension here.
9797
struct ZeMutableCmdListExtension {
9898
bool Supported = false;
99+
// If LoaderExtension is true, the L0 loader is aware of the MCL extension.
100+
// If it is false, the extension has to be loaded directly from the driver
101+
// using zeDriverGetExtensionFunctionAddress. If it is loaded directly from
102+
// the driver, any handles passed to it must be translated using
103+
// zelLoaderTranslateHandle.
104+
bool LoaderExtension = false;
99105
ze_result_t (*zexCommandListGetNextCommandIdExp)(
100106
ze_command_list_handle_t, const ze_mutable_command_id_exp_desc_t *,
101107
uint64_t *) = nullptr;

0 commit comments

Comments
 (0)