Skip to content

Commit 5524e9f

Browse files
committed
[SYCL][PI/CL] check for device version and extensions
There might be platforms where the supported device version is lower than the platform version or where not all devices do support the same extensions and hence some extensions supported by particular devices are not reported in the platform extensions. In particular for CL_PLATFORM_EXTENSIONS the OpenCL specification says: "[...] Each extension that is supported by all devices associated with this platform must be reported here." In "3.4.1 Mixed Version Support" the specification also says: "[...] The version returned corresponds to the highest version of the OpenCL specification for which the device is conformant, but is not higher than the platform version." Hence, check for the device version and extensions rather than the platform version and extensions in piProgramCreate(). Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 59a163b commit 5524e9f

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -539,38 +539,51 @@ pi_result piProgramCreate(pi_context context, const void *il, size_t length,
539539

540540
CHECK_ERR_SET_NULL_RET(ret_err, res_program, CL_INVALID_CONTEXT);
541541

542-
size_t devVerSize;
543-
ret_err = clGetPlatformInfo(curPlatform, CL_PLATFORM_VERSION, 0, nullptr,
544-
&devVerSize);
545-
std::string devVer(devVerSize, '\0');
546-
ret_err = clGetPlatformInfo(curPlatform, CL_PLATFORM_VERSION, devVerSize,
547-
&devVer.front(), nullptr);
542+
OCLV::OpenCLVersion platVer;
543+
ret_err = getPlatformVersion(curPlatform, platVer);
548544

549545
CHECK_ERR_SET_NULL_RET(ret_err, res_program, CL_INVALID_CONTEXT);
550546

551547
pi_result err = PI_SUCCESS;
552-
if (devVer.find("OpenCL 1.0") == std::string::npos &&
553-
devVer.find("OpenCL 1.1") == std::string::npos &&
554-
devVer.find("OpenCL 1.2") == std::string::npos &&
555-
devVer.find("OpenCL 2.0") == std::string::npos) {
548+
if (platVer >= OCLV::V2_1) {
549+
550+
/* Make sure all devices support CL 2.1 or newer as well. */
551+
for (cl_device_id dev : devicesInCtx) {
552+
OCLV::OpenCLVersion devVer;
553+
554+
ret_err = getDeviceVersion(dev, devVer);
555+
CHECK_ERR_SET_NULL_RET(ret_err, res_program, CL_INVALID_CONTEXT);
556+
557+
/* If the device does not support CL 2.1 or greater, we need to make sure
558+
* it supports the cl_khr_il_program extension.
559+
*/
560+
if (devVer < OCLV::V2_1) {
561+
bool supported = false;
562+
563+
ret_err = checkDeviceExtensions(dev, {"cl_khr_il_program"}, supported);
564+
CHECK_ERR_SET_NULL_RET(ret_err, res_program, CL_INVALID_CONTEXT);
565+
566+
if (!supported)
567+
return cast<pi_result>(CL_INVALID_OPERATION);
568+
}
569+
}
556570
if (res_program != nullptr)
557571
*res_program = cast<pi_program>(clCreateProgramWithIL(
558572
cast<cl_context>(context), il, length, cast<cl_int *>(&err)));
559573
return err;
560574
}
561575

562-
size_t extSize;
563-
ret_err = clGetPlatformInfo(curPlatform, CL_PLATFORM_EXTENSIONS, 0, nullptr,
564-
&extSize);
565-
std::string extStr(extSize, '\0');
566-
ret_err = clGetPlatformInfo(curPlatform, CL_PLATFORM_EXTENSIONS, extSize,
567-
&extStr.front(), nullptr);
576+
/* If none of the devices conform with CL 2.1 or newer make sure they all
577+
* support the cl_khr_il_program extension.
578+
*/
579+
for (cl_device_id dev : devicesInCtx) {
580+
bool supported = false;
568581

569-
if (ret_err != CL_SUCCESS ||
570-
extStr.find("cl_khr_il_program") == std::string::npos) {
571-
if (res_program != nullptr)
572-
*res_program = nullptr;
573-
return cast<pi_result>(CL_INVALID_CONTEXT);
582+
ret_err = checkDeviceExtensions(dev, {"cl_khr_il_program"}, supported);
583+
CHECK_ERR_SET_NULL_RET(ret_err, res_program, CL_INVALID_CONTEXT);
584+
585+
if (!supported)
586+
return cast<pi_result>(CL_INVALID_OPERATION);
574587
}
575588

576589
using apiFuncT =

0 commit comments

Comments
 (0)