Skip to content

Commit b58991e

Browse files
committed
Update spec to make kernel validation optional
Several adapters don't support validating kernel signatures when enqueued. To handle this, we now allow urEnqueueKernelLaunch to return `SUCCESS` even when parameters are invalid.
1 parent 6a3fece commit b58991e

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

include/ur_api.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6204,6 +6204,11 @@ urEventSetCallback(
62046204
///////////////////////////////////////////////////////////////////////////////
62056205
/// @brief Enqueue a command to execute a kernel
62066206
///
6207+
/// @details
6208+
/// - Adapters may perform validation on the number of arguments set to the
6209+
/// kernel, but are not required to do so and may return
6210+
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
6211+
///
62076212
/// @remarks
62086213
/// _Analogues_
62096214
/// - **clEnqueueNDRangeKernel**
@@ -6231,7 +6236,8 @@ urEventSetCallback(
62316236
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
62326237
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
62336238
/// - ::UR_RESULT_ERROR_INVALID_VALUE
6234-
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values have not been specified."
6239+
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
6240+
/// + The kernel argument values have not been specified and the adapter is able to detect this.
62356241
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
62366242
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
62376243
UR_APIEXPORT ur_result_t UR_APICALL

scripts/core/enqueue.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type: function
1616
desc: "Enqueue a command to execute a kernel"
1717
class: $xEnqueue
1818
name: KernelLaunch
19+
details:
20+
- "Adapters may perform validation on the number of arguments set to the kernel, but are not required to do so and may
21+
return `$X_RESULT_SUCCESS` even for invalid invocations."
1922
ordinal: "0"
2023
analogue:
2124
- "**clEnqueueNDRangeKernel**"
@@ -65,8 +68,8 @@ returns:
6568
- $X_RESULT_ERROR_INVALID_WORK_DIMENSION
6669
- $X_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
6770
- $X_RESULT_ERROR_INVALID_VALUE
68-
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS
69-
- "The kernel argument values have not been specified."
71+
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS:
72+
- "The kernel argument values have not been specified and the adapter is able to detect this."
7073
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
7174
- $X_RESULT_ERROR_OUT_OF_RESOURCES
7275
--- #--------------------------------------------------------------------------

source/loader/ur_libapi.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4953,6 +4953,11 @@ ur_result_t UR_APICALL urEventSetCallback(
49534953
///////////////////////////////////////////////////////////////////////////////
49544954
/// @brief Enqueue a command to execute a kernel
49554955
///
4956+
/// @details
4957+
/// - Adapters may perform validation on the number of arguments set to the
4958+
/// kernel, but are not required to do so and may return
4959+
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
4960+
///
49564961
/// @remarks
49574962
/// _Analogues_
49584963
/// - **clEnqueueNDRangeKernel**
@@ -4980,7 +4985,8 @@ ur_result_t UR_APICALL urEventSetCallback(
49804985
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
49814986
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
49824987
/// - ::UR_RESULT_ERROR_INVALID_VALUE
4983-
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values have not been specified."
4988+
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
4989+
/// + The kernel argument values have not been specified and the adapter is able to detect this.
49844990
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
49854991
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
49864992
ur_result_t UR_APICALL urEnqueueKernelLaunch(

source/ur_api.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,11 @@ ur_result_t UR_APICALL urEventSetCallback(
42024202
///////////////////////////////////////////////////////////////////////////////
42034203
/// @brief Enqueue a command to execute a kernel
42044204
///
4205+
/// @details
4206+
/// - Adapters may perform validation on the number of arguments set to the
4207+
/// kernel, but are not required to do so and may return
4208+
/// `::UR_RESULT_SUCCESS` even for invalid invocations.
4209+
///
42054210
/// @remarks
42064211
/// _Analogues_
42074212
/// - **clEnqueueNDRangeKernel**
@@ -4229,7 +4234,8 @@ ur_result_t UR_APICALL urEventSetCallback(
42294234
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
42304235
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
42314236
/// - ::UR_RESULT_ERROR_INVALID_VALUE
4232-
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS - "The kernel argument values have not been specified."
4237+
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGS
4238+
/// + The kernel argument values have not been specified and the adapter is able to detect this.
42334239
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
42344240
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
42354241
ur_result_t UR_APICALL urEnqueueKernelLaunch(

test/conformance/enqueue/urEnqueueKernelLaunch.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,12 @@ TEST_P(urEnqueueKernelLaunchTest, InvalidWorkGroupSize) {
140140
}
141141

142142
TEST_P(urEnqueueKernelLaunchTest, InvalidKernelArgs) {
143-
// Cuda and hip both lack any way to validate kernel args
144-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
145-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
146-
147-
ur_platform_backend_t backend;
148-
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
149-
sizeof(ur_platform_backend_t), &backend,
150-
nullptr));
151-
152-
if (backend == UR_PLATFORM_BACKEND_CUDA ||
153-
backend == UR_PLATFORM_BACKEND_HIP ||
154-
backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
155-
GTEST_FAIL() << "AMD, L0 and Nvidia can't check kernel arguments.";
156-
}
157-
158143
// Enqueue kernel without setting any args
159-
ASSERT_EQ_RESULT(urEnqueueKernelLaunch(queue, kernel, n_dimensions,
160-
&global_offset, &global_size,
161-
nullptr, 0, nullptr, nullptr),
162-
UR_RESULT_ERROR_INVALID_KERNEL_ARGS);
144+
auto error =
145+
urEnqueueKernelLaunch(queue, kernel, n_dimensions, &global_offset,
146+
&global_size, nullptr, 0, nullptr, nullptr);
147+
ASSERT_TRUE(error == UR_RESULT_ERROR_INVALID_KERNEL_ARGS ||
148+
error == UR_RESULT_SUCCESS);
163149
}
164150

165151
TEST_P(urEnqueueKernelLaunchKernelWgSizeTest, Success) {

0 commit comments

Comments
 (0)