Skip to content

Commit c6206db

Browse files
authored
Merge pull request #2404 from kbenzie/benie/adapter-version-query
Add UR_ADAPTER_INFO_VERSION query
2 parents 2bea25d + 3ff0730 commit c6206db

File tree

13 files changed

+48
-5
lines changed

13 files changed

+48
-5
lines changed

include/ur_api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ 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, initial value of 1 and
971+
///< incremented unpon major changes, e.g. when multiple versions of an
972+
///< adapter may exist in parallel.
970973
/// @cond
971974
UR_ADAPTER_INFO_FORCE_UINT32 = 0x7fffffff
972975
/// @endcond
@@ -988,7 +991,7 @@ typedef enum ur_adapter_info_t {
988991
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
989992
/// + `NULL == hAdapter`
990993
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
991-
/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName`
994+
/// + `::UR_ADAPTER_INFO_VERSION < propName`
992995
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
993996
/// + If `propName` is not supported by the adapter.
994997
/// - ::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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ 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: >
141+
[uint32_t] Specifies the adapter version, initial value of 1 and
142+
incremented unpon major changes, e.g. when multiple versions of an
143+
adapter may exist in parallel.
139144
--- #--------------------------------------------------------------------------
140145
type: function
141146
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
@@ -108,6 +108,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
108108
return ReturnValue(UR_ADAPTER_BACKEND_CUDA);
109109
case UR_ADAPTER_INFO_REFERENCE_COUNT:
110110
return ReturnValue(adapter.RefCount.load());
111+
case UR_ADAPTER_INFO_VERSION:
112+
return ReturnValue(uint32_t{1});
111113
default:
112114
return UR_RESULT_ERROR_INVALID_ENUMERATION;
113115
}

source/adapters/hip/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
9696
return ReturnValue(UR_ADAPTER_BACKEND_HIP);
9797
case UR_ADAPTER_INFO_REFERENCE_COUNT:
9898
return ReturnValue(adapter.RefCount.load());
99+
case UR_ADAPTER_INFO_VERSION:
100+
return ReturnValue(uint32_t{1});
99101
default:
100102
return UR_RESULT_ERROR_INVALID_ENUMERATION;
101103
}

source/adapters/level_zero/adapter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ ur_result_t urAdapterGetInfo(ur_adapter_handle_t, ur_adapter_info_t PropName,
655655
return ReturnValue(UR_ADAPTER_BACKEND_LEVEL_ZERO);
656656
case UR_ADAPTER_INFO_REFERENCE_COUNT:
657657
return ReturnValue(GlobalAdapter->RefCount.load());
658+
case UR_ADAPTER_INFO_VERSION: {
659+
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
660+
uint32_t adapterVersion = 2;
661+
#else
662+
uint32_t adapterVersion = 1;
663+
#endif
664+
return ReturnValue(adapterVersion);
665+
}
658666
default:
659667
return UR_RESULT_ERROR_INVALID_ENUMERATION;
660668
}

source/adapters/native_cpu/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
5757
return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU);
5858
case UR_ADAPTER_INFO_REFERENCE_COUNT:
5959
return ReturnValue(Adapter.RefCount.load());
60+
case UR_ADAPTER_INFO_VERSION:
61+
return ReturnValue(uint32_t{1});
6062
default:
6163
return UR_RESULT_ERROR_INVALID_ENUMERATION;
6264
}

source/adapters/opencl/adapter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
128128
return ReturnValue(UR_ADAPTER_BACKEND_OPENCL);
129129
case UR_ADAPTER_INFO_REFERENCE_COUNT:
130130
return ReturnValue(adapter->RefCount.load());
131+
case UR_ADAPTER_INFO_VERSION:
132+
return ReturnValue(uint32_t{1});
131133
default:
132134
return UR_RESULT_ERROR_INVALID_ENUMERATION;
133135
}

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)