Skip to content
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
6 changes: 4 additions & 2 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1301,14 +1301,16 @@ typedef enum ur_device_type_t {
/// + `NULL == hPlatform`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `NumEntries == 0 && phDevices != NULL`
/// - ::UR_RESULT_ERROR_INVALID_VALUE
UR_APIEXPORT ur_result_t UR_APICALL
urDeviceGet(
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
///< If NumEntries is less than the number of devices available, then
Expand Down
4 changes: 3 additions & 1 deletion scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ params:
name: NumEntries
desc: |
[in] the number of devices to be added to phDevices.
If phDevices in not NULL then NumEntries should be greater than zero, otherwise $X_RESULT_ERROR_INVALID_VALUE,
If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise $X_RESULT_ERROR_INVALID_SIZE
will be returned.
- type: "$x_device_handle_t*"
name: phDevices
Expand All @@ -144,6 +144,8 @@ params:
[out][optional] pointer to the number of devices.
pNumDevices will be updated with the total number of devices available.
returns:
- $X_RESULT_ERROR_INVALID_SIZE:
- "`NumEntries == 0 && phDevices != NULL`"
Copy link
Contributor

Choose a reason for hiding this comment

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

The description for NumEntries should be updated too since it says that it will return UR_RESULT_ERROR_INVALID_VALUE in this case

Copy link
Contributor Author

@fabiomestre fabiomestre Aug 30, 2023

Choose a reason for hiding this comment

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

Actually, I went with INVALID_SIZE because that's what the test was using. But on second thought, maybe INVALID_VALUE is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would align with the OpenCL error code. What do other entry points specify for this type of error case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is only 2 other entries that are equivalent. urAdaptersGet and urPlatformsGet. Both are using INVALID_SIZE. I guess I will keep the change to INVALID_SIZE for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consistency is best, yup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Having the same fault on HIP so 👍 from me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

- $X_RESULT_ERROR_INVALID_VALUE
--- #--------------------------------------------------------------------------
type: enum
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand Down
4 changes: 2 additions & 2 deletions source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand Down
8 changes: 6 additions & 2 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand All @@ -422,6 +422,10 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
if (UR_DEVICE_TYPE_VPU < DeviceType) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

if (NumEntries == 0 && phDevices != NULL) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
}

ur_result_t result =
Expand Down
4 changes: 2 additions & 2 deletions source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGet(
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand Down
6 changes: 4 additions & 2 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,16 @@ ur_result_t UR_APICALL urPlatformGetBackendOption(
/// + `NULL == hPlatform`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `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
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand Down
6 changes: 4 additions & 2 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,16 @@ ur_result_t UR_APICALL urPlatformGetBackendOption(
/// + `NULL == hPlatform`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `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
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t
NumEntries, ///< [in] the number of devices to be added to phDevices.
///< If phDevices in not NULL then NumEntries should be greater than zero,
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
///< If phDevices is not NULL, then NumEntries should be greater than zero.
///< Otherwise ::UR_RESULT_ERROR_INVALID_SIZE
///< will be returned.
ur_device_handle_t *
phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
Expand Down
12 changes: 12 additions & 0 deletions test/conformance/device/urDeviceGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ INSTANTIATE_TEST_SUITE_P(
return ss.str();
});

bool doesReturnArray(ur_device_info_t info_type) {
if (info_type == UR_DEVICE_INFO_SUPPORTED_PARTITIONS ||
info_type == UR_DEVICE_INFO_PARTITION_TYPE) {
return true;
}
return false;
}

TEST_P(urDeviceGetInfoTest, Success) {
ur_device_info_t info_type = GetParam();
for (auto device : devices) {
Expand All @@ -248,7 +256,11 @@ TEST_P(urDeviceGetInfoTest, Success) {
urDeviceGetInfo(device, info_type, 0, nullptr, &size);

if (result == UR_RESULT_SUCCESS) {
if (doesReturnArray(info_type) && size == 0) {
return;
}
ASSERT_NE(size, 0);

if (const auto expected_size = device_info_size_map.find(info_type);
expected_size != device_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
Expand Down