Skip to content

Commit c1a11f9

Browse files
author
Steffen Larsen
committed
[SYCL] Split invalid work-group size error handling
Signed-off-by: Steffen Larsen <[email protected]>
1 parent f41309b commit c1a11f9

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

sycl/source/detail/error_handling/enqueue_kernel.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace detail {
2121

2222
namespace enqueue_kernel_launch {
2323

24-
bool handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel,
25-
const NDRDescT &NDRDesc) {
24+
bool oclHandleInvalidWorkGroupSize(const device_impl &DeviceImpl,
25+
pi_kernel Kernel, const NDRDescT &NDRDesc) {
2626
const bool HasLocalSize = (NDRDesc.LocalSize[0] != 0);
2727

2828
const plugin &Plugin = DeviceImpl.getPlugin();
@@ -170,6 +170,46 @@ bool handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel,
170170
"OpenCL API failed. OpenCL API returns: " + codeToString(Error), Error);
171171
}
172172

173+
bool handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel,
174+
const NDRDescT &NDRDesc) {
175+
const bool HasLocalSize = (NDRDesc.LocalSize[0] != 0);
176+
177+
const plugin &Plugin = DeviceImpl.getPlugin();
178+
RT::PiDevice Device = DeviceImpl.getHandleRef();
179+
180+
if (HasLocalSize) {
181+
size_t MaxThreadsPerBlock[3] = {};
182+
Plugin.call<PiApiKind::piDeviceGetInfo>(
183+
Device, PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES, sizeof(MaxThreadsPerBlock),
184+
MaxThreadsPerBlock, nullptr);
185+
186+
for (size_t I = 0; I < 3; ++I) {
187+
if (MaxThreadsPerBlock[I] < NDRDesc.LocalSize[I]) {
188+
throw sycl::nd_range_error(
189+
"The number of work-items in each dimension of a work-group cannot "
190+
"exceed info::device::max_work_item_sizes which is {" +
191+
std::to_string(MaxThreadsPerBlock[0]) + ", " +
192+
std::to_string(MaxThreadsPerBlock[1]) + ", " +
193+
std::to_string(MaxThreadsPerBlock[2]) + "} for this device",
194+
PI_INVALID_WORK_GROUP_SIZE);
195+
}
196+
}
197+
}
198+
199+
// Backend specific invalid work group size handing
200+
// TODO: Find a better way to determine the backend
201+
std::string PlatformName =
202+
DeviceImpl.get_platform().get_info<info::platform::name>();
203+
if (PlatformName.find("OpenCL") != std::string::npos) {
204+
return oclHandleInvalidWorkGroupSize(DeviceImpl, Kernel, NDRDesc);
205+
}
206+
207+
// Fallback
208+
constexpr pi_result Error = PI_INVALID_WORK_GROUP_SIZE;
209+
throw runtime_error(
210+
"PI backend failed. PI backend returns: " + codeToString(Error), Error);
211+
}
212+
173213
bool handleError(pi_result Error, const device_impl &DeviceImpl,
174214
pi_kernel Kernel, const NDRDescT &NDRDesc) {
175215
assert(Error != PI_SUCCESS &&

0 commit comments

Comments
 (0)