@@ -92,7 +92,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
9292
9393 try {
9494 auto URCommandBuffer = std::make_unique<ur_exp_command_buffer_handle_t_>(
95- Queue, hContext, CLCommandBuffer, IsUpdatable);
95+ Queue, hContext, hDevice, CLCommandBuffer, IsUpdatable);
9696 *phCommandBuffer = URCommandBuffer.release ();
9797 } catch (...) {
9898 return UR_RESULT_ERROR_OUT_OF_RESOURCES;
@@ -540,18 +540,72 @@ void updateKernelArgs(std::vector<cl_mutable_dispatch_arg_khr> &CLArgs,
540540 }
541541}
542542
543+ ur_result_t validateCommandDesc (
544+ ur_exp_command_buffer_command_handle_t Command,
545+ const ur_exp_command_buffer_update_kernel_launch_desc_t *UpdateDesc) {
546+ // Kernel handle updates are not yet supported.
547+ if (UpdateDesc->hNewKernel && UpdateDesc->hNewKernel != Command->Kernel ) {
548+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
549+ }
550+
551+ // Error if work-dim has change but a new global size/offset hasn't been set
552+ if (UpdateDesc->newWorkDim != Command->WorkDim &&
553+ (!UpdateDesc->pNewGlobalWorkOffset || !UpdateDesc->pNewGlobalWorkSize )) {
554+ return UR_RESULT_ERROR_INVALID_OPERATION;
555+ }
556+
557+ // Verify that the device supports updating the aspects of the kernel that
558+ // the user is requesting.
559+ ur_device_handle_t URDevice = Command->hCommandBuffer ->hDevice ;
560+ cl_device_id CLDevice = cl_adapter::cast<cl_device_id>(URDevice);
561+
562+ ur_device_command_buffer_update_capability_flags_t UpdateCapabilities = 0 ;
563+ CL_RETURN_ON_FAILURE (
564+ getDeviceCommandBufferUpdateCapabilities (CLDevice, UpdateCapabilities));
565+
566+ size_t *NewGlobalWorkOffset = UpdateDesc->pNewGlobalWorkOffset ;
567+ UR_ASSERT (
568+ !NewGlobalWorkOffset ||
569+ (UpdateCapabilities &
570+ UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_OFFSET),
571+ UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
572+
573+ size_t *NewLocalWorkSize = UpdateDesc->pNewLocalWorkSize ;
574+ UR_ASSERT (
575+ !NewLocalWorkSize ||
576+ (UpdateCapabilities &
577+ UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE),
578+ UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
579+
580+ size_t *NewGlobalWorkSize = UpdateDesc->pNewGlobalWorkSize ;
581+ UR_ASSERT (
582+ !NewGlobalWorkSize ||
583+ (UpdateCapabilities &
584+ UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_SIZE),
585+ UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
586+ UR_ASSERT (
587+ !(NewGlobalWorkSize && !NewLocalWorkSize) ||
588+ (UpdateCapabilities &
589+ UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE),
590+ UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
591+
592+ UR_ASSERT (
593+ (!UpdateDesc->numNewMemObjArgs && !UpdateDesc->numNewPointerArgs &&
594+ !UpdateDesc->numNewValueArgs ) ||
595+ (UpdateCapabilities &
596+ UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_ARGUMENTS),
597+ UR_RESULT_ERROR_UNSUPPORTED_FEATURE);
598+
599+ return UR_RESULT_SUCCESS;
600+ }
543601} // end anonymous namespace
544602
545603UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp (
546604 ur_exp_command_buffer_command_handle_t hCommand,
547605 const ur_exp_command_buffer_update_kernel_launch_desc_t
548606 *pUpdateKernelLaunch) {
549607
550- // Kernel handle updates are not yet supported.
551- if (pUpdateKernelLaunch->hNewKernel &&
552- pUpdateKernelLaunch->hNewKernel != hCommand->Kernel ) {
553- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
554- }
608+ UR_RETURN_ON_FAILURE (validateCommandDesc (hCommand, pUpdateKernelLaunch));
555609
556610 ur_exp_command_buffer_handle_t hCommandBuffer = hCommand->hCommandBuffer ;
557611 cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext );
@@ -565,12 +619,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
565619 if (!hCommandBuffer->IsFinalized || !hCommandBuffer->IsUpdatable )
566620 return UR_RESULT_ERROR_INVALID_OPERATION;
567621
568- if (pUpdateKernelLaunch->newWorkDim != hCommand->WorkDim &&
569- (!pUpdateKernelLaunch->pNewGlobalWorkOffset ||
570- !pUpdateKernelLaunch->pNewGlobalWorkSize )) {
571- return UR_RESULT_ERROR_INVALID_OPERATION;
572- }
573-
574622 // Find the CL USM pointer arguments to the kernel to update
575623 std::vector<cl_mutable_dispatch_arg_khr> CLUSMArgs;
576624 updateKernelPointerArgs (CLUSMArgs, pUpdateKernelLaunch);
0 commit comments