Skip to content

Commit

Permalink
Merge the adapter and platform enums into one generic backend enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongreig committed Jan 21, 2025
1 parent f058cb2 commit f9b9aff
Show file tree
Hide file tree
Showing 47 changed files with 249 additions and 365 deletions.
6 changes: 3 additions & 3 deletions examples/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,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
71 changes: 25 additions & 46 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,27 @@ typedef struct ur_rect_region_t {

} ur_rect_region_t;

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

} ur_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -1317,8 +1338,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported adapter info
typedef enum ur_adapter_info_t {
/// [::ur_adapter_backend_t] Identifies the native backend supported by
/// the adapter.
/// [::ur_backend_t] Identifies the native backend supported by the
/// adapter.
UR_ADAPTER_INFO_BACKEND = 0,
/// [uint32_t] Reference count of the adapter.
/// The reference count returned should be considered immediately stale.
Expand Down Expand Up @@ -1379,27 +1400,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(
/// pPropValue.
size_t *pPropSizeRet);

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

} ur_adapter_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -1466,8 +1466,8 @@ typedef enum ur_platform_info_t {
/// [char[]] The string denoting profile of the platform. The size of the
/// info needs to be dynamically queried.
UR_PLATFORM_INFO_PROFILE = 5,
/// [::ur_platform_backend_t] The backend of the platform. Identifies the
/// native backend adapter implementing this platform.
/// [::ur_backend_t] The backend of the platform. Identifies the native
/// backend adapter implementing this platform.
UR_PLATFORM_INFO_BACKEND = 6,
/// [::ur_adapter_handle_t] The adapter handle associated with the
/// platform.
Expand Down Expand Up @@ -1686,27 +1686,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
/// the frontend option.
const char **ppPlatformOption);

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

} ur_platform_backend_t;

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down
31 changes: 11 additions & 20 deletions include/ur_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ 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 @@ -132,16 +143,6 @@ 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 Down Expand Up @@ -172,16 +173,6 @@ 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
109 changes: 37 additions & 72 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ operator<<(std::ostream &os,
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,
Expand All @@ -307,16 +308,12 @@ 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);
Expand Down Expand Up @@ -2029,6 +2026,36 @@ inline std::ostream &operator<<(std::ostream &os,
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 @@ -2247,10 +2274,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,

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) {
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
if (sizeof(ur_backend_t) > size) {
os << "invalid size (is: " << size
<< ", expected: >=" << sizeof(ur_adapter_backend_t) << ")";
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";
Expand Down Expand Up @@ -2293,37 +2320,6 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
}
} // 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 @@ -2395,10 +2391,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
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) {
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
if (sizeof(ur_backend_t) > size) {
os << "invalid size (is: " << size
<< ", expected: >=" << sizeof(ur_platform_backend_t) << ")";
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
return UR_RESULT_ERROR_INVALID_SIZE;
}
os << (const void *)(tptr) << " (";
Expand Down Expand Up @@ -2463,37 +2459,6 @@ operator<<(std::ostream &os,
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 @@ -182,27 +182,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"
Loading

0 comments on commit f9b9aff

Please sign in to comment.