Skip to content

Commit e1d0da8

Browse files
Merge pull request #2032 from al42and/more-robust-opencl
[CL] Make device queries more robust
2 parents cd92304 + 9623c0a commit e1d0da8

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

include/ur_api.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,7 @@ typedef enum ur_device_info_t {
15691569
///< ::urDevicePartition
15701570
UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS = 80, ///< [uint32_t] max number of sub groups
15711571
UR_DEVICE_INFO_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS = 81, ///< [::ur_bool_t] support sub group independent forward progress
1572-
UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL = 82, ///< [uint32_t[]] return an array of sub group sizes supported on Intel
1573-
///< device
1572+
UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL = 82, ///< [uint32_t[]] return an array of supported sub group sizes
15741573
UR_DEVICE_INFO_USM_HOST_SUPPORT = 83, ///< [::ur_device_usm_access_capability_flags_t] support USM host memory
15751574
///< access
15761575
UR_DEVICE_INFO_USM_DEVICE_SUPPORT = 84, ///< [::ur_device_usm_access_capability_flags_t] support USM device memory

scripts/core/device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ etors:
365365
- name: SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS
366366
desc: "[$x_bool_t] support sub group independent forward progress"
367367
- name: SUB_GROUP_SIZES_INTEL
368-
desc: "[uint32_t[]] return an array of sub group sizes supported on Intel device"
368+
desc: "[uint32_t[]] return an array of supported sub group sizes"
369369
- name: USM_HOST_SUPPORT
370370
desc: "[$x_device_usm_access_capability_flags_t] support USM host memory access"
371371
- name: USM_DEVICE_SUPPORT

source/adapters/opencl/device.cpp

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,12 +825,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
825825
case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_TYPE:
826826
case UR_DEVICE_INFO_LOCAL_MEM_TYPE:
827827
case UR_DEVICE_INFO_EXECUTION_CAPABILITIES:
828-
case UR_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN:
829-
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
830-
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
831-
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
832-
case UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT:
833-
case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT: {
828+
case UR_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN: {
834829
/* CL type: cl_bitfield / enum
835830
* UR type: ur_flags_t (uint32_t) */
836831

@@ -844,6 +839,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
844839
* types are uint32_t */
845840
return ReturnValue(static_cast<uint32_t>(CLValue));
846841
}
842+
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
843+
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
844+
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
845+
case UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT:
846+
case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT: {
847+
/* CL type: cl_bitfield / enum
848+
* UR type: ur_flags_t (uint32_t) */
849+
bool Supported = false;
850+
UR_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
851+
cl_adapter::cast<cl_device_id>(hDevice),
852+
{"cl_intel_unified_shared_memory"}, Supported));
853+
if (Supported) {
854+
cl_bitfield CLValue = 0;
855+
CL_RETURN_ON_FAILURE(
856+
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CLPropName,
857+
sizeof(cl_bitfield), &CLValue, nullptr));
858+
return ReturnValue(static_cast<uint32_t>(CLValue));
859+
} else {
860+
return ReturnValue(0);
861+
}
862+
}
847863
case UR_DEVICE_INFO_IMAGE_SUPPORTED:
848864
case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT:
849865
case UR_DEVICE_INFO_HOST_UNIFIED_MEMORY:
@@ -918,8 +934,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
918934
case UR_DEVICE_INFO_VERSION:
919935
case UR_EXT_DEVICE_INFO_OPENCL_C_VERSION:
920936
case UR_DEVICE_INFO_BUILT_IN_KERNELS:
921-
case UR_DEVICE_INFO_MAX_WORK_ITEM_SIZES:
922-
case UR_DEVICE_INFO_IP_VERSION: {
937+
case UR_DEVICE_INFO_MAX_WORK_ITEM_SIZES: {
923938
/* We can just use the OpenCL outputs because the sizes of OpenCL types
924939
* are the same as UR.
925940
* | CL | UR | Size |
@@ -937,7 +952,33 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
937952

938953
return UR_RESULT_SUCCESS;
939954
}
955+
case UR_DEVICE_INFO_IP_VERSION: {
956+
bool Supported;
957+
UR_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
958+
cl_adapter::cast<cl_device_id>(hDevice),
959+
{"cl_intel_device_attribute_query"}, Supported));
960+
if (!Supported) {
961+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
962+
}
963+
CL_RETURN_ON_FAILURE(
964+
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CLPropName,
965+
propSize, pPropValue, pPropSizeRet));
966+
967+
return UR_RESULT_SUCCESS;
968+
}
969+
940970
case UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: {
971+
bool isExtensionSupported;
972+
if (cl_adapter::checkDeviceExtensions(
973+
cl_adapter::cast<cl_device_id>(hDevice),
974+
{"cl_intel_required_subgroup_size"},
975+
isExtensionSupported) != UR_RESULT_SUCCESS ||
976+
!isExtensionSupported) {
977+
std::vector<uint32_t> aThreadIsItsOwnSubGroup({1});
978+
return ReturnValue(aThreadIsItsOwnSubGroup.data(),
979+
aThreadIsItsOwnSubGroup.size());
980+
}
981+
941982
// Have to convert size_t to uint32_t
942983
size_t SubGroupSizesSize = 0;
943984
CL_RETURN_ON_FAILURE(

0 commit comments

Comments
 (0)