diff --git a/sycl/source/detail/kernel_impl.hpp b/sycl/source/detail/kernel_impl.hpp index beb59234e415f..a4436800918b4 100644 --- a/sycl/source/detail/kernel_impl.hpp +++ b/sycl/source/detail/kernel_impl.hpp @@ -214,6 +214,18 @@ inline context kernel_impl::get_info() const { template inline typename Param::return_type kernel_impl::get_info(const device &Device) const { + if constexpr (std::is_same_v< + Param, info::kernel_device_specific::global_work_size>) { + bool isDeviceCustom = Device.get_info() == + info::device_type::custom; + if (!isDeviceCustom && !isBuiltInKernel(Device)) + throw exception( + sycl::make_error_code(errc::invalid), + "info::kernel_device_specific::global_work_size descriptor may only " + "be used if the device type is device_type::custom or if the kernel " + "is a built-in kernel."); + } + if (is_host()) { return get_kernel_device_specific_info_host(Device); } diff --git a/sycl/test-e2e/Basic/kernel_info.cpp b/sycl/test-e2e/Basic/kernel_info.cpp index 936b8e866dc99..157181adda719 100644 --- a/sycl/test-e2e/Basic/kernel_info.cpp +++ b/sycl/test-e2e/Basic/kernel_info.cpp @@ -82,16 +82,34 @@ int main() { krn.get_info(dev); assert(compileNumSg <= maxNumSg); - try { - // To check (a) first if the kernel is device built-in, (b) then check if - // the device type is custom - if (!sycl::is_compatible({KernelID}, q.get_device())) { - assert(dev.get_info() == - sycl::info::device_type::custom); - } + { + std::error_code Errc; + std::string ErrMsg = ""; + bool IsExceptionThrown = false; + try { + krn.get_info(dev); + auto BuiltInIds = dev.get_info(); + bool isBuiltInKernel = std::find(BuiltInIds.begin(), BuiltInIds.end(), + KernelID) != BuiltInIds.end(); + bool isCustomDevice = dev.get_info() == + sycl::info::device_type::custom; + assert((isCustomDevice || isBuiltInKernel) && + "info::kernel_device_specific::global_work_size descriptor can " + "only be used with custom device " + "or built-in kernel."); - krn.get_info(dev); - } catch (sycl::exception &e) { - assert(e.code() == sycl::errc::invalid); + } catch (sycl::exception &e) { + IsExceptionThrown = true; + Errc = e.code(); + ErrMsg = e.what(); + } + assert(IsExceptionThrown && + "Invalid using of info::kernel_device_specific::global_work_size " + "query should throw an exception."); + assert(Errc == errc::invalid); + assert(ErrMsg == + "info::kernel_device_specific::global_work_size descriptor may only " + "be used if the device type is device_type::custom or if the " + "kernel is a built-in kernel."); } }