@@ -354,6 +354,32 @@ class __SYCL_EXPORT handler {
354
354
PI_ERROR_INVALID_OPERATION);
355
355
}
356
356
357
+ constexpr static int AccessTargetMask = 0x7ff ;
358
+ // / According to section 4.7.6.11. of the SYCL specification, a local accessor
359
+ // / must not be used in a SYCL kernel function that is invoked via single_task
360
+ // / or via the simple form of parallel_for that takes a range parameter.
361
+ template <typename KernelName, typename KernelType>
362
+ void throwOnLocalAccessorMisuse () const {
363
+ using NameT =
364
+ typename detail::get_kernel_name_t <KernelName, KernelType>::name;
365
+ using KI = sycl::detail::KernelInfo<NameT>;
366
+
367
+ auto *KernelArgs = &KI::getParamDesc (0 );
368
+
369
+ for (unsigned I = 0 ; I < KI::getNumParams (); ++I) {
370
+ const detail::kernel_param_kind_t &Kind = KernelArgs[I].kind ;
371
+ const access::target AccTarget =
372
+ static_cast <access::target>(KernelArgs[I].info & AccessTargetMask);
373
+ if ((Kind == detail::kernel_param_kind_t ::kind_accessor) &&
374
+ (AccTarget == target::local))
375
+ throw sycl::exception (
376
+ make_error_code (errc::kernel_argument),
377
+ " A local accessor must not be used in a SYCL kernel function "
378
+ " that is invoked via single_task or via the simple form of "
379
+ " parallel_for that takes a range parameter." );
380
+ }
381
+ }
382
+
357
383
// / Extracts and prepares kernel arguments from the lambda using integration
358
384
// / header.
359
385
void
@@ -906,6 +932,7 @@ class __SYCL_EXPORT handler {
906
932
void parallel_for_lambda_impl (range<Dims> NumWorkItems,
907
933
KernelType KernelFunc) {
908
934
throwIfActionIsCreated ();
935
+ throwOnLocalAccessorMisuse<KernelName, KernelType>();
909
936
using LambdaArgType = sycl::detail::lambda_arg_type<KernelType, item<Dims>>;
910
937
911
938
// If 1D kernel argument is an integral type, convert it to sycl::item<1>
@@ -1387,6 +1414,7 @@ class __SYCL_EXPORT handler {
1387
1414
ext::oneapi::experimental::detail::empty_properties_t >
1388
1415
void single_task_lambda_impl (_KERNELFUNCPARAM(KernelFunc)) {
1389
1416
throwIfActionIsCreated ();
1417
+ throwOnLocalAccessorMisuse<KernelName, KernelType>();
1390
1418
// TODO: Properties may change the kernel function, so in order to avoid
1391
1419
// conflicts they should be included in the name.
1392
1420
using NameT =
0 commit comments