diff --git a/test/conformance/exp_command_buffer/exp_command_buffer_adapter_hip.match b/test/conformance/exp_command_buffer/exp_command_buffer_adapter_hip.match index a39a452d04..e69de29bb2 100644 --- a/test/conformance/exp_command_buffer/exp_command_buffer_adapter_hip.match +++ b/test/conformance/exp_command_buffer/exp_command_buffer_adapter_hip.match @@ -1,4 +0,0 @@ -urCommandBufferKernelHandleUpdateTest.Success/AMD_HIP_BACKEND___{{.*}}_ -urCommandBufferKernelHandleUpdateTest.UpdateAgain/AMD_HIP_BACKEND___{{.*}}_ -urCommandBufferKernelHandleUpdateTest.KernelAlternativeNotRegistered/AMD_HIP_BACKEND___{{.*}}_ -urCommandBufferKernelHandleUpdateTest.RegisterInvalidKernelAlternative/AMD_HIP_BACKEND___{{.*}}_ diff --git a/test/conformance/exp_command_buffer/exp_command_buffer_adapter_native_cpu.match b/test/conformance/exp_command_buffer/exp_command_buffer_adapter_native_cpu.match index a4b2789372..765a5d44c9 100644 --- a/test/conformance/exp_command_buffer/exp_command_buffer_adapter_native_cpu.match +++ b/test/conformance/exp_command_buffer/exp_command_buffer_adapter_native_cpu.match @@ -13,8 +13,6 @@ {{OPT}}InvalidUpdateTest.NotFinalizedCommandBuffer/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}InvalidUpdateTest.NotUpdatableCommandBuffer/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}InvalidUpdateTest.GlobalLocalSizeMistach/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} -{{OPT}}InvalidUpdateTest.ImplToUserDefinedLocalSize/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} -{{OPT}}InvalidUpdateTest.UserToImplDefinedLocalSize/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}InvalidUpdateTest.InvalidDimensions/SYCL_NATIVE_CPU___SYCL_Native_CPU__X_ {{OPT}}USMFillCommandTest.UpdateParameters/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}USMFillCommandTest.UpdateBeforeEnqueue/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} @@ -23,7 +21,8 @@ {{OPT}}NDRangeUpdateTest.Update3D/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}NDRangeUpdateTest.Update2D/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}NDRangeUpdateTest.Update1D/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} -{{OPT}}NDRangeUpdateTest.Invalid/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +{{OPT}}NDRangeUpdateTest.ImplToUserDefinedLocalSize/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +{{OPT}}NDRangeUpdateTest.UserToImplDefinedLocalSize/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}USMSaxpyKernelTest.UpdateParameters/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}USMMultiSaxpyKernelTest.UpdateParameters/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}USMMultiSaxpyKernelTest.UpdateWithoutBlocking/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} diff --git a/test/conformance/exp_command_buffer/update/invalid_update.cpp b/test/conformance/exp_command_buffer/update/invalid_update.cpp index 2ebd328630..6c9c2b3dce 100644 --- a/test/conformance/exp_command_buffer/update/invalid_update.cpp +++ b/test/conformance/exp_command_buffer/update/invalid_update.cpp @@ -197,77 +197,6 @@ TEST_P(InvalidUpdateTest, GlobalLocalSizeMistach) { ASSERT_EQ(UR_RESULT_ERROR_INVALID_OPERATION, result); } -//// Test setting `pNewLocalWorkSize` to a non-NULL value when the command was -//// created with a NULL local work size gives the correct error. -//TEST_P(InvalidUpdateTest, ImplToUserDefinedLocalSize) { -// // Append kernel command to command-buffer using NULL local work size -// ur_exp_command_buffer_command_handle_t second_command_handle = nullptr; -// ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( -// updatable_cmd_buf_handle, kernel, n_dimensions, &global_offset, -// &global_size, nullptr, 0, nullptr, 0, nullptr, nullptr, -// &second_command_handle)); -// ASSERT_NE(second_command_handle, nullptr); -// -// EXPECT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); -// finalized = true; -// -// size_t new_global_size = 64; -// size_t new_local_size = 16; -// ur_exp_command_buffer_update_kernel_launch_desc_t update_desc = { -// UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC, // stype -// nullptr, // pNext -// kernel, // hNewKernel -// 0, // numNewMemObjArgs -// 0, // numNewPointerArgs -// 0, // numNewValueArgs -// n_dimensions, // newWorkDim -// nullptr, // pNewMemObjArgList -// nullptr, // pNewPointerArgList -// nullptr, // pNewValueArgList -// nullptr, // pNewGlobalWorkOffset -// &new_global_size, // pNewGlobalWorkSize -// &new_local_size, // pNewLocalWorkSize -// }; -// -// // Update command local size to non-NULL when created with NULL value -// ur_result_t result = urCommandBufferUpdateKernelLaunchExp( -// second_command_handle, &update_desc); -// EXPECT_EQ(UR_RESULT_ERROR_INVALID_OPERATION, result); -// -// if (second_command_handle) { -// EXPECT_SUCCESS(urCommandBufferReleaseCommandExp(second_command_handle)); -// } -//} - -//// Test setting `pNewLocalWorkSize` to a NULL value when the command was -//// created with a non-NULL local work size gives the correct error. -//TEST_P(InvalidUpdateTest, UserToImplDefinedLocalSize) { -// ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); -// finalized = true; -// -// size_t new_global_size = 64; -// ur_exp_command_buffer_update_kernel_launch_desc_t update_desc = { -// UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC, // stype -// nullptr, // pNext -// kernel, // hNewKernel -// 0, // numNewMemObjArgs -// 0, // numNewPointerArgs -// 0, // numNewValueArgs -// n_dimensions, // newWorkDim -// nullptr, // pNewMemObjArgList -// nullptr, // pNewPointerArgList -// nullptr, // pNewValueArgList -// nullptr, // pNewGlobalWorkOffset -// &new_global_size, // pNewGlobalWorkSize -// nullptr, // pNewLocalWorkSize -// }; -// -// // Update command local size to NULL when created with non-NULL value -// ur_result_t result = -// urCommandBufferUpdateKernelLaunchExp(command_handle, &update_desc); -// ASSERT_EQ(UR_RESULT_ERROR_INVALID_OPERATION, result); -//} - // If the kernel handle is not being updated, then it's invalid to change // the number of dimensions. TEST_P(InvalidUpdateTest, InvalidDimensions) { @@ -291,7 +220,6 @@ TEST_P(InvalidUpdateTest, InvalidDimensions) { nullptr, // pNewLocalWorkSize }; - // Update command local size to NULL when created with non-NULL value ur_result_t result = urCommandBufferUpdateKernelLaunchExp(command_handle, &update_desc); ASSERT_EQ(UR_RESULT_ERROR_INVALID_OPERATION, result); diff --git a/test/conformance/exp_command_buffer/update/ndrange_update.cpp b/test/conformance/exp_command_buffer/update/ndrange_update.cpp index 946be64165..63493660e1 100644 --- a/test/conformance/exp_command_buffer/update/ndrange_update.cpp +++ b/test/conformance/exp_command_buffer/update/ndrange_update.cpp @@ -29,30 +29,34 @@ struct NDRangeUpdateTest std::memset(shared_ptr, 0, allocation_size); ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, shared_ptr)); - - // Add a 3 dimension kernel command to command-buffer and close - // command-buffer - ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( - updatable_cmd_buf_handle, kernel, n_dimensions, - global_offset.data(), global_size.data(), local_size.data(), 0, - nullptr, 0, nullptr, nullptr, &command_handle)); - ASSERT_NE(command_handle, nullptr); - - ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + // + // // Add a 3 dimension kernel command to command-buffer and close + // // command-buffer + // ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + // updatable_cmd_buf_handle, kernel, n_dimensions, + // global_offset.data(), global_size.data(), local_size.data(), 0, + // nullptr, 0, nullptr, nullptr, &command_handle)); + // ASSERT_NE(command_handle, nullptr); + // + // ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); } // For each work-item the kernel prints the global id and local id in each // of the 3 dimensions to an offset in the output based on global linear // id. void Validate(std::array global_size, - std::array local_size, + std::optional> local_size, std::array global_offset) { // DPC++ swaps the X & Z dimension for 3 Dimensional kernels // between those set by user and SPIR-V builtins. // See `ReverseRangeDimensionsForKernel()` in commands.cpp std::swap(global_size[0], global_size[2]); - std::swap(local_size[0], local_size[2]); + + if (local_size.has_value()) { + std::swap(local_size.value()[0], local_size.value()[2]); + } + std::swap(global_offset[0], global_offset[2]); // Verify global ID and local ID of each work item @@ -73,13 +77,15 @@ struct NDRangeUpdateTest EXPECT_EQ(global_id_y, y + global_offset[1]); EXPECT_EQ(global_id_z, z + global_offset[2]); - const int local_id_x = wi_ptr[3]; - const int local_id_y = wi_ptr[4]; - const int local_id_z = wi_ptr[5]; + if (local_size.has_value()) { + const int local_id_x = wi_ptr[3]; + const int local_id_y = wi_ptr[4]; + const int local_id_z = wi_ptr[5]; - EXPECT_EQ(local_id_x, x % local_size[0]); - EXPECT_EQ(local_id_y, y % local_size[1]); - EXPECT_EQ(local_id_z, z % local_size[2]); + EXPECT_EQ(local_id_x, x % local_size.value()[0]); + EXPECT_EQ(local_id_y, y % local_size.value()[1]); + EXPECT_EQ(local_id_z, z % local_size.value()[2]); + } } } } @@ -112,10 +118,17 @@ struct NDRangeUpdateTest UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(NDRangeUpdateTest); -// Keep the kernel work dimensions as 3, and update local size and global -// offset. +// Add a 3 dimension kernel command to the command-buffer and update the +// local size and global offset TEST_P(NDRangeUpdateTest, Update3D) { - // Run command-buffer prior to update an verify output + ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + updatable_cmd_buf_handle, kernel, n_dimensions, global_offset.data(), + global_size.data(), local_size.data(), 0, nullptr, 0, nullptr, nullptr, + &command_handle)); + ASSERT_NE(command_handle, nullptr); + ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + + // Run command-buffer prior to update and verify output ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, nullptr, nullptr)); ASSERT_SUCCESS(urQueueFinish(queue)); @@ -152,9 +165,17 @@ TEST_P(NDRangeUpdateTest, Update3D) { Validate(new_global_size, new_local_size, new_global_offset); } -// Update the kernel work dimensions to use 1 in the Z dimension, -// and update global size, local size, and global offset to new values. +// Add a 3 dimension kernel command to the command-buffer. Update the kernel +// work dimensions to be 1 in the Z dimension, and update global size, local +// size, and global offset to new values. TEST_P(NDRangeUpdateTest, Update2D) { + ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + updatable_cmd_buf_handle, kernel, n_dimensions, global_offset.data(), + global_size.data(), local_size.data(), 0, nullptr, 0, nullptr, nullptr, + &command_handle)); + ASSERT_NE(command_handle, nullptr); + ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + // Run command-buffer prior to update an verify output ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, nullptr, nullptr)); @@ -201,10 +222,18 @@ TEST_P(NDRangeUpdateTest, Update2D) { Validate(new_global_size, new_local_size, new_global_offset); } -// Update the kernel work dimensions to be 1 in Y & Z dimensions, and check -// that the previously set global size, local size, and global offset update +// Add a 3 dimension kernel command to the command-buffer. Update the kernel +// work dimensions to be 1 in the Y & Z dimensions, and check that the +// previously set global size, local size, and global offset update // accordingly. TEST_P(NDRangeUpdateTest, Update1D) { + ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + updatable_cmd_buf_handle, kernel, n_dimensions, global_offset.data(), + global_size.data(), local_size.data(), 0, nullptr, 0, nullptr, nullptr, + &command_handle)); + ASSERT_NE(command_handle, nullptr); + ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + // Run command-buffer prior to update an verify output ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, nullptr, nullptr)); @@ -246,27 +275,106 @@ TEST_P(NDRangeUpdateTest, Update1D) { Validate(new_global_size, new_local_size, new_global_offset); } -// Test error code is returned if work dimension parameter changes -TEST_P(NDRangeUpdateTest, Invalid) { - const size_t new_work_dim = n_dimensions - 1; +// Test that setting `pNewLocalWorkSize` to a non-NULL value when the command +// was created with a NULL local work size works. +TEST_P(NDRangeUpdateTest, ImplToUserDefinedLocalSize) { + + // Append a kernel node without setting the local work-size. + ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + updatable_cmd_buf_handle, kernel, n_dimensions, global_offset.data(), + global_size.data(), nullptr, 0, nullptr, 0, nullptr, nullptr, + &command_handle)); + ASSERT_NE(command_handle, nullptr); + ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + + // Run command-buffer prior to update an verify output + ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, + nullptr, nullptr)); + ASSERT_SUCCESS(urQueueFinish(queue)); + Validate(global_size, std::nullopt, global_offset); + + // Set local size and global offset to update to + std::array new_local_size = {4, 2, 2}; + std::array new_global_offset = {3, 2, 1}; + std::array new_global_size = global_size; + + // Set a user-defined local work-size in the update desc. ur_exp_command_buffer_update_kernel_launch_desc_t update_desc = { UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC, // stype nullptr, // pNext - kernel, // hNewKernel - 0, // numNewMemObjArgs - 0, // numNewPointerArgs - 0, // numNewValueArgs - new_work_dim, // newWorkDim - nullptr, // pNewMemObjArgList - nullptr, // pNewPointerArgList - nullptr, // pNewValueArgList - nullptr, // pNewGlobalWorkOffset - nullptr, // pNewGlobalWorkSize - nullptr, // pNewLocalWorkSize + kernel, // hNewKernel + 0, // numNewMemObjArgs + 0, // numNewPointerArgs + 0, // numNewValueArgs + n_dimensions, // newWorkDim + nullptr, // pNewMemObjArgList + nullptr, // pNewPointerArgList + nullptr, // pNewValueArgList + new_global_offset.data(), // pNewGlobalWorkOffset + new_global_size.data(), // pNewGlobalWorkSize + new_local_size.data(), // pNewLocalWorkSize }; - // Update command to command-buffer to use different work dim - ur_result_t result = - urCommandBufferUpdateKernelLaunchExp(command_handle, &update_desc); - ASSERT_EQ(UR_RESULT_ERROR_INVALID_OPERATION, result); + // Update kernel and enqueue command-buffer again + ASSERT_SUCCESS( + urCommandBufferUpdateKernelLaunchExp(command_handle, &update_desc)); + ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, + nullptr, nullptr)); + ASSERT_SUCCESS(urQueueFinish(queue)); + + // Verify that the use defined local work-size was set correctly. + Validate(new_global_size, new_local_size, new_global_offset); } + +// Test that setting `pNewLocalWorkSize` to a NULL value when the command was +// created with a non-NULL local work size works. +TEST_P(NDRangeUpdateTest, UserToImplDefinedLocalSize) { + + // Append a kernel node and set a user defined local work-size. + ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp( + updatable_cmd_buf_handle, kernel, n_dimensions, global_offset.data(), + global_size.data(), local_size.data(), 0, nullptr, 0, nullptr, nullptr, + &command_handle)); + ASSERT_NE(command_handle, nullptr); + ASSERT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle)); + + // Run command-buffer prior to update and verify output + ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, + nullptr, nullptr)); + ASSERT_SUCCESS(urQueueFinish(queue)); + Validate(global_size, local_size, global_offset); + + // Set local size and global offset to update to + std::array new_global_offset = {3, 2, 1}; + std::array new_global_size = global_size; + + // Do not set a local-work size in the update desc to let the implementation + // decide which local-work size should be used. + ur_exp_command_buffer_update_kernel_launch_desc_t update_desc = { + UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC, // stype + nullptr, // pNext + kernel, // hNewKernel + 0, // numNewMemObjArgs + 0, // numNewPointerArgs + 0, // numNewValueArgs + n_dimensions, // newWorkDim + nullptr, // pNewMemObjArgList + nullptr, // pNewPointerArgList + nullptr, // pNewValueArgList + new_global_offset.data(), // pNewGlobalWorkOffset + new_global_size.data(), // pNewGlobalWorkSize + nullptr, // pNewLocalWorkSize + }; + + // Update kernel and enqueue command-buffer again + ASSERT_SUCCESS( + urCommandBufferUpdateKernelLaunchExp(command_handle, &update_desc)); + ASSERT_SUCCESS(urCommandBufferEnqueueExp(updatable_cmd_buf_handle, queue, 0, + nullptr, nullptr)); + ASSERT_SUCCESS(urQueueFinish(queue)); + + // Verify that the kernel ran successfully and the global size and offset + // have been updated. + Validate(new_global_size, std::nullopt, new_global_offset); +} +