Skip to content

[SYCL] Throw for invalid global_work_size query #9072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sycl/source/detail/kernel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ inline context kernel_impl::get_info<info::kernel::context>() const {
template <typename Param>
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::device_type>() ==
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<Param>(Device);
}
Expand Down
38 changes: 28 additions & 10 deletions sycl/test-e2e/Basic/kernel_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,34 @@ int main() {
krn.get_info<info::kernel_device_specific::compile_num_sub_groups>(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::device_type>() ==
sycl::info::device_type::custom);
}
{
std::error_code Errc;
std::string ErrMsg = "";
bool IsExceptionThrown = false;
try {
krn.get_info<sycl::info::kernel_device_specific::global_work_size>(dev);
auto BuiltInIds = dev.get_info<info::device::built_in_kernel_ids>();
bool isBuiltInKernel = std::find(BuiltInIds.begin(), BuiltInIds.end(),
KernelID) != BuiltInIds.end();
bool isCustomDevice = dev.get_info<sycl::info::device::device_type>() ==
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<sycl::info::kernel_device_specific::global_work_size>(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.");
}
}