Skip to content

Commit 9f11e28

Browse files
committed
Merge the adapter and platform enums into one generic backend enum.
1 parent f058cb2 commit 9f11e28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+249
-366
lines changed

examples/codegen/codegen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ std::vector<ur_adapter_handle_t>
4949
get_supported_adapters(std::vector<ur_adapter_handle_t> &adapters) {
5050
std::vector<ur_adapter_handle_t> supported_adapters;
5151
for (auto adapter : adapters) {
52-
ur_adapter_backend_t backend;
52+
ur_backend_t backend;
5353
ur_check(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
54-
sizeof(ur_adapter_backend_t), &backend, nullptr));
54+
sizeof(ur_backend_t), &backend, nullptr));
5555

56-
if (backend == UR_ADAPTER_BACKEND_LEVEL_ZERO) {
56+
if (backend == UR_BACKEND_LEVEL_ZERO) {
5757
supported_adapters.push_back(adapter);
5858
}
5959
}

include/ur_api.h

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,27 @@ typedef struct ur_rect_region_t {
904904

905905
} ur_rect_region_t;
906906

907+
///////////////////////////////////////////////////////////////////////////////
908+
/// @brief Defines known backends.
909+
typedef enum ur_backend_t {
910+
/// The backend is not a recognized one
911+
UR_BACKEND_UNKNOWN = 0,
912+
/// The backend is Level Zero
913+
UR_BACKEND_LEVEL_ZERO = 1,
914+
/// The backend is OpenCL
915+
UR_BACKEND_OPENCL = 2,
916+
/// The backend is CUDA
917+
UR_BACKEND_CUDA = 3,
918+
/// The backend is HIP
919+
UR_BACKEND_HIP = 4,
920+
/// The backend is Native CPU
921+
UR_BACKEND_NATIVE_CPU = 5,
922+
/// @cond
923+
UR_BACKEND_FORCE_UINT32 = 0x7fffffff
924+
/// @endcond
925+
926+
} ur_backend_t;
927+
907928
#if !defined(__GNUC__)
908929
#pragma endregion
909930
#endif
@@ -1317,8 +1338,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
13171338
///////////////////////////////////////////////////////////////////////////////
13181339
/// @brief Supported adapter info
13191340
typedef enum ur_adapter_info_t {
1320-
/// [::ur_adapter_backend_t] Identifies the native backend supported by
1321-
/// the adapter.
1341+
/// [::ur_backend_t] Identifies the native backend supported by the
1342+
/// adapter.
13221343
UR_ADAPTER_INFO_BACKEND = 0,
13231344
/// [uint32_t] Reference count of the adapter.
13241345
/// The reference count returned should be considered immediately stale.
@@ -1379,27 +1400,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(
13791400
/// pPropValue.
13801401
size_t *pPropSizeRet);
13811402

1382-
///////////////////////////////////////////////////////////////////////////////
1383-
/// @brief Identifies backend of the adapter
1384-
typedef enum ur_adapter_backend_t {
1385-
/// The backend is not a recognized one
1386-
UR_ADAPTER_BACKEND_UNKNOWN = 0,
1387-
/// The backend is Level Zero
1388-
UR_ADAPTER_BACKEND_LEVEL_ZERO = 1,
1389-
/// The backend is OpenCL
1390-
UR_ADAPTER_BACKEND_OPENCL = 2,
1391-
/// The backend is CUDA
1392-
UR_ADAPTER_BACKEND_CUDA = 3,
1393-
/// The backend is HIP
1394-
UR_ADAPTER_BACKEND_HIP = 4,
1395-
/// The backend is Native CPU
1396-
UR_ADAPTER_BACKEND_NATIVE_CPU = 5,
1397-
/// @cond
1398-
UR_ADAPTER_BACKEND_FORCE_UINT32 = 0x7fffffff
1399-
/// @endcond
1400-
1401-
} ur_adapter_backend_t;
1402-
14031403
#if !defined(__GNUC__)
14041404
#pragma endregion
14051405
#endif
@@ -1466,8 +1466,8 @@ typedef enum ur_platform_info_t {
14661466
/// [char[]] The string denoting profile of the platform. The size of the
14671467
/// info needs to be dynamically queried.
14681468
UR_PLATFORM_INFO_PROFILE = 5,
1469-
/// [::ur_platform_backend_t] The backend of the platform. Identifies the
1470-
/// native backend adapter implementing this platform.
1469+
/// [::ur_backend_t] The backend of the platform. Identifies the native
1470+
/// backend adapter implementing this platform.
14711471
UR_PLATFORM_INFO_BACKEND = 6,
14721472
/// [::ur_adapter_handle_t] The adapter handle associated with the
14731473
/// platform.
@@ -1686,27 +1686,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
16861686
/// the frontend option.
16871687
const char **ppPlatformOption);
16881688

1689-
///////////////////////////////////////////////////////////////////////////////
1690-
/// @brief Identifies native backend adapters
1691-
typedef enum ur_platform_backend_t {
1692-
/// The backend is not a recognized one
1693-
UR_PLATFORM_BACKEND_UNKNOWN = 0,
1694-
/// The backend is Level Zero
1695-
UR_PLATFORM_BACKEND_LEVEL_ZERO = 1,
1696-
/// The backend is OpenCL
1697-
UR_PLATFORM_BACKEND_OPENCL = 2,
1698-
/// The backend is CUDA
1699-
UR_PLATFORM_BACKEND_CUDA = 3,
1700-
/// The backend is HIP
1701-
UR_PLATFORM_BACKEND_HIP = 4,
1702-
/// The backend is Native CPU
1703-
UR_PLATFORM_BACKEND_NATIVE_CPU = 5,
1704-
/// @cond
1705-
UR_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
1706-
/// @endcond
1707-
1708-
} ur_platform_backend_t;
1709-
17101689
#if !defined(__GNUC__)
17111690
#pragma endregion
17121691
#endif

include/ur_print.h

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ UR_APIEXPORT ur_result_t UR_APICALL
9292
urPrintRectRegion(const struct ur_rect_region_t params, char *buffer,
9393
const size_t buff_size, size_t *out_size);
9494

95+
///////////////////////////////////////////////////////////////////////////////
96+
/// @brief Print ur_backend_t enum
97+
/// @returns
98+
/// - ::UR_RESULT_SUCCESS
99+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
100+
/// - `buff_size < out_size`
101+
UR_APIEXPORT ur_result_t UR_APICALL urPrintBackend(enum ur_backend_t value,
102+
char *buffer,
103+
const size_t buff_size,
104+
size_t *out_size);
105+
95106
///////////////////////////////////////////////////////////////////////////////
96107
/// @brief Print ur_device_init_flag_t enum
97108
/// @returns
@@ -132,16 +143,6 @@ UR_APIEXPORT ur_result_t UR_APICALL
132143
urPrintAdapterInfo(enum ur_adapter_info_t value, char *buffer,
133144
const size_t buff_size, size_t *out_size);
134145

135-
///////////////////////////////////////////////////////////////////////////////
136-
/// @brief Print ur_adapter_backend_t enum
137-
/// @returns
138-
/// - ::UR_RESULT_SUCCESS
139-
/// - ::UR_RESULT_ERROR_INVALID_SIZE
140-
/// - `buff_size < out_size`
141-
UR_APIEXPORT ur_result_t UR_APICALL
142-
urPrintAdapterBackend(enum ur_adapter_backend_t value, char *buffer,
143-
const size_t buff_size, size_t *out_size);
144-
145146
///////////////////////////////////////////////////////////////////////////////
146147
/// @brief Print ur_platform_info_t enum
147148
/// @returns
@@ -172,16 +173,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintPlatformNativeProperties(
172173
const struct ur_platform_native_properties_t params, char *buffer,
173174
const size_t buff_size, size_t *out_size);
174175

175-
///////////////////////////////////////////////////////////////////////////////
176-
/// @brief Print ur_platform_backend_t enum
177-
/// @returns
178-
/// - ::UR_RESULT_SUCCESS
179-
/// - ::UR_RESULT_ERROR_INVALID_SIZE
180-
/// - `buff_size < out_size`
181-
UR_APIEXPORT ur_result_t UR_APICALL
182-
urPrintPlatformBackend(enum ur_platform_backend_t value, char *buffer,
183-
const size_t buff_size, size_t *out_size);
184-
185176
///////////////////////////////////////////////////////////////////////////////
186177
/// @brief Print ur_device_binary_t struct
187178
/// @returns

include/ur_print.hpp

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ operator<<(std::ostream &os,
299299
inline std::ostream &
300300
operator<<(std::ostream &os,
301301
[[maybe_unused]] const struct ur_rect_region_t params);
302+
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value);
302303
inline std::ostream &operator<<(std::ostream &os,
303304
enum ur_device_init_flag_t value);
304305
inline std::ostream &operator<<(std::ostream &os,
@@ -307,16 +308,12 @@ inline std::ostream &
307308
operator<<(std::ostream &os,
308309
[[maybe_unused]] const struct ur_code_location_t params);
309310
inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value);
310-
inline std::ostream &operator<<(std::ostream &os,
311-
enum ur_adapter_backend_t value);
312311
inline std::ostream &operator<<(std::ostream &os,
313312
enum ur_platform_info_t value);
314313
inline std::ostream &operator<<(std::ostream &os, enum ur_api_version_t value);
315314
inline std::ostream &operator<<(
316315
std::ostream &os,
317316
[[maybe_unused]] const struct ur_platform_native_properties_t params);
318-
inline std::ostream &operator<<(std::ostream &os,
319-
enum ur_platform_backend_t value);
320317
inline std::ostream &
321318
operator<<(std::ostream &os,
322319
[[maybe_unused]] const struct ur_device_binary_t params);
@@ -2029,6 +2026,36 @@ inline std::ostream &operator<<(std::ostream &os,
20292026
return os;
20302027
}
20312028
///////////////////////////////////////////////////////////////////////////////
2029+
/// @brief Print operator for the ur_backend_t type
2030+
/// @returns
2031+
/// std::ostream &
2032+
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value) {
2033+
switch (value) {
2034+
case UR_BACKEND_UNKNOWN:
2035+
os << "UR_BACKEND_UNKNOWN";
2036+
break;
2037+
case UR_BACKEND_LEVEL_ZERO:
2038+
os << "UR_BACKEND_LEVEL_ZERO";
2039+
break;
2040+
case UR_BACKEND_OPENCL:
2041+
os << "UR_BACKEND_OPENCL";
2042+
break;
2043+
case UR_BACKEND_CUDA:
2044+
os << "UR_BACKEND_CUDA";
2045+
break;
2046+
case UR_BACKEND_HIP:
2047+
os << "UR_BACKEND_HIP";
2048+
break;
2049+
case UR_BACKEND_NATIVE_CPU:
2050+
os << "UR_BACKEND_NATIVE_CPU";
2051+
break;
2052+
default:
2053+
os << "unknown enumerator";
2054+
break;
2055+
}
2056+
return os;
2057+
}
2058+
///////////////////////////////////////////////////////////////////////////////
20322059
/// @brief Print operator for the ur_device_init_flag_t type
20332060
/// @returns
20342061
/// std::ostream &
@@ -2247,10 +2274,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
22472274

22482275
switch (value) {
22492276
case UR_ADAPTER_INFO_BACKEND: {
2250-
const ur_adapter_backend_t *tptr = (const ur_adapter_backend_t *)ptr;
2251-
if (sizeof(ur_adapter_backend_t) > size) {
2277+
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
2278+
if (sizeof(ur_backend_t) > size) {
22522279
os << "invalid size (is: " << size
2253-
<< ", expected: >=" << sizeof(ur_adapter_backend_t) << ")";
2280+
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
22542281
return UR_RESULT_ERROR_INVALID_SIZE;
22552282
}
22562283
os << (const void *)(tptr) << " (";
@@ -2293,37 +2320,6 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
22932320
}
22942321
} // namespace ur::details
22952322

2296-
///////////////////////////////////////////////////////////////////////////////
2297-
/// @brief Print operator for the ur_adapter_backend_t type
2298-
/// @returns
2299-
/// std::ostream &
2300-
inline std::ostream &operator<<(std::ostream &os,
2301-
enum ur_adapter_backend_t value) {
2302-
switch (value) {
2303-
case UR_ADAPTER_BACKEND_UNKNOWN:
2304-
os << "UR_ADAPTER_BACKEND_UNKNOWN";
2305-
break;
2306-
case UR_ADAPTER_BACKEND_LEVEL_ZERO:
2307-
os << "UR_ADAPTER_BACKEND_LEVEL_ZERO";
2308-
break;
2309-
case UR_ADAPTER_BACKEND_OPENCL:
2310-
os << "UR_ADAPTER_BACKEND_OPENCL";
2311-
break;
2312-
case UR_ADAPTER_BACKEND_CUDA:
2313-
os << "UR_ADAPTER_BACKEND_CUDA";
2314-
break;
2315-
case UR_ADAPTER_BACKEND_HIP:
2316-
os << "UR_ADAPTER_BACKEND_HIP";
2317-
break;
2318-
case UR_ADAPTER_BACKEND_NATIVE_CPU:
2319-
os << "UR_ADAPTER_BACKEND_NATIVE_CPU";
2320-
break;
2321-
default:
2322-
os << "unknown enumerator";
2323-
break;
2324-
}
2325-
return os;
2326-
}
23272323
///////////////////////////////////////////////////////////////////////////////
23282324
/// @brief Print operator for the ur_platform_info_t type
23292325
/// @returns
@@ -2395,10 +2391,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
23952391
printPtr(os, tptr);
23962392
} break;
23972393
case UR_PLATFORM_INFO_BACKEND: {
2398-
const ur_platform_backend_t *tptr = (const ur_platform_backend_t *)ptr;
2399-
if (sizeof(ur_platform_backend_t) > size) {
2394+
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
2395+
if (sizeof(ur_backend_t) > size) {
24002396
os << "invalid size (is: " << size
2401-
<< ", expected: >=" << sizeof(ur_platform_backend_t) << ")";
2397+
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
24022398
return UR_RESULT_ERROR_INVALID_SIZE;
24032399
}
24042400
os << (const void *)(tptr) << " (";
@@ -2463,37 +2459,6 @@ operator<<(std::ostream &os,
24632459
return os;
24642460
}
24652461
///////////////////////////////////////////////////////////////////////////////
2466-
/// @brief Print operator for the ur_platform_backend_t type
2467-
/// @returns
2468-
/// std::ostream &
2469-
inline std::ostream &operator<<(std::ostream &os,
2470-
enum ur_platform_backend_t value) {
2471-
switch (value) {
2472-
case UR_PLATFORM_BACKEND_UNKNOWN:
2473-
os << "UR_PLATFORM_BACKEND_UNKNOWN";
2474-
break;
2475-
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
2476-
os << "UR_PLATFORM_BACKEND_LEVEL_ZERO";
2477-
break;
2478-
case UR_PLATFORM_BACKEND_OPENCL:
2479-
os << "UR_PLATFORM_BACKEND_OPENCL";
2480-
break;
2481-
case UR_PLATFORM_BACKEND_CUDA:
2482-
os << "UR_PLATFORM_BACKEND_CUDA";
2483-
break;
2484-
case UR_PLATFORM_BACKEND_HIP:
2485-
os << "UR_PLATFORM_BACKEND_HIP";
2486-
break;
2487-
case UR_PLATFORM_BACKEND_NATIVE_CPU:
2488-
os << "UR_PLATFORM_BACKEND_NATIVE_CPU";
2489-
break;
2490-
default:
2491-
os << "unknown enumerator";
2492-
break;
2493-
}
2494-
return os;
2495-
}
2496-
///////////////////////////////////////////////////////////////////////////////
24972462
/// @brief Print operator for the ur_device_binary_t type
24982463
/// @returns
24992464
/// std::ostream &

scripts/core/adapter.yml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ name: $x_adapter_info_t
130130
typed_etors: True
131131
etors:
132132
- name: BACKEND
133-
desc: "[$x_adapter_backend_t] Identifies the native backend supported by the adapter."
133+
desc: "[$x_backend_t] Identifies the native backend supported by the adapter."
134134
- name: REFERENCE_COUNT
135135
desc: |
136136
[uint32_t] Reference count of the adapter.
@@ -182,27 +182,3 @@ returns:
182182
- "`pPropValue == NULL && pPropSizeRet == NULL`"
183183
- $X_RESULT_ERROR_OUT_OF_RESOURCES
184184
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
185-
--- #--------------------------------------------------------------------------
186-
type: enum
187-
desc: "Identifies backend of the adapter"
188-
class: $x
189-
name: $x_adapter_backend_t
190-
etors:
191-
- name: UNKNOWN
192-
value: "0"
193-
desc: "The backend is not a recognized one"
194-
- name: LEVEL_ZERO
195-
value: "1"
196-
desc: "The backend is Level Zero"
197-
- name: OPENCL
198-
value: "2"
199-
desc: "The backend is OpenCL"
200-
- name: CUDA
201-
value: "3"
202-
desc: "The backend is CUDA"
203-
- name: HIP
204-
value: "4"
205-
desc: "The backend is HIP"
206-
- name: NATIVE_CPU
207-
value: "5"
208-
desc: "The backend is Native CPU"

0 commit comments

Comments
 (0)