Skip to content

Commit b237c12

Browse files
committed
Fix return of component and composite device info queries
The UR_DEVICE_INFO_COMPONENT_DEVICES and UR_DEVICE_INFO_COMPOSITE_DEVICE device info queries currently have confusing return values for all backends. For backends that do not support these queries, they return 0, despite both queries being expected to return 1 or more devices, which may have a larger type than the integral 0. To address this, these backends now return UR_RESULT_ERROR_UNSUPPORTED_FEATURE to signal that the device info queries are not supported by the given backend. For the L0 backend that supports this, the case where the component devices query has no devices, it also returns a 0 literal. Instead, this commit changes it to report a 0-sized return value and will not write to the return value if asked. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 905804c commit b237c12

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

source/adapters/cuda/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10771077
case UR_DEVICE_INFO_COMPONENT_DEVICES:
10781078
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
10791079
// These two are exclusive of L0.
1080-
return ReturnValue(0);
1080+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
10811081
case UR_DEVICE_INFO_MAX_READ_WRITE_IMAGE_ARGS:
10821082
case UR_DEVICE_INFO_GPU_EU_COUNT:
10831083
case UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH:

source/adapters/hip/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
849849
case UR_DEVICE_INFO_COMPONENT_DEVICES:
850850
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
851851
// These two are exclusive of L0.
852-
return ReturnValue(0);
852+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
853853
case UR_DEVICE_INFO_TIMESTAMP_RECORDING_SUPPORT_EXP:
854854
return ReturnValue(true);
855855

source/adapters/level_zero/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
891891
// First call to get SubDeviceCount.
892892
ZE2UR_CALL(zeDeviceGetSubDevices, (DevHandle, &SubDeviceCount, nullptr));
893893
if (SubDeviceCount == 0)
894-
return ReturnValue(0);
894+
return ReturnValue(std::nullopt);
895895

896896
std::vector<ze_device_handle_t> SubDevs(SubDeviceCount);
897897
// Second call to get the actual list of devices.

source/adapters/native_cpu/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
312312
case UR_DEVICE_INFO_COMPONENT_DEVICES:
313313
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
314314
// These two are exclusive of L0.
315-
return ReturnValue(0);
315+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
316316

317317
CASE_UR_UNSUPPORTED(UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH);
318318
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT:

source/adapters/opencl/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
966966
case UR_DEVICE_INFO_COMPONENT_DEVICES:
967967
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
968968
// These two are exclusive of L0.
969-
return ReturnValue(0);
969+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
970970
/* TODO: Check regularly to see if support is enabled in OpenCL. Intel GPU
971971
* EU device-specific information extensions. Some of the queries are
972972
* enabled by cl_intel_device_attribute_query extension, but it's not yet in

source/ur/ur.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <functional>
1717
#include <iostream>
1818
#include <mutex>
19+
#include <optional>
1920
#include <shared_mutex>
2021
#include <string>
2122
#include <thread>
@@ -263,6 +264,12 @@ getInfo<const char *>(size_t param_value_size, void *param_value,
263264
return getInfoArray(strlen(value) + 1, param_value_size, param_value,
264265
param_value_size_ret, value);
265266
}
267+
268+
ur_result_t getInfoEmpty(size_t param_value_size, void *param_value,
269+
size_t *param_value_size_ret) {
270+
return getInfoImpl(param_value_size, param_value, param_value_size_ret, 0,
271+
0, [](void *, int, size_t) {});
272+
}
266273
} // namespace ur
267274

268275
class UrReturnHelper {
@@ -296,6 +303,12 @@ class UrReturnHelper {
296303
param_value_size_ret, t);
297304
}
298305

306+
// Special case when there is no return value
307+
ur_result_t operator()(std::nullopt_t) {
308+
return ur::getInfoEmpty(param_value_size, param_value,
309+
param_value_size_ret);
310+
}
311+
299312
protected:
300313
size_t param_value_size;
301314
void *param_value;

0 commit comments

Comments
 (0)