diff --git a/sycl/source/detail/device_info.hpp b/sycl/source/detail/device_info.hpp index 4d46720fc7ce5..4fc8be379bb0e 100644 --- a/sycl/source/detail/device_info.hpp +++ b/sycl/source/detail/device_info.hpp @@ -122,8 +122,9 @@ template struct get_device_info { } }; -// Specialization for string return type, variable return size -template struct get_device_info { +// Helper struct to allow using the specialization of get_device_info +// for string return type in other specializations. +template struct get_device_info_string { static string_class get(RT::PiDevice dev, const plugin &Plugin) { size_t resultSize; Plugin.call( @@ -140,6 +141,13 @@ template struct get_device_info { } }; +// Specialization for string return type, variable return size +template struct get_device_info { + static string_class get(RT::PiDevice dev, const plugin &Plugin) { + return get_device_info_string::get(dev, Plugin); + } +}; + // Specialization for parent device template struct get_device_info { static T get(RT::PiDevice dev, const plugin &Plugin); @@ -176,6 +184,30 @@ struct get_device_info, param> { } }; +// Specialization for OpenCL version, splits the string returned by OpenCL +template <> struct get_device_info { + static string_class get(RT::PiDevice dev, const plugin &Plugin) { + string_class result = + get_device_info_string::get(dev, Plugin); + + // Extract OpenCL version from the returned string. + // For example, for the string "OpenCL 2.1 (Build 0)" + // return '2.1'. + auto dotPos = result.find('.'); + if (dotPos == std::string::npos) + return result; + + auto leftPos = result.rfind(' ', dotPos); + if (leftPos == std::string::npos) + leftPos = 0; + else + leftPos++; + + auto rightPos = result.find(' ', dotPos); + return result.substr(leftPos, rightPos - leftPos); + } +}; + // Specialization for single_fp_config, no type support check required template <> struct get_device_info, diff --git a/sycl/source/detail/error_handling/enqueue_kernel.cpp b/sycl/source/detail/error_handling/enqueue_kernel.cpp index 455c88bbc7e66..ab846466161ca 100644 --- a/sycl/source/detail/error_handling/enqueue_kernel.cpp +++ b/sycl/source/detail/error_handling/enqueue_kernel.cpp @@ -57,8 +57,8 @@ bool handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, if (Platform.get_backend() == cl::sycl::backend::opencl) { string_class VersionString = DeviceImpl.get_info(); IsOpenCL = true; - IsOpenCLV1x = (VersionString.find("OpenCL 1.") == 0); - IsOpenCLV20 = (VersionString.find("OpenCL 2.0") == 0); + IsOpenCLV1x = (VersionString.find("1.") == 0); + IsOpenCLV20 = (VersionString.find("2.0") == 0); } size_t CompileWGSize[3] = {0}; diff --git a/sycl/test/basic_tests/info_ocl_version.cpp b/sycl/test/basic_tests/info_ocl_version.cpp new file mode 100644 index 0000000000000..e42383bbe3e79 --- /dev/null +++ b/sycl/test/basic_tests/info_ocl_version.cpp @@ -0,0 +1,37 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: env %CPU_RUN_PLACEHOLDER %t.out +// RUN: env %GPU_RUN_PLACEHOLDER %t.out +// RUN: env %ACC_RUN_PLACEHOLDER %t.out + +//==--------info_ocl_version.cpp - SYCL objects get_info() test ------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +using namespace cl::sycl; + +// This test checks that cl::sycl::info::device::version +// is returned in a form: . + +int main() { + default_selector selector; + device dev(selector.select_device()); + auto ocl_version = dev.get_info(); + std::cout << ocl_version << std::endl; + const std::regex oclVersionRegex("[0-9]\\.[0-9]"); + if (!std::regex_match(ocl_version, oclVersionRegex)) { + std::cout << "Failed" << std::endl; + return 1; + } + std::cout << "Passed" << std::endl; + return 0; +} diff --git a/sycl/test/basic_tests/parallel_for_range.cpp b/sycl/test/basic_tests/parallel_for_range.cpp index cab6523a70d06..5100639638369 100644 --- a/sycl/test/basic_tests/parallel_for_range.cpp +++ b/sycl/test/basic_tests/parallel_for_range.cpp @@ -30,16 +30,18 @@ int main() { string_class DeviceVendorName = D.get_info(); auto DeviceType = D.get_info(); + const bool OCLBackend = D.get_platform().get_backend() == backend::opencl; string_class OCLVersionStr = D.get_info(); - const bool OCLBackend = (OCLVersionStr.find("OpenCL") != string_class::npos); - assert((!OCLBackend || (OCLVersionStr.size() >= 10)) && - "Unexpected device version string"); // strlen("OpenCL X.Y") - const char *OCLVersion = &OCLVersionStr[7]; // strlen("OpenCL ") + assert((OCLVersionStr.size() == 3) && "Unexpected device version string"); + assert(OCLVersionStr.find(".") != string_class::npos && + "Unexpected device version string"); + const char OCLVersionMajor = OCLVersionStr[0]; + const char OCLVersionMinor = OCLVersionStr[2]; // reqd_work_group_size is OpenCL specific. if (OCLBackend) { - if (OCLVersion[0] == '1' || - (OCLVersion[0] == '2' && OCLVersion[2] == '0')) { + if (OCLVersionMajor == '1' || + (OCLVersionMajor == '2' && OCLVersionMinor == '0')) { // parallel_for, (16, 16, 16) global, (8, 8, 8) local, reqd_wg_size(4, 4, // 4) // -> fail @@ -143,7 +145,7 @@ int main() { } } // if (OCLBackend) - if (!OCLBackend || (OCLVersion[0] == '1')) { + if (!OCLBackend || (OCLVersionMajor == '1')) { // OpenCL 1.x or non-OpenCL backends which behave like OpenCl 1.2 in SYCL. // CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and @@ -346,7 +348,7 @@ int main() { << std::endl; return 1; } - } else if (OCLBackend && (OCLVersion[0] == '2')) { + } else if (OCLBackend && (OCLVersionMajor == '2')) { // OpenCL 2.x // OpenCL 2.x: diff --git a/sycl/test/plugins/sycl-ls-gpu-opencl.cpp b/sycl/test/plugins/sycl-ls-gpu-opencl.cpp index 9172093380f79..4437e68c28335 100755 --- a/sycl/test/plugins/sycl-ls-gpu-opencl.cpp +++ b/sycl/test/plugins/sycl-ls-gpu-opencl.cpp @@ -3,8 +3,8 @@ // RUN: env SYCL_BE=PI_OPENCL sycl-ls --verbose >%t.opencl.out // RUN: FileCheck %s --check-prefixes=CHECK-GPU-BUILTIN,CHECK-GPU-CUSTOM --input-file %t.opencl.out -// CHECK-GPU-BUILTIN: gpu_selector(){{.*}}GPU : OpenCL -// CHECK-GPU-CUSTOM: custom_selector(gpu){{.*}}GPU : OpenCL +// CHECK-GPU-BUILTIN: gpu_selector(){{.*}}GPU : {{[0-9]\.[0-9]}} +// CHECK-GPU-CUSTOM: custom_selector(gpu){{.*}}GPU : {{[0-9]\.[0-9]}} //==-- sycl-ls-gpu-opencl.cpp - SYCL test for discovered/selected devices -===// // diff --git a/sycl/test/sub_group/broadcast.cpp b/sycl/test/sub_group/broadcast.cpp index 3dbba78387b2d..49df849c1baad 100644 --- a/sycl/test/sub_group/broadcast.cpp +++ b/sycl/test/sub_group/broadcast.cpp @@ -1,4 +1,3 @@ -// XFAIL: cpu // UNSUPPORTED: cuda // CUDA compilation and runtime do not yet support sub-groups. diff --git a/sycl/test/sub_group/broadcast_fp64.cpp b/sycl/test/sub_group/broadcast_fp64.cpp index 9652fa6b73f46..f9f87e8f95fd9 100644 --- a/sycl/test/sub_group/broadcast_fp64.cpp +++ b/sycl/test/sub_group/broadcast_fp64.cpp @@ -1,4 +1,3 @@ -// XFAIL: cpu // UNSUPPORTED: cuda // CUDA compilation and runtime do not yet support sub-groups.