Skip to content

Commit ceffb34

Browse files
committed
Add UR_ADAPTER_INFO_VERSION query
In order to support in-code management of known failures we need a query to differentiate between the two versions of the Level Zero adapter. This patch adds the `UR_ADAPTER_INFO_VERSION` query which returns a `uint32_t` which is set to return `1` for all adapters except the Level Zero adapter when being compiled in V2 mode.
1 parent 7a4902d commit ceffb34

File tree

13 files changed

+43
-5
lines changed

13 files changed

+43
-5
lines changed

include/ur_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ typedef enum ur_adapter_info_t {
967967
///< The reference count returned should be considered immediately stale.
968968
///< It is unsuitable for general use in applications. This feature is
969969
///< provided for identifying memory leaks.
970+
UR_ADAPTER_INFO_VERSION = 2, ///< [uint32_t] Specifies the adapter version, defaults to 1.
970971
/// @cond
971972
UR_ADAPTER_INFO_FORCE_UINT32 = 0x7fffffff
972973
/// @endcond
@@ -988,7 +989,7 @@ typedef enum ur_adapter_info_t {
988989
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
989990
/// + `NULL == hAdapter`
990991
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
991-
/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName`
992+
/// + `::UR_ADAPTER_INFO_VERSION < propName`
992993
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
993994
/// + If `propName` is not supported by the adapter.
994995
/// - ::UR_RESULT_ERROR_INVALID_SIZE

include/ur_print.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value)
19221922
case UR_ADAPTER_INFO_REFERENCE_COUNT:
19231923
os << "UR_ADAPTER_INFO_REFERENCE_COUNT";
19241924
break;
1925+
case UR_ADAPTER_INFO_VERSION:
1926+
os << "UR_ADAPTER_INFO_VERSION";
1927+
break;
19251928
default:
19261929
os << "unknown enumerator";
19271930
break;
@@ -1962,6 +1965,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_adapter_inf
19621965

19631966
os << ")";
19641967
} break;
1968+
case UR_ADAPTER_INFO_VERSION: {
1969+
const uint32_t *tptr = (const uint32_t *)ptr;
1970+
if (sizeof(uint32_t) > size) {
1971+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
1972+
return UR_RESULT_ERROR_INVALID_SIZE;
1973+
}
1974+
os << (const void *)(tptr) << " (";
1975+
1976+
os << *tptr;
1977+
1978+
os << ")";
1979+
} break;
19651980
default:
19661981
os << "unknown enumerator";
19671982
return UR_RESULT_ERROR_INVALID_ENUMERATION;

scripts/core/adapter.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ etors:
136136
[uint32_t] Reference count of the adapter.
137137
The reference count returned should be considered immediately stale.
138138
It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
139+
- name: VERSION
140+
desc: "[uint32_t] Specifies the adapter version, defaults to 1."
139141
--- #--------------------------------------------------------------------------
140142
type: function
141143
desc: "Retrieves information about the adapter"

source/adapters/cuda/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
106106
switch (propName) {
107107
case UR_ADAPTER_INFO_BACKEND:
108108
return ReturnValue(UR_ADAPTER_BACKEND_CUDA);
109+
case UR_ADAPTER_INFO_VERSION:
110+
return ReturnValue(uint32_t{1});
109111
case UR_ADAPTER_INFO_REFERENCE_COUNT:
110112
return ReturnValue(adapter.RefCount.load());
111113
default:

source/adapters/hip/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
9494
switch (propName) {
9595
case UR_ADAPTER_INFO_BACKEND:
9696
return ReturnValue(UR_ADAPTER_BACKEND_HIP);
97+
case UR_ADAPTER_INFO_VERSION:
98+
return ReturnValue(uint32_t{1});
9799
case UR_ADAPTER_INFO_REFERENCE_COUNT:
98100
return ReturnValue(adapter.RefCount.load());
99101
default:

source/adapters/level_zero/adapter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,14 @@ ur_result_t urAdapterGetInfo(ur_adapter_handle_t, ur_adapter_info_t PropName,
653653
switch (PropName) {
654654
case UR_ADAPTER_INFO_BACKEND:
655655
return ReturnValue(UR_ADAPTER_BACKEND_LEVEL_ZERO);
656+
case UR_ADAPTER_INFO_VERSION: {
657+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
658+
uint32_t adapterVersion = 2;
659+
#else
660+
uint32_t adapterVersion = 1;
661+
#endif
662+
return ReturnValue(adapterVersion);
663+
}
656664
case UR_ADAPTER_INFO_REFERENCE_COUNT:
657665
return ReturnValue(GlobalAdapter->RefCount.load());
658666
default:

source/adapters/native_cpu/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
5555
switch (propName) {
5656
case UR_ADAPTER_INFO_BACKEND:
5757
return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU);
58+
case UR_ADAPTER_INFO_VERSION:
59+
return ReturnValue(uint32_t{1});
5860
case UR_ADAPTER_INFO_REFERENCE_COUNT:
5961
return ReturnValue(Adapter.RefCount.load());
6062
default:

source/adapters/opencl/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
126126
switch (propName) {
127127
case UR_ADAPTER_INFO_BACKEND:
128128
return ReturnValue(UR_ADAPTER_BACKEND_OPENCL);
129+
case UR_ADAPTER_INFO_VERSION:
130+
return ReturnValue(uint32_t{1});
129131
case UR_ADAPTER_INFO_REFERENCE_COUNT:
130132
return ReturnValue(adapter->RefCount.load());
131133
default:

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGetInfo(
182182
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
183183
}
184184

185-
if (UR_ADAPTER_INFO_REFERENCE_COUNT < propName) {
185+
if (UR_ADAPTER_INFO_VERSION < propName) {
186186
return UR_RESULT_ERROR_INVALID_ENUMERATION;
187187
}
188188

source/loader/ur_libapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ ur_result_t UR_APICALL urAdapterGetLastError(
451451
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
452452
/// + `NULL == hAdapter`
453453
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
454-
/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName`
454+
/// + `::UR_ADAPTER_INFO_VERSION < propName`
455455
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
456456
/// + If `propName` is not supported by the adapter.
457457
/// - ::UR_RESULT_ERROR_INVALID_SIZE

0 commit comments

Comments
 (0)