Skip to content

Commit 531e18b

Browse files
[NFC][SYCL] Simplify usage of associateWithHandler (#6450)
After #1770 some uses of associateWithHandler have to be guarded by "#ifndef __SYCL_DEVICE_ONLY__" as the accessor's inheritance chain differs between host/device compilation. Put the burden of that into the handler's implementation instead of paying the price at uses.
1 parent 9825b96 commit 531e18b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

sycl/include/sycl/detail/handler_proxy.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ namespace detail {
2020

2121
class AccessorBaseHost;
2222

23+
#ifdef __SYCL_DEVICE_ONLY__
24+
// In device compilation accessor isn't inherited from AccessorBaseHost, so
25+
// can't detect by it. Since we don't expect it to be ever called in device
26+
// execution, just use blind void *.
27+
inline void associateWithHandler(handler &, void *, access::target) {}
28+
#else
2329
__SYCL_EXPORT void associateWithHandler(handler &, AccessorBaseHost *,
2430
access::target);
31+
#endif
2532
} // namespace detail
2633
} // namespace sycl
2734
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/oneapi/reduction.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,10 @@ class reduction_impl_algo<
563563
/// to keep the accessor alive until the command group finishes the work.
564564
/// This function does not do anything for USM reductions.
565565
void associateWithHandler(handler &CGH) {
566-
#ifndef __SYCL_DEVICE_ONLY__
567566
if (MRWAcc)
568567
CGH.associateWithHandler(MRWAcc.get(), access::target::device);
569568
else if (MDWAcc)
570569
CGH.associateWithHandler(MDWAcc.get(), access::target::device);
571-
#else
572-
(void)CGH;
573-
#endif
574570
}
575571

576572
/// Creates and returns a local accessor with the \p Size elements.

sycl/include/sycl/handler.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,15 @@ class __SYCL_EXPORT handler {
495495

496496
bool is_host() { return MIsHost; }
497497

498+
#ifdef __SYCL_DEVICE_ONLY__
499+
// In device compilation accessor isn't inherited from AccessorBaseHost, so
500+
// can't detect by it. Since we don't expect it to be ever called in device
501+
// execution, just use blind void *.
502+
void associateWithHandler(void *AccBase, access::target AccTarget);
503+
#else
498504
void associateWithHandler(detail::AccessorBaseHost *AccBase,
499505
access::target AccTarget);
506+
#endif
500507

501508
// Recursively calls itself until arguments pack is fully processed.
502509
// The version for regular(standard layout) argument.
@@ -1386,11 +1393,7 @@ class __SYCL_EXPORT handler {
13861393
void
13871394
require(accessor<DataT, Dims, AccMode, AccTarget, access::placeholder::true_t>
13881395
Acc) {
1389-
#ifndef __SYCL_DEVICE_ONLY__
13901396
associateWithHandler(&Acc, AccTarget);
1391-
#else
1392-
(void)Acc;
1393-
#endif
13941397
}
13951398

13961399
/// Registers event dependencies on this command group.
@@ -2667,9 +2670,11 @@ class __SYCL_EXPORT handler {
26672670
class Algorithm>
26682671
friend class ext::oneapi::detail::reduction_impl_algo;
26692672

2673+
#ifndef __SYCL_DEVICE_ONLY__
26702674
friend void detail::associateWithHandler(handler &,
26712675
detail::AccessorBaseHost *,
26722676
access::target);
2677+
#endif
26732678

26742679
friend class ::MockHandler;
26752680
friend class detail::queue_impl;

0 commit comments

Comments
 (0)