Skip to content

Commit 4e69cc6

Browse files
authored
Merge pull request #740 from Wee-Free-Scot/Issue220_Add-support-for-ODS
Implement ONEAPI_DEVICE_SELECTOR in UR
2 parents b4150ad + 085f991 commit 4e69cc6

File tree

13 files changed

+1131
-3
lines changed

13 files changed

+1131
-3
lines changed

include/ur_api.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ typedef enum ur_function_t {
220220
UR_FUNCTION_COMMAND_BUFFER_RELEASE_COMMAND_EXP = 217, ///< Enumerator for ::urCommandBufferReleaseCommandExp
221221
UR_FUNCTION_COMMAND_BUFFER_GET_INFO_EXP = 218, ///< Enumerator for ::urCommandBufferGetInfoExp
222222
UR_FUNCTION_COMMAND_BUFFER_COMMAND_GET_INFO_EXP = 219, ///< Enumerator for ::urCommandBufferCommandGetInfoExp
223+
UR_FUNCTION_DEVICE_GET_SELECTED = 220, ///< Enumerator for ::urDeviceGetSelected
223224
/// @cond
224225
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
225226
/// @endcond
@@ -1387,6 +1388,46 @@ urDeviceGet(
13871388
///< pNumDevices will be updated with the total number of devices available.
13881389
);
13891390

1391+
///////////////////////////////////////////////////////////////////////////////
1392+
/// @brief Retrieves devices within a platform selected by ONEAPI_DEVICE_SELECTOR
1393+
///
1394+
/// @details
1395+
/// - Multiple calls to this function will return identical device handles,
1396+
/// in the same order.
1397+
/// - The number and order of handles returned from this function will be
1398+
/// affected by environment variables that filter or select which devices
1399+
/// are exposed through this API.
1400+
/// - A reference is taken for each returned device and must be released
1401+
/// with a subsequent call to ::urDeviceRelease.
1402+
/// - The application may call this function from simultaneous threads, the
1403+
/// implementation must be thread-safe.
1404+
///
1405+
/// @returns
1406+
/// - ::UR_RESULT_SUCCESS
1407+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
1408+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
1409+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
1410+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
1411+
/// + `NULL == hPlatform`
1412+
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
1413+
/// + `::UR_DEVICE_TYPE_VPU < DeviceType`
1414+
/// - ::UR_RESULT_ERROR_INVALID_VALUE
1415+
UR_APIEXPORT ur_result_t UR_APICALL
1416+
urDeviceGetSelected(
1417+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance
1418+
ur_device_type_t DeviceType, ///< [in] the type of the devices.
1419+
uint32_t NumEntries, ///< [in] the number of devices to be added to phDevices.
1420+
///< If phDevices in not NULL then NumEntries should be greater than zero,
1421+
///< otherwise ::UR_RESULT_ERROR_INVALID_VALUE,
1422+
///< will be returned.
1423+
ur_device_handle_t *phDevices, ///< [out][optional][range(0, NumEntries)] array of handle of devices.
1424+
///< If NumEntries is less than the number of devices available, then only
1425+
///< that number of devices will be retrieved.
1426+
uint32_t *pNumDevices ///< [out][optional] pointer to the number of devices.
1427+
///< pNumDevices will be updated with the total number of selected devices
1428+
///< available for the given platform.
1429+
);
1430+
13901431
///////////////////////////////////////////////////////////////////////////////
13911432
/// @brief Supported device info
13921433
typedef enum ur_device_info_t {
@@ -11154,6 +11195,18 @@ typedef struct ur_device_get_params_t {
1115411195
uint32_t **ppNumDevices;
1115511196
} ur_device_get_params_t;
1115611197

11198+
///////////////////////////////////////////////////////////////////////////////
11199+
/// @brief Function parameters for urDeviceGetSelected
11200+
/// @details Each entry is a pointer to the parameter passed to the function;
11201+
/// allowing the callback the ability to modify the parameter's value
11202+
typedef struct ur_device_get_selected_params_t {
11203+
ur_platform_handle_t *phPlatform;
11204+
ur_device_type_t *pDeviceType;
11205+
uint32_t *pNumEntries;
11206+
ur_device_handle_t **pphDevices;
11207+
uint32_t **ppNumDevices;
11208+
} ur_device_get_selected_params_t;
11209+
1115711210
///////////////////////////////////////////////////////////////////////////////
1115811211
/// @brief Function parameters for urDeviceGetInfo
1115911212
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_print.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintVirtualMemGetInfoParams(const struct
24502450
/// - `buff_size < out_size`
24512451
UR_APIEXPORT ur_result_t UR_APICALL urPrintDeviceGetParams(const struct ur_device_get_params_t *params, char *buffer, const size_t buff_size, size_t *out_size);
24522452

2453+
///////////////////////////////////////////////////////////////////////////////
2454+
/// @brief Print ur_device_get_selected_params_t struct
2455+
/// @returns
2456+
/// - ::UR_RESULT_SUCCESS
2457+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
2458+
/// - `buff_size < out_size`
2459+
UR_APIEXPORT ur_result_t UR_APICALL urPrintDeviceGetSelectedParams(const struct ur_device_get_selected_params_t *params, char *buffer, const size_t buff_size, size_t *out_size);
2460+
24532461
///////////////////////////////////////////////////////////////////////////////
24542462
/// @brief Print ur_device_get_info_params_t struct
24552463
/// @returns

include/ur_print.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
909909
case UR_FUNCTION_COMMAND_BUFFER_COMMAND_GET_INFO_EXP:
910910
os << "UR_FUNCTION_COMMAND_BUFFER_COMMAND_GET_INFO_EXP";
911911
break;
912+
case UR_FUNCTION_DEVICE_GET_SELECTED:
913+
os << "UR_FUNCTION_DEVICE_GET_SELECTED";
914+
break;
912915
default:
913916
os << "unknown enumerator";
914917
break;
@@ -16292,6 +16295,48 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
1629216295
return os;
1629316296
}
1629416297

16298+
///////////////////////////////////////////////////////////////////////////////
16299+
/// @brief Print operator for the ur_device_get_selected_params_t type
16300+
/// @returns
16301+
/// std::ostream &
16302+
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_device_get_selected_params_t *params) {
16303+
16304+
os << ".hPlatform = ";
16305+
16306+
ur::details::printPtr(os,
16307+
*(params->phPlatform));
16308+
16309+
os << ", ";
16310+
os << ".DeviceType = ";
16311+
16312+
os << *(params->pDeviceType);
16313+
16314+
os << ", ";
16315+
os << ".NumEntries = ";
16316+
16317+
os << *(params->pNumEntries);
16318+
16319+
os << ", ";
16320+
os << ".phDevices = {";
16321+
for (size_t i = 0; *(params->pphDevices) != NULL && i < *params->pNumEntries; ++i) {
16322+
if (i != 0) {
16323+
os << ", ";
16324+
}
16325+
16326+
ur::details::printPtr(os,
16327+
(*(params->pphDevices))[i]);
16328+
}
16329+
os << "}";
16330+
16331+
os << ", ";
16332+
os << ".pNumDevices = ";
16333+
16334+
ur::details::printPtr(os,
16335+
*(params->ppNumDevices));
16336+
16337+
return os;
16338+
}
16339+
1629516340
///////////////////////////////////////////////////////////////////////////////
1629616341
/// @brief Print operator for the ur_device_get_info_params_t type
1629716342
/// @returns
@@ -17090,6 +17135,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_
1709017135
case UR_FUNCTION_DEVICE_GET: {
1709117136
os << (const struct ur_device_get_params_t *)params;
1709217137
} break;
17138+
case UR_FUNCTION_DEVICE_GET_SELECTED: {
17139+
os << (const struct ur_device_get_selected_params_t *)params;
17140+
} break;
1709317141
case UR_FUNCTION_DEVICE_GET_INFO: {
1709417142
os << (const struct ur_device_get_info_params_t *)params;
1709517143
} break;

scripts/core/device.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,45 @@ returns:
150150
- "`NumEntries > 0 && phDevices == NULL`"
151151
- $X_RESULT_ERROR_INVALID_VALUE
152152
--- #--------------------------------------------------------------------------
153+
type: function
154+
desc: "Retrieves devices within a platform selected by ONEAPI_DEVICE_SELECTOR"
155+
class: $xDevice
156+
loader_only: True
157+
name: GetSelected
158+
decl: static
159+
ordinal: "0"
160+
details:
161+
- "Multiple calls to this function will return identical device handles, in the same order."
162+
- "The number and order of handles returned from this function will be affected by environment variables that filter or select which devices are exposed through this API."
163+
- "A reference is taken for each returned device and must be released with a subsequent call to $xDeviceRelease."
164+
- "The application may call this function from simultaneous threads, the implementation must be thread-safe."
165+
params:
166+
- type: $x_platform_handle_t
167+
name: hPlatform
168+
desc: "[in] handle of the platform instance"
169+
- type: "$x_device_type_t"
170+
name: DeviceType
171+
desc: |
172+
[in] the type of the devices.
173+
- type: "uint32_t"
174+
name: NumEntries
175+
desc: |
176+
[in] the number of devices to be added to phDevices.
177+
If phDevices in not NULL then NumEntries should be greater than zero, otherwise $X_RESULT_ERROR_INVALID_VALUE,
178+
will be returned.
179+
- type: "$x_device_handle_t*"
180+
name: phDevices
181+
desc: |
182+
[out][optional][range(0, NumEntries)] array of handle of devices.
183+
If NumEntries is less than the number of devices available, then only that number of devices will be retrieved.
184+
- type: "uint32_t*"
185+
name: pNumDevices
186+
desc: |
187+
[out][optional] pointer to the number of devices.
188+
pNumDevices will be updated with the total number of selected devices available for the given platform.
189+
returns:
190+
- $X_RESULT_ERROR_INVALID_VALUE
191+
--- #--------------------------------------------------------------------------
153192
type: enum
154193
desc: "Supported device info"
155194
class: $xDevice

scripts/core/registry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ etors:
574574
- name: COMMAND_BUFFER_COMMAND_GET_INFO_EXP
575575
desc: Enumerator for $xCommandBufferCommandGetInfoExp
576576
value: '219'
577+
- name: DEVICE_GET_SELECTED
578+
desc: Enumerator for $xDeviceGetSelected
579+
value: '220'
577580
---
578581
type: enum
579582
desc: Defines structure types

0 commit comments

Comments
 (0)