Skip to content

Commit f85bc38

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

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

sycl/source/detail/error_handling/enqueue_kernel.cpp

Lines changed: 42 additions & 3 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,13 +170,52 @@ 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+
// Fallback
200+
constexpr pi_result Error = PI_INVALID_WORK_GROUP_SIZE;
201+
throw runtime_error(
202+
"PI backend failed. PI backend returns: " + codeToString(Error), Error);
203+
}
204+
173205
bool handleError(pi_result Error, const device_impl &DeviceImpl,
174206
pi_kernel Kernel, const NDRDescT &NDRDesc) {
175207
assert(Error != PI_SUCCESS &&
176208
"Success is expected to be handled on caller side");
177209
switch (Error) {
178-
case PI_INVALID_WORK_GROUP_SIZE:
210+
case PI_INVALID_WORK_GROUP_SIZE: {
211+
std::string PlatformName =
212+
DeviceImpl.get_platform().get_info<info::platform::name>();
213+
// TODO: Find a better way to determine the backend
214+
if (PlatformName.find("OpenCL") != std::string::npos) {
215+
return oclHandleInvalidWorkGroupSize(DeviceImpl, Kernel, NDRDesc);
216+
}
179217
return handleInvalidWorkGroupSize(DeviceImpl, Kernel, NDRDesc);
218+
}
180219
// TODO: Handle other error codes
181220
default:
182221
throw runtime_error(

0 commit comments

Comments
 (0)