@@ -21,8 +21,8 @@ namespace detail {
21
21
22
22
namespace enqueue_kernel_launch {
23
23
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) {
26
26
const bool HasLocalSize = (NDRDesc.LocalSize [0 ] != 0 );
27
27
28
28
const plugin &Plugin = DeviceImpl.getPlugin ();
@@ -170,6 +170,46 @@ bool handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel,
170
170
" OpenCL API failed. OpenCL API returns: " + codeToString (Error), Error);
171
171
}
172
172
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
+
173
213
bool handleError (pi_result Error, const device_impl &DeviceImpl,
174
214
pi_kernel Kernel, const NDRDescT &NDRDesc) {
175
215
assert (Error != PI_SUCCESS &&
0 commit comments