Skip to content

Commit aea1f8e

Browse files
committed
Merge the adapter and platform enums into one generic backend enum.
1 parent e7c9d84 commit aea1f8e

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

+256
-373
lines changed

unified-runtime/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
}

unified-runtime/include/ur_api.h

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

895895
} ur_rect_region_t;
896896

897+
///////////////////////////////////////////////////////////////////////////////
898+
/// @brief Defines known backends.
899+
typedef enum ur_backend_t {
900+
/// The backend is not a recognized one
901+
UR_BACKEND_UNKNOWN = 0,
902+
/// The backend is Level Zero
903+
UR_BACKEND_LEVEL_ZERO = 1,
904+
/// The backend is OpenCL
905+
UR_BACKEND_OPENCL = 2,
906+
/// The backend is CUDA
907+
UR_BACKEND_CUDA = 3,
908+
/// The backend is HIP
909+
UR_BACKEND_HIP = 4,
910+
/// The backend is Native CPU
911+
UR_BACKEND_NATIVE_CPU = 5,
912+
/// @cond
913+
UR_BACKEND_FORCE_UINT32 = 0x7fffffff
914+
/// @endcond
915+
916+
} ur_backend_t;
917+
897918
#if !defined(__GNUC__)
898919
#pragma endregion
899920
#endif
@@ -1308,8 +1329,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
13081329
///////////////////////////////////////////////////////////////////////////////
13091330
/// @brief Supported adapter info
13101331
typedef enum ur_adapter_info_t {
1311-
/// [::ur_adapter_backend_t] Identifies the native backend supported by
1312-
/// the adapter.
1332+
/// [::ur_backend_t] Identifies the native backend supported by the
1333+
/// adapter.
13131334
UR_ADAPTER_INFO_BACKEND = 0,
13141335
/// [uint32_t] Reference count of the adapter.
13151336
/// The reference count returned should be considered immediately stale.
@@ -1370,27 +1391,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(
13701391
/// pPropValue.
13711392
size_t *pPropSizeRet);
13721393

1373-
///////////////////////////////////////////////////////////////////////////////
1374-
/// @brief Identifies backend of the adapter
1375-
typedef enum ur_adapter_backend_t {
1376-
/// The backend is not a recognized one
1377-
UR_ADAPTER_BACKEND_UNKNOWN = 0,
1378-
/// The backend is Level Zero
1379-
UR_ADAPTER_BACKEND_LEVEL_ZERO = 1,
1380-
/// The backend is OpenCL
1381-
UR_ADAPTER_BACKEND_OPENCL = 2,
1382-
/// The backend is CUDA
1383-
UR_ADAPTER_BACKEND_CUDA = 3,
1384-
/// The backend is HIP
1385-
UR_ADAPTER_BACKEND_HIP = 4,
1386-
/// The backend is Native CPU
1387-
UR_ADAPTER_BACKEND_NATIVE_CPU = 5,
1388-
/// @cond
1389-
UR_ADAPTER_BACKEND_FORCE_UINT32 = 0x7fffffff
1390-
/// @endcond
1391-
1392-
} ur_adapter_backend_t;
1393-
13941394
#if !defined(__GNUC__)
13951395
#pragma endregion
13961396
#endif
@@ -1457,8 +1457,8 @@ typedef enum ur_platform_info_t {
14571457
/// [char[]] The string denoting profile of the platform. The size of the
14581458
/// info needs to be dynamically queried.
14591459
UR_PLATFORM_INFO_PROFILE = 5,
1460-
/// [::ur_platform_backend_t] The backend of the platform. Identifies the
1461-
/// native backend adapter implementing this platform.
1460+
/// [::ur_backend_t] The backend of the platform. Identifies the native
1461+
/// backend adapter implementing this platform.
14621462
UR_PLATFORM_INFO_BACKEND = 6,
14631463
/// [::ur_adapter_handle_t] The adapter handle associated with the
14641464
/// platform.
@@ -1677,27 +1677,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption(
16771677
/// the frontend option.
16781678
const char **ppPlatformOption);
16791679

1680-
///////////////////////////////////////////////////////////////////////////////
1681-
/// @brief Identifies native backend adapters
1682-
typedef enum ur_platform_backend_t {
1683-
/// The backend is not a recognized one
1684-
UR_PLATFORM_BACKEND_UNKNOWN = 0,
1685-
/// The backend is Level Zero
1686-
UR_PLATFORM_BACKEND_LEVEL_ZERO = 1,
1687-
/// The backend is OpenCL
1688-
UR_PLATFORM_BACKEND_OPENCL = 2,
1689-
/// The backend is CUDA
1690-
UR_PLATFORM_BACKEND_CUDA = 3,
1691-
/// The backend is HIP
1692-
UR_PLATFORM_BACKEND_HIP = 4,
1693-
/// The backend is Native CPU
1694-
UR_PLATFORM_BACKEND_NATIVE_CPU = 5,
1695-
/// @cond
1696-
UR_PLATFORM_BACKEND_FORCE_UINT32 = 0x7fffffff
1697-
/// @endcond
1698-
1699-
} ur_platform_backend_t;
1700-
17011680
#if !defined(__GNUC__)
17021681
#pragma endregion
17031682
#endif

unified-runtime/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

unified-runtime/include/ur_print.hpp

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ operator<<(std::ostream &os,
277277
inline std::ostream &
278278
operator<<(std::ostream &os,
279279
[[maybe_unused]] const struct ur_rect_region_t params);
280+
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value);
280281
inline std::ostream &operator<<(std::ostream &os,
281282
enum ur_device_init_flag_t value);
282283
inline std::ostream &operator<<(std::ostream &os,
@@ -285,16 +286,12 @@ inline std::ostream &
285286
operator<<(std::ostream &os,
286287
[[maybe_unused]] const struct ur_code_location_t params);
287288
inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value);
288-
inline std::ostream &operator<<(std::ostream &os,
289-
enum ur_adapter_backend_t value);
290289
inline std::ostream &operator<<(std::ostream &os,
291290
enum ur_platform_info_t value);
292291
inline std::ostream &operator<<(std::ostream &os, enum ur_api_version_t value);
293292
inline std::ostream &operator<<(
294293
std::ostream &os,
295294
[[maybe_unused]] const struct ur_platform_native_properties_t params);
296-
inline std::ostream &operator<<(std::ostream &os,
297-
enum ur_platform_backend_t value);
298295
inline std::ostream &
299296
operator<<(std::ostream &os,
300297
[[maybe_unused]] const struct ur_device_binary_t params);
@@ -1982,6 +1979,36 @@ inline std::ostream &operator<<(std::ostream &os,
19821979
return os;
19831980
}
19841981
///////////////////////////////////////////////////////////////////////////////
1982+
/// @brief Print operator for the ur_backend_t type
1983+
/// @returns
1984+
/// std::ostream &
1985+
inline std::ostream &operator<<(std::ostream &os, enum ur_backend_t value) {
1986+
switch (value) {
1987+
case UR_BACKEND_UNKNOWN:
1988+
os << "UR_BACKEND_UNKNOWN";
1989+
break;
1990+
case UR_BACKEND_LEVEL_ZERO:
1991+
os << "UR_BACKEND_LEVEL_ZERO";
1992+
break;
1993+
case UR_BACKEND_OPENCL:
1994+
os << "UR_BACKEND_OPENCL";
1995+
break;
1996+
case UR_BACKEND_CUDA:
1997+
os << "UR_BACKEND_CUDA";
1998+
break;
1999+
case UR_BACKEND_HIP:
2000+
os << "UR_BACKEND_HIP";
2001+
break;
2002+
case UR_BACKEND_NATIVE_CPU:
2003+
os << "UR_BACKEND_NATIVE_CPU";
2004+
break;
2005+
default:
2006+
os << "unknown enumerator";
2007+
break;
2008+
}
2009+
return os;
2010+
}
2011+
///////////////////////////////////////////////////////////////////////////////
19852012
/// @brief Print operator for the ur_device_init_flag_t type
19862013
/// @returns
19872014
/// std::ostream &
@@ -2200,10 +2227,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
22002227

22012228
switch (value) {
22022229
case UR_ADAPTER_INFO_BACKEND: {
2203-
const ur_adapter_backend_t *tptr = (const ur_adapter_backend_t *)ptr;
2204-
if (sizeof(ur_adapter_backend_t) > size) {
2230+
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
2231+
if (sizeof(ur_backend_t) > size) {
22052232
os << "invalid size (is: " << size
2206-
<< ", expected: >=" << sizeof(ur_adapter_backend_t) << ")";
2233+
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
22072234
return UR_RESULT_ERROR_INVALID_SIZE;
22082235
}
22092236
os << (const void *)(tptr) << " (";
@@ -2246,37 +2273,6 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
22462273
}
22472274
} // namespace ur::details
22482275

2249-
///////////////////////////////////////////////////////////////////////////////
2250-
/// @brief Print operator for the ur_adapter_backend_t type
2251-
/// @returns
2252-
/// std::ostream &
2253-
inline std::ostream &operator<<(std::ostream &os,
2254-
enum ur_adapter_backend_t value) {
2255-
switch (value) {
2256-
case UR_ADAPTER_BACKEND_UNKNOWN:
2257-
os << "UR_ADAPTER_BACKEND_UNKNOWN";
2258-
break;
2259-
case UR_ADAPTER_BACKEND_LEVEL_ZERO:
2260-
os << "UR_ADAPTER_BACKEND_LEVEL_ZERO";
2261-
break;
2262-
case UR_ADAPTER_BACKEND_OPENCL:
2263-
os << "UR_ADAPTER_BACKEND_OPENCL";
2264-
break;
2265-
case UR_ADAPTER_BACKEND_CUDA:
2266-
os << "UR_ADAPTER_BACKEND_CUDA";
2267-
break;
2268-
case UR_ADAPTER_BACKEND_HIP:
2269-
os << "UR_ADAPTER_BACKEND_HIP";
2270-
break;
2271-
case UR_ADAPTER_BACKEND_NATIVE_CPU:
2272-
os << "UR_ADAPTER_BACKEND_NATIVE_CPU";
2273-
break;
2274-
default:
2275-
os << "unknown enumerator";
2276-
break;
2277-
}
2278-
return os;
2279-
}
22802276
///////////////////////////////////////////////////////////////////////////////
22812277
/// @brief Print operator for the ur_platform_info_t type
22822278
/// @returns
@@ -2348,10 +2344,10 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
23482344
printPtr(os, tptr);
23492345
} break;
23502346
case UR_PLATFORM_INFO_BACKEND: {
2351-
const ur_platform_backend_t *tptr = (const ur_platform_backend_t *)ptr;
2352-
if (sizeof(ur_platform_backend_t) > size) {
2347+
const ur_backend_t *tptr = (const ur_backend_t *)ptr;
2348+
if (sizeof(ur_backend_t) > size) {
23532349
os << "invalid size (is: " << size
2354-
<< ", expected: >=" << sizeof(ur_platform_backend_t) << ")";
2350+
<< ", expected: >=" << sizeof(ur_backend_t) << ")";
23552351
return UR_RESULT_ERROR_INVALID_SIZE;
23562352
}
23572353
os << (const void *)(tptr) << " (";
@@ -2416,37 +2412,6 @@ operator<<(std::ostream &os,
24162412
return os;
24172413
}
24182414
///////////////////////////////////////////////////////////////////////////////
2419-
/// @brief Print operator for the ur_platform_backend_t type
2420-
/// @returns
2421-
/// std::ostream &
2422-
inline std::ostream &operator<<(std::ostream &os,
2423-
enum ur_platform_backend_t value) {
2424-
switch (value) {
2425-
case UR_PLATFORM_BACKEND_UNKNOWN:
2426-
os << "UR_PLATFORM_BACKEND_UNKNOWN";
2427-
break;
2428-
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
2429-
os << "UR_PLATFORM_BACKEND_LEVEL_ZERO";
2430-
break;
2431-
case UR_PLATFORM_BACKEND_OPENCL:
2432-
os << "UR_PLATFORM_BACKEND_OPENCL";
2433-
break;
2434-
case UR_PLATFORM_BACKEND_CUDA:
2435-
os << "UR_PLATFORM_BACKEND_CUDA";
2436-
break;
2437-
case UR_PLATFORM_BACKEND_HIP:
2438-
os << "UR_PLATFORM_BACKEND_HIP";
2439-
break;
2440-
case UR_PLATFORM_BACKEND_NATIVE_CPU:
2441-
os << "UR_PLATFORM_BACKEND_NATIVE_CPU";
2442-
break;
2443-
default:
2444-
os << "unknown enumerator";
2445-
break;
2446-
}
2447-
return os;
2448-
}
2449-
///////////////////////////////////////////////////////////////////////////////
24502415
/// @brief Print operator for the ur_device_binary_t type
24512416
/// @returns
24522417
/// std::ostream &

unified-runtime/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)