Skip to content

Commit 6e8d61c

Browse files
committed
[UR] Add UR_DEVICE_INFO_VALIDATES_ON_LAUNCH
This device info is used to specify whether a given device can validate arguments passed to a kernel when it is launched. This also updates the spec to specify that if this value is not set, then running a kernel with invalid arguments is UB. This does not imply any behavior changes in adapters themselves; they already UB-ed anyway. This just writes it into the spec and makes some conformance tests not fail them for it.
1 parent 4751c96 commit 6e8d61c

File tree

14 files changed

+87
-20
lines changed

14 files changed

+87
-20
lines changed

unified-runtime/include/ur_api.h

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/include/ur_print.hpp

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/scripts/core/device.yml

+2
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ etors:
462462
desc: "[int32_t][optional-query] return max power limit in milliwatts."
463463
- name: BFLOAT16_CONVERSIONS_NATIVE
464464
desc: "[$x_bool_t] support for native bfloat16 conversions"
465+
- name: VALIDATES_ON_LAUNCH
466+
desc: "[$x_bool_t] $xEnqueueKernelLaunch may return $X_RESULT_ERROR_INVALID_KERNEL_ARGS"
465467
--- #--------------------------------------------------------------------------
466468
type: function
467469
desc: "Retrieves various information about device"

unified-runtime/scripts/core/enqueue.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type: function
1616
desc: "Enqueue a command to execute a kernel"
1717
class: $xEnqueue
1818
name: KernelLaunch
19+
details:
20+
- "Adapters must perform validation on provided kernel arguments when launching them if they report
21+
`$X_DEVICE_INFO_VALIDATES_ON_LAUNCH` as true for the appropriate device. If this is reported as false, then
22+
launching a kernel with invalid arguments is Undefined Behavior."
1923
ordinal: "0"
2024
analogue:
2125
- "**clEnqueueNDRangeKernel**"
@@ -65,8 +69,8 @@ returns:
6569
- $X_RESULT_ERROR_INVALID_WORK_DIMENSION
6670
- $X_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
6771
- $X_RESULT_ERROR_INVALID_VALUE
68-
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS
69-
- "The kernel argument values have not been specified."
72+
- $X_RESULT_ERROR_INVALID_KERNEL_ARGS:
73+
- "The kernel argument values are not valid and `$X_DEVICE_INFO_VALIDATE_ON_LAUNCH` is true for the device"
7074
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
7175
- $X_RESULT_ERROR_OUT_OF_RESOURCES
7276
--- #--------------------------------------------------------------------------

unified-runtime/source/adapters/cuda/device.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11881188
return ReturnValue(false);
11891189
case UR_DEVICE_INFO_ASYNC_USM_ALLOCATIONS_SUPPORT_EXP:
11901190
return ReturnValue(true);
1191+
case UR_DEVICE_INFO_VALIDATES_ON_LAUNCH:
1192+
return ReturnValue(false);
11911193
default:
11921194
break;
11931195
}

unified-runtime/source/adapters/hip/device.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10951095
return ReturnValue(true);
10961096
case UR_DEVICE_INFO_MULTI_DEVICE_COMPILE_SUPPORT_EXP:
10971097
return ReturnValue(false);
1098+
case UR_DEVICE_INFO_VALIDATES_ON_LAUNCH:
1099+
return ReturnValue(false);
10981100
default:
10991101
break;
11001102
}

unified-runtime/source/adapters/level_zero/device.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,8 @@ ur_result_t urDeviceGetInfo(
13351335
return ReturnValue(int32_t{PowerProperties.maxLimit});
13361336
}
13371337
}
1338+
case UR_DEVICE_INFO_VALIDATES_ON_LAUNCH:
1339+
return ReturnValue(false);
13381340
default:
13391341
logger::error("Unsupported ParamName in urGetDeviceInfo");
13401342
logger::error("ParamNameParamName={}(0x{})", ParamName,

unified-runtime/source/adapters/native_cpu/device.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
456456
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
457457
return ReturnValue(false);
458458

459+
case UR_DEVICE_INFO_VALIDATES_ON_LAUNCH:
460+
return ReturnValue(false);
461+
459462
default:
460463
DIE_NO_IMPLEMENTATION;
461464
}

unified-runtime/source/adapters/opencl/device.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
14271427
return ReturnValue(true);
14281428
case UR_DEVICE_INFO_MULTI_DEVICE_COMPILE_SUPPORT_EXP:
14291429
return ReturnValue(false);
1430+
case UR_DEVICE_INFO_VALIDATES_ON_LAUNCH:
1431+
return ReturnValue(true);
14301432
// TODO: We can't query to check if these are supported, they will need to be
14311433
// manually updated if support is ever implemented.
14321434
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:

unified-runtime/source/loader/ur_libapi.cpp

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/source/ur_api.cpp

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/test/conformance/device/urDeviceGetInfo.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,20 @@ TEST_P(urDeviceGetInfoTest, SuccessMinPowerLimit) {
26622662
property_value);
26632663
}
26642664

2665+
TEST_P(urDeviceGetInfoTest, SuccessValidatesOnLaunch) {
2666+
size_t property_size = 0;
2667+
const ur_device_info_t property_name = UR_DEVICE_INFO_VALIDATES_ON_LAUNCH;
2668+
2669+
ASSERT_SUCCESS(
2670+
urDeviceGetInfo(device, property_name, 0, nullptr, &property_size));
2671+
2672+
ASSERT_EQ(property_size, sizeof(ur_bool_t));
2673+
2674+
ur_bool_t property_value = 0;
2675+
ASSERT_SUCCESS(urDeviceGetInfo(device, property_name, property_size,
2676+
&property_value, nullptr));
2677+
}
2678+
26652679
TEST_P(urDeviceGetInfoTest, InvalidNullHandleDevice) {
26662680
ur_device_type_t device_type;
26672681
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,

unified-runtime/test/conformance/enqueue/urEnqueueKernelLaunch.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,13 @@ TEST_P(urEnqueueKernelLaunchTest, InvalidWorkGroupSize) {
154154
}
155155

156156
TEST_P(urEnqueueKernelLaunchTest, InvalidKernelArgs) {
157-
// Cuda and hip both lack any way to validate kernel args
158-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{});
159-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
160-
161-
ur_platform_backend_t backend;
162-
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
163-
sizeof(ur_platform_backend_t), &backend,
164-
nullptr));
157+
ur_bool_t validates;
158+
ASSERT_SUCCESS(urDeviceGetInfo(device, UR_DEVICE_INFO_VALIDATES_ON_LAUNCH,
159+
sizeof(validates), &validates, nullptr));
165160

166-
if (backend == UR_PLATFORM_BACKEND_CUDA ||
167-
backend == UR_PLATFORM_BACKEND_HIP ||
168-
backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
169-
GTEST_FAIL() << "AMD, L0 and Nvidia can't check kernel arguments.";
161+
if (!validates) {
162+
GTEST_SKIP() << "Adapter can't check kernel arguments.";
163+
return;
170164
}
171165

172166
// Enqueue kernel without setting any args

unified-runtime/tools/urinfo/urinfo.hpp

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)