Skip to content

[NFC][SYCL] Simplify usage of associateWithHandler #6450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sycl/include/sycl/detail/handler_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ namespace detail {

class AccessorBaseHost;

#ifdef __SYCL_DEVICE_ONLY__
// In device compilation accessor isn't inherited from AccessorBaseHost, so
// can't detect by it. Since we don't expect it to be ever called in device
// execution, just use blind void *.
inline void associateWithHandler(handler &, void *, access::target) {}
#else
__SYCL_EXPORT void associateWithHandler(handler &, AccessorBaseHost *,
access::target);
#endif
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
4 changes: 0 additions & 4 deletions sycl/include/sycl/ext/oneapi/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,10 @@ class reduction_impl_algo<
/// to keep the accessor alive until the command group finishes the work.
/// This function does not do anything for USM reductions.
void associateWithHandler(handler &CGH) {
#ifndef __SYCL_DEVICE_ONLY__
if (MRWAcc)
CGH.associateWithHandler(MRWAcc.get(), access::target::device);
else if (MDWAcc)
CGH.associateWithHandler(MDWAcc.get(), access::target::device);
#else
(void)CGH;
#endif
}

/// Creates and returns a local accessor with the \p Size elements.
Expand Down
13 changes: 9 additions & 4 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,15 @@ class __SYCL_EXPORT handler {

bool is_host() { return MIsHost; }

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

// Recursively calls itself until arguments pack is fully processed.
// The version for regular(standard layout) argument.
Expand Down Expand Up @@ -1386,11 +1393,7 @@ class __SYCL_EXPORT handler {
void
require(accessor<DataT, Dims, AccMode, AccTarget, access::placeholder::true_t>
Acc) {
#ifndef __SYCL_DEVICE_ONLY__
associateWithHandler(&Acc, AccTarget);
#else
(void)Acc;
#endif
}

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

#ifndef __SYCL_DEVICE_ONLY__
friend void detail::associateWithHandler(handler &,
detail::AccessorBaseHost *,
access::target);
#endif

friend class ::MockHandler;
friend class detail::queue_impl;
Expand Down