1212
1313#include < cassert>
1414
15- ur_result_t cl_adapter::getDeviceVersion (cl_device_id Dev,
16- oclv::OpenCLVersion &Version) {
17-
18- size_t DevVerSize = 0 ;
19- CL_RETURN_ON_FAILURE (
20- clGetDeviceInfo (Dev, CL_DEVICE_VERSION, 0 , nullptr , &DevVerSize));
21-
22- std::string DevVer (DevVerSize, ' \0 ' );
23- CL_RETURN_ON_FAILURE (clGetDeviceInfo (Dev, CL_DEVICE_VERSION, DevVerSize,
24- DevVer.data (), nullptr ));
25-
26- Version = oclv::OpenCLVersion (DevVer);
27- if (!Version.isValid ()) {
28- return UR_RESULT_ERROR_INVALID_DEVICE;
29- }
30-
31- return UR_RESULT_SUCCESS;
32- }
33-
34- ur_result_t cl_adapter::checkDeviceExtensions (
35- cl_device_id Dev, const std::vector<std::string> &Exts, bool &Supported) {
36- size_t ExtSize = 0 ;
37- CL_RETURN_ON_FAILURE (
38- clGetDeviceInfo (Dev, CL_DEVICE_EXTENSIONS, 0 , nullptr , &ExtSize));
39-
40- std::string ExtStr (ExtSize, ' \0 ' );
41-
42- CL_RETURN_ON_FAILURE (clGetDeviceInfo (Dev, CL_DEVICE_EXTENSIONS, ExtSize,
43- ExtStr.data (), nullptr ));
44-
45- Supported = true ;
46- for (const std::string &Ext : Exts) {
47- if (!(Supported = (ExtStr.find (Ext) != std::string::npos))) {
48- break ;
49- }
50- }
51-
52- return UR_RESULT_SUCCESS;
53- }
54-
5515UR_APIEXPORT ur_result_t UR_APICALL
5616urDeviceGet (ur_platform_handle_t hPlatform, ur_device_type_t DeviceType,
5717 [[maybe_unused]] uint32_t NumEntries, ur_device_handle_t *phDevices,
@@ -351,8 +311,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
351311 }
352312 case UR_DEVICE_INFO_DEVICE_ID: {
353313 bool Supported = false ;
354- CL_RETURN_ON_FAILURE (cl_adapter::checkDeviceExtensions (
355- hDevice->get (), {" cl_khr_pci_bus_info" }, Supported));
314+ CL_RETURN_ON_FAILURE (
315+ hDevice->checkDeviceExtensions ( {" cl_khr_pci_bus_info" }, Supported));
356316
357317 if (!Supported) {
358318 return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
@@ -367,7 +327,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
367327
368328 case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: {
369329 oclv::OpenCLVersion Version;
370- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), Version));
330+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( Version));
371331
372332 const std::string Results = std::to_string (Version.getMajor ()) + " ." +
373333 std::to_string (Version.getMinor ());
@@ -470,7 +430,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
470430 /* Corresponding OpenCL query is only available starting with OpenCL 2.1
471431 * and we have to emulate it on older OpenCL runtimes. */
472432 oclv::OpenCLVersion DevVer;
473- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), DevVer));
433+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( DevVer));
474434
475435 if (DevVer >= oclv::V2_1) {
476436 cl_uint CLValue;
@@ -499,8 +459,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
499459 * UR type: ur_device_fp_capability_flags_t */
500460 if (propName == UR_DEVICE_INFO_HALF_FP_CONFIG) {
501461 bool Supported;
502- CL_RETURN_ON_FAILURE (cl_adapter::checkDeviceExtensions (
503- hDevice->get (), {" cl_khr_fp16" }, Supported));
462+ CL_RETURN_ON_FAILURE (
463+ hDevice->checkDeviceExtensions ( {" cl_khr_fp16" }, Supported));
504464
505465 if (!Supported) {
506466 return UR_RESULT_ERROR_INVALID_ENUMERATION;
@@ -519,7 +479,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
519479 /* This query is missing before OpenCL 3.0. Check version and handle
520480 * appropriately */
521481 oclv::OpenCLVersion DevVer;
522- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), DevVer));
482+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( DevVer));
523483
524484 /* Minimum required capability to be returned. For OpenCL 1.2, this is all
525485 * that is required */
@@ -576,7 +536,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
576536 UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP;
577537
578538 oclv::OpenCLVersion DevVer;
579- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), DevVer));
539+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( DevVer));
580540
581541 cl_device_atomic_capabilities CLCapabilities;
582542 if (DevVer >= oclv::V3_0) {
@@ -627,7 +587,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
627587 UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQ_REL;
628588
629589 oclv::OpenCLVersion DevVer;
630- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), DevVer));
590+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( DevVer));
631591
632592 cl_device_atomic_capabilities CLCapabilities;
633593 if (DevVer >= oclv::V3_0) {
@@ -674,7 +634,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
674634 UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP;
675635
676636 oclv::OpenCLVersion DevVer;
677- CL_RETURN_ON_FAILURE (cl_adapter::getDeviceVersion ( hDevice->get (), DevVer));
637+ CL_RETURN_ON_FAILURE (hDevice->getDeviceVersion ( DevVer));
678638
679639 cl_device_atomic_capabilities CLCapabilities;
680640 if (DevVer >= oclv::V3_0) {
@@ -725,8 +685,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
725685 }
726686 case UR_DEVICE_INFO_ATOMIC_64: {
727687 bool Supported = false ;
728- CL_RETURN_ON_FAILURE (cl_adapter::checkDeviceExtensions (
729- hDevice->get (),
688+ CL_RETURN_ON_FAILURE (hDevice->checkDeviceExtensions (
730689 {" cl_khr_int64_base_atomics" , " cl_khr_int64_extended_atomics" },
731690 Supported));
732691
@@ -743,8 +702,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
743702 }
744703 case UR_DEVICE_INFO_MEM_CHANNEL_SUPPORT: {
745704 bool Supported = false ;
746- CL_RETURN_ON_FAILURE (cl_adapter:: checkDeviceExtensions (
747- hDevice-> get (), {" cl_intel_mem_channel_property" }, Supported));
705+ CL_RETURN_ON_FAILURE (hDevice-> checkDeviceExtensions (
706+ {" cl_intel_mem_channel_property" }, Supported));
748707
749708 return ReturnValue (Supported);
750709 }
@@ -769,8 +728,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
769728 }
770729 case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
771730 bool Supported = false ;
772- CL_RETURN_ON_FAILURE (cl_adapter:: checkDeviceExtensions (
773- hDevice-> get (), {" cl_intel_program_scope_host_pipe" }, Supported));
731+ CL_RETURN_ON_FAILURE (hDevice-> checkDeviceExtensions (
732+ {" cl_intel_program_scope_host_pipe" }, Supported));
774733 return ReturnValue (Supported);
775734 }
776735 case UR_DEVICE_INFO_QUEUE_PROPERTIES:
@@ -1064,18 +1023,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(
10641023 ur_device_handle_t hDevice, uint64_t *pDeviceTimestamp,
10651024 uint64_t *pHostTimestamp) {
10661025 oclv::OpenCLVersion DevVer, PlatVer;
1067- cl_platform_id Platform;
10681026 cl_device_id DeviceId = hDevice->get ();
10691027
10701028 // TODO: Cache OpenCL version for each device and platform
1071- auto RetErr = clGetDeviceInfo (DeviceId, CL_DEVICE_PLATFORM,
1072- sizeof (cl_platform_id), &Platform, nullptr );
1073- CL_RETURN_ON_FAILURE (RetErr);
10741029
1075- RetErr = cl_adapter:: getDeviceVersion (DeviceId, DevVer);
1030+ auto RetErr = hDevice-> getDeviceVersion (DevVer);
10761031 CL_RETURN_ON_FAILURE (RetErr);
10771032
1078- RetErr = cl_adapter:: getPlatformVersion (Platform, PlatVer);
1033+ RetErr = hDevice-> Platform -> getPlatformVersion (PlatVer);
10791034
10801035 if (PlatVer < oclv::V2_1 || DevVer < oclv::V2_1) {
10811036 return UR_RESULT_ERROR_INVALID_OPERATION;
0 commit comments