@@ -92,7 +92,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
92
92
93
93
try {
94
94
auto URCommandBuffer = std::make_unique<ur_exp_command_buffer_handle_t_>(
95
- Queue, hContext, CLCommandBuffer, IsUpdatable);
95
+ Queue, hContext, hDevice, CLCommandBuffer, IsUpdatable);
96
96
*phCommandBuffer = URCommandBuffer.release ();
97
97
} catch (...) {
98
98
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
@@ -540,18 +540,72 @@ void updateKernelArgs(std::vector<cl_mutable_dispatch_arg_khr> &CLArgs,
540
540
}
541
541
}
542
542
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
+ }
543
601
} // end anonymous namespace
544
602
545
603
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp (
546
604
ur_exp_command_buffer_command_handle_t hCommand,
547
605
const ur_exp_command_buffer_update_kernel_launch_desc_t
548
606
*pUpdateKernelLaunch) {
549
607
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));
555
609
556
610
ur_exp_command_buffer_handle_t hCommandBuffer = hCommand->hCommandBuffer ;
557
611
cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext );
@@ -565,12 +619,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
565
619
if (!hCommandBuffer->IsFinalized || !hCommandBuffer->IsUpdatable )
566
620
return UR_RESULT_ERROR_INVALID_OPERATION;
567
621
568
- if (pUpdateKernelLaunch->newWorkDim != hCommand->WorkDim &&
569
- (!pUpdateKernelLaunch->pNewGlobalWorkOffset ||
570
- !pUpdateKernelLaunch->pNewGlobalWorkSize )) {
571
- return UR_RESULT_ERROR_INVALID_OPERATION;
572
- }
573
-
574
622
// Find the CL USM pointer arguments to the kernel to update
575
623
std::vector<cl_mutable_dispatch_arg_khr> CLUSMArgs;
576
624
updateKernelPointerArgs (CLUSMArgs, pUpdateKernelLaunch);
0 commit comments