Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UR] Update spec to make kernel argument validation in urEnqueueKernelLaunch optional #17068

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions unified-runtime/include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7431,6 +7431,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(
///////////////////////////////////////////////////////////////////////////////
/// @brief Enqueue a command to execute a kernel
///
/// @details
/// - Adapters may perform validation on the number of arguments set to the
/// kernel, but are not required to do so and may return
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just say that passing incorrect kernel arguments is "undefined behavior" or something like that.

As shown in the test, if an adapter is unable to validate the arguments it's unlikely to be able to gracefully return success as well.

If we want to keep some level of argument validation, maybe it could be guarded behind a device property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the benefits of marking it as UB are worthwhile, especially since I don't think we have (explicit) UB anywhere else in UR. Cuda seems to be the only target with major issues with invalid arguments, do you see that resulting in UB?

///
/// @remarks
/// _Analogues_
/// - **clEnqueueNDRangeKernel**
Expand Down Expand Up @@ -7458,8 +7463,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values
/// have not been specified."
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
/// + The kernel argument values have not been specified and the adapter
/// is able to detect this.
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
Expand Down
7 changes: 5 additions & 2 deletions unified-runtime/scripts/core/enqueue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type: function
desc: "Enqueue a command to execute a kernel"
class: $xEnqueue
name: KernelLaunch
details:
- "Adapters may perform validation on the number of arguments set to the kernel, but are not required to do so and may
return `$X_RESULT_SUCCESS` even for invalid invocations."
ordinal: "0"
analogue:
- "**clEnqueueNDRangeKernel**"
Expand Down Expand Up @@ -65,8 +68,8 @@ returns:
- $X_RESULT_ERROR_INVALID_WORK_DIMENSION
- $X_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
- $X_RESULT_ERROR_INVALID_VALUE
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS
- "The kernel argument values have not been specified."
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS:
- "The kernel argument values have not been specified and the adapter is able to detect this."
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
- $X_RESULT_ERROR_OUT_OF_RESOURCES
--- #--------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions unified-runtime/source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4982,6 +4982,11 @@ ur_result_t UR_APICALL urEventSetCallback(
///////////////////////////////////////////////////////////////////////////////
/// @brief Enqueue a command to execute a kernel
///
/// @details
/// - Adapters may perform validation on the number of arguments set to the
/// kernel, but are not required to do so and may return
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
///
/// @remarks
/// _Analogues_
/// - **clEnqueueNDRangeKernel**
Expand Down Expand Up @@ -5009,8 +5014,9 @@ ur_result_t UR_APICALL urEventSetCallback(
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values
/// have not been specified."
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
/// + The kernel argument values have not been specified and the adapter
/// is able to detect this.
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
ur_result_t UR_APICALL urEnqueueKernelLaunch(
Expand Down
10 changes: 8 additions & 2 deletions unified-runtime/source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4347,6 +4347,11 @@ ur_result_t UR_APICALL urEventSetCallback(
///////////////////////////////////////////////////////////////////////////////
/// @brief Enqueue a command to execute a kernel
///
/// @details
/// - Adapters may perform validation on the number of arguments set to the
/// kernel, but are not required to do so and may return
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
///
/// @remarks
/// _Analogues_
/// - **clEnqueueNDRangeKernel**
Expand Down Expand Up @@ -4374,8 +4379,9 @@ ur_result_t UR_APICALL urEventSetCallback(
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
/// - ::UR_RESULT_ERROR_INVALID_VALUE
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values
/// have not been specified."
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
/// + The kernel argument values have not been specified and the adapter
/// is able to detect this.
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
ur_result_t UR_APICALL urEnqueueKernelLaunch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,19 @@ TEST_P(urEnqueueKernelLaunchTest, InvalidWorkGroupSize) {
}

TEST_P(urEnqueueKernelLaunchTest, InvalidKernelArgs) {
// Cuda and hip both lack any way to validate kernel args
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});

ur_platform_backend_t backend;
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
sizeof(ur_platform_backend_t), &backend,
nullptr));

if (backend == UR_PLATFORM_BACKEND_CUDA ||
backend == UR_PLATFORM_BACKEND_HIP ||
backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
GTEST_FAIL() << "AMD, L0 and Nvidia can't check kernel arguments.";
}
// Seems to segfault
UUR_KNOWN_FAILURE_ON(uur::HIP{});
// cuLaunchKernel seems to be returning CUDA_ERROR_INVALID_VALUE which is
// converted to UR_RESULT_ERROR_INVALID_VALUE
// https://github.com/oneapi-src/unified-runtime/issues/2720
UUR_KNOWN_FAILURE_ON(uur::CUDA{});

// Enqueue kernel without setting any args
ASSERT_EQ_RESULT(urEnqueueKernelLaunch(queue, kernel, n_dimensions,
&global_offset, &global_size, nullptr,
0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_KERNEL_ARGS);
auto error =
urEnqueueKernelLaunch(queue, kernel, n_dimensions, &global_offset,
&global_size, nullptr, 0, nullptr, nullptr);
ASSERT_TRUE(error == UR_RESULT_ERROR_INVALID_KERNEL_ARGS ||
error == UR_RESULT_SUCCESS);
}

TEST_P(urEnqueueKernelLaunchKernelWgSizeTest, Success) {
Expand Down
Loading