Skip to content

Commit 5b183b4

Browse files
authored
[SYCL] Throw right errc for work_group_size query (#8645)
clGetKernelWorkGroupInfo returns CL_INVALID_VALUE if param_name is CL_KERNEL_GLOBAL_WORK_SIZE and device is not a custom device and kernel is not a built-in kernel. According to SYCL2020 an exception with the errc::invalid error code should be thrown.
1 parent 30c8062 commit 5b183b4

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ set(SYCL_SOURCES
168168
"detail/device_global_map.cpp"
169169
"detail/device_global_map_entry.cpp"
170170
"detail/device_impl.cpp"
171-
"detail/error_handling/enqueue_kernel.cpp"
171+
"detail/error_handling/error_handling.cpp"
172172
"detail/event_impl.cpp"
173173
"detail/filter_selector_impl.cpp"
174174
"detail/fusion/fusion_wrapper.cpp"

sycl/source/detail/error_handling/enqueue_kernel.cpp renamed to sycl/source/detail/error_handling/error_handling.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,28 @@ void handleErrorOrWarning(pi_result Error, const device_impl &DeviceImpl,
360360
}
361361

362362
} // namespace detail::enqueue_kernel_launch
363+
364+
namespace detail::kernel_get_group_info {
365+
void handleErrorOrWarning(pi_result Error, pi_kernel_group_info Descriptor,
366+
const plugin &Plugin) {
367+
assert(Error != PI_SUCCESS &&
368+
"Success is expected to be handled on caller side");
369+
switch (Error) {
370+
case PI_ERROR_INVALID_VALUE:
371+
if (Descriptor == CL_KERNEL_GLOBAL_WORK_SIZE)
372+
throw sycl::exception(
373+
sycl::make_error_code(errc::invalid),
374+
"info::kernel_device_specific::global_work_size descriptor may only "
375+
"be used if the device type is device_type::custom or if the kernel "
376+
"is a built-in kernel.");
377+
break;
378+
// TODO: Handle other error codes
379+
default:
380+
Plugin.checkPiResult(Error);
381+
break;
382+
}
383+
}
384+
} // namespace detail::kernel_get_group_info
385+
363386
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
364387
} // namespace sycl

sycl/source/detail/error_handling/error_handling.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ void handleErrorOrWarning(pi_result, const device_impl &, pi_kernel,
2929
const NDRDescT &);
3030
} // namespace enqueue_kernel_launch
3131

32+
namespace kernel_get_group_info {
33+
/// Analyzes error code of piKernelGetGroupInfo.
34+
void handleErrorOrWarning(pi_result, pi_kernel_group_info, const plugin &);
35+
} // namespace kernel_get_group_info
36+
3237
} // namespace detail
3338
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
3439
} // namespace sycl

sycl/source/detail/kernel_info.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <detail/error_handling/error_handling.hpp>
1112
#include <sycl/detail/common.hpp>
1213
#include <sycl/detail/common_info.hpp>
1314
#include <sycl/detail/info_desc_helpers.hpp>
@@ -71,8 +72,11 @@ typename std::enable_if<!IsSubGroupInfo<Param>::value>::type
7172
get_kernel_device_specific_info_helper(RT::PiKernel Kernel, RT::PiDevice Device,
7273
const plugin &Plugin, void *Result,
7374
size_t Size) {
74-
Plugin.call<PiApiKind::piKernelGetGroupInfo>(
75+
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piKernelGetGroupInfo>(
7576
Kernel, Device, PiInfoCode<Param>::value, Size, Result, nullptr);
77+
if (Error != PI_SUCCESS)
78+
kernel_get_group_info::handleErrorOrWarning(Error, PiInfoCode<Param>::value,
79+
Plugin);
7680
}
7781

7882
template <typename Param>

0 commit comments

Comments
 (0)