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] Add validation check to urDeviceGet #860

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
2 changes: 2 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ typedef enum ur_device_type_t {
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phDevices != NULL`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NumEntries > 0 && phDevices == NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
UR_APIEXPORT ur_result_t UR_APICALL
urDeviceGet(
Expand Down
2 changes: 2 additions & 0 deletions scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ params:
returns:
- $X_RESULT_ERROR_INVALID_SIZE:
- "`NumEntries == 0 && phDevices != NULL`"
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
- "`NumEntries > 0 && phDevices == NULL`"
- $X_RESULT_ERROR_INVALID_VALUE
--- #--------------------------------------------------------------------------
type: enum
Expand Down
4 changes: 4 additions & 0 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (NumEntries > 0 && phDevices == NULL) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (UR_DEVICE_TYPE_VPU < DeviceType) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
Expand Down
2 changes: 2 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ ur_result_t UR_APICALL urPlatformGetBackendOption(
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phDevices != NULL`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NumEntries > 0 && phDevices == NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
ur_result_t UR_APICALL urDeviceGet(
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance
Expand Down
2 changes: 2 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ ur_result_t UR_APICALL urPlatformGetBackendOption(
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phDevices != NULL`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NumEntries > 0 && phDevices == NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
ur_result_t UR_APICALL urDeviceGet(
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance
Expand Down
12 changes: 11 additions & 1 deletion test/conformance/device/urDeviceGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_F(urDeviceGetTest, InvalidEnumerationDevicesType) {
urDeviceGet(platform, UR_DEVICE_TYPE_FORCE_UINT32, 0, nullptr, &count));
}

TEST_F(urDeviceGetTest, InvalidValueNumEntries) {
TEST_F(urDeviceGetTest, InvalidSizeNumEntries) {
uint32_t count = 0;
ASSERT_SUCCESS(
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &count));
Expand All @@ -59,3 +59,13 @@ TEST_F(urDeviceGetTest, InvalidValueNumEntries) {
UR_RESULT_ERROR_INVALID_SIZE,
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, devices.data(), nullptr));
}

TEST_F(urDeviceGetTest, InvalidNullPointerDevices) {
uint32_t count = 0;
ASSERT_SUCCESS(
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &count));
ASSERT_NE(count, 0);
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, count, nullptr, nullptr));
}