Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the adapter and platform enums into one generic backend enum. #2377

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions examples/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ std::vector<ur_adapter_handle_t>
get_supported_adapters(std::vector<ur_adapter_handle_t> &adapters) {
std::vector<ur_adapter_handle_t> supported_adapters;
for (auto adapter : adapters) {
ur_adapter_backend_t backend;
ur_backend_t backend;
ur_check(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(ur_adapter_backend_t), &backend,
nullptr));
sizeof(ur_backend_t), &backend, nullptr));

if (backend == UR_ADAPTER_BACKEND_LEVEL_ZERO) {
if (backend == UR_BACKEND_LEVEL_ZERO) {
supported_adapters.push_back(adapter);
}
}
Expand Down
53 changes: 19 additions & 34 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,21 @@ typedef struct ur_rect_region_t {

} ur_rect_region_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Defines known backends.
typedef enum ur_backend_t {
UR_BACKEND_UNKNOWN = 0, ///< The backend is not a recognized one
UR_BACKEND_LEVEL_ZERO = 1, ///< The backend is Level Zero
UR_BACKEND_OPENCL = 2, ///< The backend is OpenCL
UR_BACKEND_CUDA = 3, ///< The backend is CUDA
UR_BACKEND_HIP = 4, ///< The backend is HIP
UR_BACKEND_NATIVE_CPU = 5, ///< The backend is Native CPU
/// @cond
UR_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -961,8 +976,8 @@ urAdapterGetLastError(
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported adapter info
typedef enum ur_adapter_info_t {
UR_ADAPTER_INFO_BACKEND = 0, ///< [::ur_adapter_backend_t] Identifies the native backend supported by
///< the adapter.
UR_ADAPTER_INFO_BACKEND = 0, ///< [::ur_backend_t] Identifies the native backend supported by the
///< adapter.
UR_ADAPTER_INFO_REFERENCE_COUNT = 1, ///< [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
Expand Down Expand Up @@ -1012,21 +1027,6 @@ urAdapterGetInfo(
size_t *pPropSizeRet ///< [out][optional] pointer to the actual number of bytes being queried by pPropValue.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Identifies backend of the adapter
typedef enum ur_adapter_backend_t {
UR_ADAPTER_BACKEND_UNKNOWN = 0, ///< The backend is not a recognized one
UR_ADAPTER_BACKEND_LEVEL_ZERO = 1, ///< The backend is Level Zero
UR_ADAPTER_BACKEND_OPENCL = 2, ///< The backend is OpenCL
UR_ADAPTER_BACKEND_CUDA = 3, ///< The backend is CUDA
UR_ADAPTER_BACKEND_HIP = 4, ///< The backend is HIP
UR_ADAPTER_BACKEND_NATIVE_CPU = 5, ///< The backend is Native CPU
/// @cond
UR_ADAPTER_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_adapter_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -1085,8 +1085,8 @@ typedef enum ur_platform_info_t {
///< size of the info needs to be dynamically queried.
UR_PLATFORM_INFO_PROFILE = 5, ///< [char[]] The string denoting profile of the platform. The size of the
///< info needs to be dynamically queried.
UR_PLATFORM_INFO_BACKEND = 6, ///< [::ur_platform_backend_t] The backend of the platform. Identifies the
///< native backend adapter implementing this platform.
UR_PLATFORM_INFO_BACKEND = 6, ///< [::ur_backend_t] The backend of the platform. Identifies the native
///< backend adapter implementing this platform.
/// @cond
UR_PLATFORM_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -1281,21 +1281,6 @@ urPlatformGetBackendOption(
///< the frontend option.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Identifies native backend adapters
typedef enum ur_platform_backend_t {
UR_PLATFORM_BACKEND_UNKNOWN = 0, ///< The backend is not a recognized one
UR_PLATFORM_BACKEND_LEVEL_ZERO = 1, ///< The backend is Level Zero
UR_PLATFORM_BACKEND_OPENCL = 2, ///< The backend is OpenCL
UR_PLATFORM_BACKEND_CUDA = 3, ///< The backend is CUDA
UR_PLATFORM_BACKEND_HIP = 4, ///< The backend is HIP
UR_PLATFORM_BACKEND_NATIVE_CPU = 5, ///< The backend is Native CPU
/// @cond
UR_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_platform_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down
24 changes: 8 additions & 16 deletions include/ur_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintRectOffset(const struct ur_rect_offse
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintRectRegion(const struct ur_rect_region_t params, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_backend_t enum
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintBackend(enum ur_backend_t value, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_device_init_flag_t enum
/// @returns
Expand Down Expand Up @@ -106,14 +114,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintCodeLocation(const struct ur_code_loc
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintAdapterInfo(enum ur_adapter_info_t value, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_adapter_backend_t enum
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintAdapterBackend(enum ur_adapter_backend_t value, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_platform_info_t enum
/// @returns
Expand All @@ -138,14 +138,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintApiVersion(enum ur_api_version_t valu
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintPlatformNativeProperties(const struct ur_platform_native_properties_t params, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_platform_backend_t enum
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// - `buff_size < out_size`
UR_APIEXPORT ur_result_t UR_APICALL urPrintPlatformBackend(enum ur_platform_backend_t value, char *buffer, const size_t buff_size, size_t *out_size);

///////////////////////////////////////////////////////////////////////////////
/// @brief Print ur_device_binary_t struct
/// @returns
Expand Down
105 changes: 37 additions & 68 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,14 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_base_desc_t params);
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_rect_offset_t params);
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_rect_region_t params);
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_device_init_flag_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_loader_config_info_t value);
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_code_location_t params);
inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_backend_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_api_version_t value);
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_platform_native_properties_t params);
inline std::ostream &operator<<(std::ostream &os, enum ur_platform_backend_t value);
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_device_binary_t params);
inline std::ostream &operator<<(std::ostream &os, enum ur_device_type_t value);
inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value);
Expand Down Expand Up @@ -1726,6 +1725,36 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_rect_region_t
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_backend_t type
/// @returns
/// std::ostream &
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value) {
switch (value) {
case UR_BACKEND_UNKNOWN:
os << "UR_BACKEND_UNKNOWN";
break;
case UR_BACKEND_LEVEL_ZERO:
os << "UR_BACKEND_LEVEL_ZERO";
break;
case UR_BACKEND_OPENCL:
os << "UR_BACKEND_OPENCL";
break;
case UR_BACKEND_CUDA:
os << "UR_BACKEND_CUDA";
break;
case UR_BACKEND_HIP:
os << "UR_BACKEND_HIP";
break;
case UR_BACKEND_NATIVE_CPU:
os << "UR_BACKEND_NATIVE_CPU";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_device_init_flag_t type
/// @returns
/// std::ostream &
Expand Down Expand Up @@ -1935,9 +1964,9 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_adapter_inf

switch (value) {
case UR_ADAPTER_INFO_BACKEND: {
const ur_adapter_backend_t *tptr = (const ur_adapter_backend_t *)ptr;
if (sizeof(ur_adapter_backend_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_adapter_backend_t) << ")";
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
if (sizeof(ur_backend_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_backend_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";
Expand Down Expand Up @@ -1966,36 +1995,6 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_adapter_inf
}
} // namespace ur::details

///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_adapter_backend_t type
/// @returns
/// std::ostream &
inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_backend_t value) {
switch (value) {
case UR_ADAPTER_BACKEND_UNKNOWN:
os << "UR_ADAPTER_BACKEND_UNKNOWN";
break;
case UR_ADAPTER_BACKEND_LEVEL_ZERO:
os << "UR_ADAPTER_BACKEND_LEVEL_ZERO";
break;
case UR_ADAPTER_BACKEND_OPENCL:
os << "UR_ADAPTER_BACKEND_OPENCL";
break;
case UR_ADAPTER_BACKEND_CUDA:
os << "UR_ADAPTER_BACKEND_CUDA";
break;
case UR_ADAPTER_BACKEND_HIP:
os << "UR_ADAPTER_BACKEND_HIP";
break;
case UR_ADAPTER_BACKEND_NATIVE_CPU:
os << "UR_ADAPTER_BACKEND_NATIVE_CPU";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_platform_info_t type
/// @returns
Expand Down Expand Up @@ -2062,9 +2061,9 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_platform_in
printPtr(os, tptr);
} break;
case UR_PLATFORM_INFO_BACKEND: {
const ur_platform_backend_t *tptr = (const ur_platform_backend_t *)ptr;
if (sizeof(ur_platform_backend_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_platform_backend_t) << ")";
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
if (sizeof(ur_backend_t) > size) {
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_backend_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";
Expand Down Expand Up @@ -2115,36 +2114,6 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_platform_nativ
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_platform_backend_t type
/// @returns
/// std::ostream &
inline std::ostream &operator<<(std::ostream &os, enum ur_platform_backend_t value) {
switch (value) {
case UR_PLATFORM_BACKEND_UNKNOWN:
os << "UR_PLATFORM_BACKEND_UNKNOWN";
break;
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
os << "UR_PLATFORM_BACKEND_LEVEL_ZERO";
break;
case UR_PLATFORM_BACKEND_OPENCL:
os << "UR_PLATFORM_BACKEND_OPENCL";
break;
case UR_PLATFORM_BACKEND_CUDA:
os << "UR_PLATFORM_BACKEND_CUDA";
break;
case UR_PLATFORM_BACKEND_HIP:
os << "UR_PLATFORM_BACKEND_HIP";
break;
case UR_PLATFORM_BACKEND_NATIVE_CPU:
os << "UR_PLATFORM_BACKEND_NATIVE_CPU";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ur_device_binary_t type
/// @returns
/// std::ostream &
Expand Down
26 changes: 1 addition & 25 deletions scripts/core/adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ name: $x_adapter_info_t
typed_etors: True
etors:
- name: BACKEND
desc: "[$x_adapter_backend_t] Identifies the native backend supported by the adapter."
desc: "[$x_backend_t] Identifies the native backend supported by the adapter."
- name: REFERENCE_COUNT
desc: |
[uint32_t] Reference count of the adapter.
Expand Down Expand Up @@ -177,27 +177,3 @@ returns:
- "`pPropValue == NULL && pPropSizeRet == NULL`"
- $X_RESULT_ERROR_OUT_OF_RESOURCES
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
--- #--------------------------------------------------------------------------
type: enum
desc: "Identifies backend of the adapter"
class: $x
name: $x_adapter_backend_t
etors:
- name: UNKNOWN
value: "0"
desc: "The backend is not a recognized one"
- name: LEVEL_ZERO
value: "1"
desc: "The backend is Level Zero"
- name: OPENCL
value: "2"
desc: "The backend is OpenCL"
- name: CUDA
value: "3"
desc: "The backend is CUDA"
- name: HIP
value: "4"
desc: "The backend is HIP"
- name: NATIVE_CPU
value: "5"
desc: "The backend is Native CPU"
23 changes: 23 additions & 0 deletions scripts/core/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,26 @@ members:
- type: uint64_t
name: depth
desc: "[in] scalar (scalar)"
--- #--------------------------------------------------------------------------
type: enum
desc: "Defines known backends."
name: $x_backend_t
etors:
- name: UNKNOWN
value: "0"
desc: "The backend is not a recognized one"
- name: LEVEL_ZERO
value: "1"
desc: "The backend is Level Zero"
- name: OPENCL
value: "2"
desc: "The backend is OpenCL"
- name: CUDA
value: "3"
desc: "The backend is CUDA"
- name: HIP
value: "4"
desc: "The backend is HIP"
- name: NATIVE_CPU
value: "5"
desc: "The backend is Native CPU"
Loading
Loading