Skip to content

[NFC] [SYCL] Make code a bit cleaner when using DISABLE_SYCL_INSTRUMENTATION_METADATA #3401

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 9 commits into from
Mar 26, 2021
Merged
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
145 changes: 56 additions & 89 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@

#include <utility>

// having _TWO_ mid-param #ifdefs makes the functions very difficult to read.
// Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and
// _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be
// _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined,
// these macros are #undef immediately.

// replace _CODELOCPARAM(&CodeLoc) with nothing
// or : , const detail::code_location &CodeLoc =
// detail::code_location::current()
// replace _CODELOCARG(&CodeLoc) with nothing
// or : const detail::code_location &CodeLoc = {}

#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
#define _CODELOCONLYPARAM(a) \
const detail::code_location a = detail::code_location::current()
#define _CODELOCPARAM(a) \
, const detail::code_location a = detail::code_location::current()

#define _CODELOCARG(a)
#define _CODELOCFW(a) , a
#else
#define _CODELOCONLYPARAM(a)
#define _CODELOCPARAM(a)

#define _CODELOCARG(a) const detail::code_location a = {}
#define _CODELOCFW(a)
#endif

// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc
// or const KernelType &KernelFunc
#ifdef __SYCL_NONCONST_FUNCTOR__
#define _KERNELFUNCPARAM(a) KernelType a
#else
#define _KERNELFUNCPARAM(a) const KernelType &a
#endif

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

Expand Down Expand Up @@ -182,17 +218,9 @@ class __SYCL_EXPORT queue {
/// \param CGF is a function object containing command group.
/// \param CodeLoc is the code location of the submit call (default argument)
/// \return a SYCL event object for the submitted command group.
template <typename T>
event
submit(T CGF
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
,
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = {};
#endif
template <typename T> event submit(T CGF _CODELOCPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc);

return submit_impl(CGF, CodeLoc);
}

Expand All @@ -208,16 +236,9 @@ class __SYCL_EXPORT queue {
/// \return a SYCL event object, which corresponds to the queue the command
/// group is being enqueued on.
template <typename T>
event
submit(T CGF, queue &SecondaryQueue
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
,
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = {};
#endif
event submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc);

return submit_impl(CGF, SecondaryQueue, CodeLoc);
}

Expand All @@ -228,16 +249,8 @@ class __SYCL_EXPORT queue {
/// \param CodeLoc is the code location of the submit call (default argument)
/// \return a SYCL event object, which corresponds to the queue the command
/// group is being enqueued on.
event submit_barrier(
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
return submit([=](handler &CGH) { CGH.barrier(); }
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
, CodeLoc
#endif
);
event submit_barrier(_CODELOCONLYPARAM(&CodeLoc)) {
return submit([=](handler &CGH) { CGH.barrier(); } _CODELOCFW(CodeLoc));
}

/// Prevents any commands submitted afterward to this queue from executing
Expand All @@ -249,33 +262,20 @@ class __SYCL_EXPORT queue {
/// \param CodeLoc is the code location of the submit call (default argument)
/// \return a SYCL event object, which corresponds to the queue the command
/// group is being enqueued on.
event submit_barrier(
const vector_class<event> &WaitList
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
,
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
return submit([=](handler &CGH) { CGH.barrier(WaitList); }
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
, CodeLoc
#endif
);
event
submit_barrier(const vector_class<event> &WaitList _CODELOCPARAM(&CodeLoc)) {
return submit(
[=](handler &CGH) { CGH.barrier(WaitList); } _CODELOCFW(CodeLoc));
}

/// Performs a blocking wait for the completion of all enqueued tasks in the
/// queue.
///
/// Synchronous errors will be reported through SYCL exceptions.
/// @param CodeLoc is the code location of the submit call (default argument)
void wait(
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = {};
#endif
void wait(_CODELOCONLYPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc)

wait_proxy(CodeLoc);
}

Expand All @@ -287,14 +287,9 @@ class __SYCL_EXPORT queue {
/// construction. If no async_handler was provided then asynchronous
/// exceptions will be lost.
/// @param CodeLoc is the code location of the submit call (default argument)
void wait_and_throw(
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = detail::code_location::current()
#endif
) {
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
const detail::code_location &CodeLoc = {};
#endif
void wait_and_throw(_CODELOCONLYPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc);

wait_and_throw_proxy(CodeLoc);
}

Expand Down Expand Up @@ -373,36 +368,6 @@ class __SYCL_EXPORT queue {
return submit([=](handler &CGH) { CGH.prefetch(Ptr, Count); });
}

// having _TWO_ mid-param #ifdefs makes the functions very difficult to read.
// Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and
// _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be
// _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined,
// these macros are #undef immediately.

// replace _CODELOCPARAM(&CodeLoc) with nothing
// or : , const detail::code_location &CodeLoc =
// detail::code_location::current()
// replace _CODELOCARG(&CodeLoc) with nothing
// or : const detail::code_location &CodeLoc = {}

#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
#define _CODELOCPARAM(a) \
, const detail::code_location a = detail::code_location::current()

#define _CODELOCARG(a)
#else
#define _CODELOCPARAM(a)

#define _CODELOCARG(a) const detail::code_location a = {}
#endif
// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc
// or const KernelType &KernelFunc
#ifdef __SYCL_NONCONST_FUNCTOR__
#define _KERNELFUNCPARAM(a) KernelType a
#else
#define _KERNELFUNCPARAM(a) const KernelType &a
#endif

/// single_task version with a kernel represented as a lambda.
///
/// \param KernelFunc is the Kernel functor or lambda
Expand Down Expand Up @@ -744,7 +709,9 @@ class __SYCL_EXPORT queue {

// Clean up CODELOC and KERNELFUNC macros.
#undef _CODELOCPARAM
#undef _CODELOCONLYPARAM
#undef _CODELOCARG
#undef _CODELOCFW
#undef _KERNELFUNCPARAM

/// Returns whether the queue is in order or OoO
Expand Down