diff --git a/include/ur_api.h b/include/ur_api.h index eb8b07221c..9890291e36 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -967,6 +967,9 @@ typedef enum ur_adapter_info_t { ///< The reference count returned should be considered immediately stale. ///< It is unsuitable for general use in applications. This feature is ///< provided for identifying memory leaks. + UR_ADAPTER_INFO_VERSION = 2, ///< [uint32_t] Specifies the adapter version, initial value of 1 and + ///< incremented unpon major changes, e.g. when multiple versions of an + ///< adapter may exist in parallel. /// @cond UR_ADAPTER_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -988,7 +991,7 @@ typedef enum ur_adapter_info_t { /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hAdapter` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// + `::UR_ADAPTER_INFO_VERSION < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 8888a74f91..cdc8a36243 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -1922,6 +1922,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value) case UR_ADAPTER_INFO_REFERENCE_COUNT: os << "UR_ADAPTER_INFO_REFERENCE_COUNT"; break; + case UR_ADAPTER_INFO_VERSION: + os << "UR_ADAPTER_INFO_VERSION"; + break; default: os << "unknown enumerator"; break; @@ -1962,6 +1965,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_adapter_inf os << ")"; } break; + case UR_ADAPTER_INFO_VERSION: { + const uint32_t *tptr = (const uint32_t *)ptr; + if (sizeof(uint32_t) > size) { + os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")"; + return UR_RESULT_ERROR_INVALID_SIZE; + } + os << (const void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; default: os << "unknown enumerator"; return UR_RESULT_ERROR_INVALID_ENUMERATION; diff --git a/scripts/core/adapter.yml b/scripts/core/adapter.yml index a4eddd823c..4fc9a104ed 100644 --- a/scripts/core/adapter.yml +++ b/scripts/core/adapter.yml @@ -136,6 +136,11 @@ etors: [uint32_t] Reference count of the adapter. The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks. + - name: VERSION + desc: > + [uint32_t] Specifies the adapter version, initial value of 1 and + incremented unpon major changes, e.g. when multiple versions of an + adapter may exist in parallel. --- #-------------------------------------------------------------------------- type: function desc: "Retrieves information about the adapter" diff --git a/source/adapters/cuda/adapter.cpp b/source/adapters/cuda/adapter.cpp index c8949cd9a8..49bb964f8e 100644 --- a/source/adapters/cuda/adapter.cpp +++ b/source/adapters/cuda/adapter.cpp @@ -108,6 +108,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, return ReturnValue(UR_ADAPTER_BACKEND_CUDA); case UR_ADAPTER_INFO_REFERENCE_COUNT: return ReturnValue(adapter.RefCount.load()); + case UR_ADAPTER_INFO_VERSION: + return ReturnValue(uint32_t{1}); default: return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/adapters/hip/adapter.cpp b/source/adapters/hip/adapter.cpp index 99db21695f..1bfe498bf6 100644 --- a/source/adapters/hip/adapter.cpp +++ b/source/adapters/hip/adapter.cpp @@ -96,6 +96,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, return ReturnValue(UR_ADAPTER_BACKEND_HIP); case UR_ADAPTER_INFO_REFERENCE_COUNT: return ReturnValue(adapter.RefCount.load()); + case UR_ADAPTER_INFO_VERSION: + return ReturnValue(uint32_t{1}); default: return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/adapters/level_zero/adapter.cpp b/source/adapters/level_zero/adapter.cpp index f2ac67ddff..5d6583f3d4 100644 --- a/source/adapters/level_zero/adapter.cpp +++ b/source/adapters/level_zero/adapter.cpp @@ -655,6 +655,14 @@ ur_result_t urAdapterGetInfo(ur_adapter_handle_t, ur_adapter_info_t PropName, return ReturnValue(UR_ADAPTER_BACKEND_LEVEL_ZERO); case UR_ADAPTER_INFO_REFERENCE_COUNT: return ReturnValue(GlobalAdapter->RefCount.load()); + case UR_ADAPTER_INFO_VERSION: { +#ifdef UR_ADAPTER_LEVEL_ZERO_V2 + uint32_t adapterVersion = 2; +#else + uint32_t adapterVersion = 1; +#endif + return ReturnValue(adapterVersion); + } default: return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/adapters/native_cpu/adapter.cpp b/source/adapters/native_cpu/adapter.cpp index 2b5b95ccd0..727c3e3dba 100644 --- a/source/adapters/native_cpu/adapter.cpp +++ b/source/adapters/native_cpu/adapter.cpp @@ -57,6 +57,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU); case UR_ADAPTER_INFO_REFERENCE_COUNT: return ReturnValue(Adapter.RefCount.load()); + case UR_ADAPTER_INFO_VERSION: + return ReturnValue(uint32_t{1}); default: return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/adapters/opencl/adapter.cpp b/source/adapters/opencl/adapter.cpp index bf81f6bdaf..162bc59b6a 100644 --- a/source/adapters/opencl/adapter.cpp +++ b/source/adapters/opencl/adapter.cpp @@ -128,6 +128,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t, return ReturnValue(UR_ADAPTER_BACKEND_OPENCL); case UR_ADAPTER_INFO_REFERENCE_COUNT: return ReturnValue(adapter->RefCount.load()); + case UR_ADAPTER_INFO_VERSION: + return ReturnValue(uint32_t{1}); default: return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index b3969de10f..ebdb4b5384 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -182,7 +182,7 @@ __urdlllocal ur_result_t UR_APICALL urAdapterGetInfo( return UR_RESULT_ERROR_INVALID_NULL_POINTER; } - if (UR_ADAPTER_INFO_REFERENCE_COUNT < propName) { + if (UR_ADAPTER_INFO_VERSION < propName) { return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 3340363737..898f259e0b 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -451,7 +451,7 @@ ur_result_t UR_APICALL urAdapterGetLastError( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hAdapter` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// + `::UR_ADAPTER_INFO_VERSION < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 853d61472e..4a57f5467d 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -410,7 +410,7 @@ ur_result_t UR_APICALL urAdapterGetLastError( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hAdapter` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// + `::UR_ADAPTER_INFO_VERSION < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/test/conformance/adapter/urAdapterGetInfo.cpp b/test/conformance/adapter/urAdapterGetInfo.cpp index 4dff3ce4dc..63c3cbfca1 100644 --- a/test/conformance/adapter/urAdapterGetInfo.cpp +++ b/test/conformance/adapter/urAdapterGetInfo.cpp @@ -20,12 +20,14 @@ struct urAdapterGetInfoTest : uur::runtime::urAdapterTest, std::unordered_map adapter_info_size_map = { {UR_ADAPTER_INFO_BACKEND, sizeof(ur_adapter_backend_t)}, + {UR_ADAPTER_INFO_VERSION, sizeof(uint32_t)}, {UR_ADAPTER_INFO_REFERENCE_COUNT, sizeof(uint32_t)}, }; INSTANTIATE_TEST_SUITE_P( urAdapterGetInfo, urAdapterGetInfoTest, - ::testing::Values(UR_ADAPTER_INFO_BACKEND, UR_ADAPTER_INFO_REFERENCE_COUNT), + ::testing::Values(UR_ADAPTER_INFO_BACKEND, UR_ADAPTER_INFO_VERSION, + UR_ADAPTER_INFO_REFERENCE_COUNT), [](const ::testing::TestParamInfo &info) { std::stringstream ss; ss << info.param; diff --git a/tools/urinfo/urinfo.hpp b/tools/urinfo/urinfo.hpp index 37c7a80328..813ca34da1 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -28,6 +28,8 @@ inline void printAdapterInfos(ur_adapter_handle_t hAdapter, std::string_view prefix = " ") { std::cout << prefix; printAdapterInfo(hAdapter, UR_ADAPTER_INFO_BACKEND); + std::cout << prefix; + printAdapterInfo(hAdapter, UR_ADAPTER_INFO_VERSION); } inline void printPlatformInfos(ur_platform_handle_t hPlatform,