Skip to content

Commit e43c0a3

Browse files
author
Sergey Kanaev
committed
[NFC] [SYCL] Make code a bit cleaner when using DISABLE_SYCL_INSTRUMENTATION_METADATA
Signed-off-by: Sergey Kanaev <[email protected]>
1 parent b9f6926 commit e43c0a3

File tree

1 file changed

+50
-85
lines changed

1 file changed

+50
-85
lines changed

sycl/include/CL/sycl/queue.hpp

Lines changed: 50 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@
2222

2323
#include <utility>
2424

25+
// having _TWO_ mid-param #ifdefs makes the functions very difficult to read.
26+
// Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and
27+
// _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be
28+
// _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined,
29+
// these macros are #undef immediately.
30+
31+
// replace _CODELOCPARAM(&CodeLoc) with nothing
32+
// or : , const detail::code_location &CodeLoc =
33+
// detail::code_location::current()
34+
// replace _CODELOCARG(&CodeLoc) with nothing
35+
// or : const detail::code_location &CodeLoc = {}
36+
37+
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
38+
#define _CODELOCPARAM(a) \
39+
, const detail::code_location a = detail::code_location::current()
40+
41+
#define _CODELOCARG(a)
42+
#define _CODELOCFW(a) , a
43+
#else
44+
#define _CODELOCPARAM(a)
45+
46+
#define _CODELOCARG(a) const detail::code_location a = {}
47+
#define _CODELOCFW(a)
48+
#endif
49+
50+
// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc
51+
// or const KernelType &KernelFunc
52+
#ifdef __SYCL_NONCONST_FUNCTOR__
53+
#define _KERNELFUNCPARAM(a) KernelType a
54+
#else
55+
#define _KERNELFUNCPARAM(a) const KernelType &a
56+
#endif
57+
2558
__SYCL_INLINE_NAMESPACE(cl) {
2659
namespace sycl {
2760

@@ -184,15 +217,9 @@ class __SYCL_EXPORT queue {
184217
/// \return a SYCL event object for the submitted command group.
185218
template <typename T>
186219
event
187-
submit(T CGF
188-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
189-
,
190-
const detail::code_location &CodeLoc = detail::code_location::current()
191-
#endif
192-
) {
193-
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
194-
const detail::code_location &CodeLoc = {};
195-
#endif
220+
submit(T CGF _CODELOCPARAM(&CodeLoc)) {
221+
_CODELOCARG(&CodeLoc);
222+
196223
return submit_impl(CGF, CodeLoc);
197224
}
198225

@@ -209,15 +236,9 @@ class __SYCL_EXPORT queue {
209236
/// group is being enqueued on.
210237
template <typename T>
211238
event
212-
submit(T CGF, queue &SecondaryQueue
213-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
214-
,
215-
const detail::code_location &CodeLoc = detail::code_location::current()
216-
#endif
217-
) {
218-
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
219-
const detail::code_location &CodeLoc = {};
220-
#endif
239+
submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) {
240+
_CODELOCARG(&CodeLoc);
241+
221242
return submit_impl(CGF, SecondaryQueue, CodeLoc);
222243
}
223244

@@ -228,16 +249,8 @@ class __SYCL_EXPORT queue {
228249
/// \param CodeLoc is the code location of the submit call (default argument)
229250
/// \return a SYCL event object, which corresponds to the queue the command
230251
/// group is being enqueued on.
231-
event submit_barrier(
232-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
233-
const detail::code_location &CodeLoc = detail::code_location::current()
234-
#endif
235-
) {
236-
return submit([=](handler &CGH) { CGH.barrier(); }
237-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
238-
, CodeLoc
239-
#endif
240-
);
252+
event submit_barrier(_CODELOCPARAM(&CodeLoc)) {
253+
return submit([=](handler &CGH) { CGH.barrier(); } _CODELOCFW(CodeLoc));
241254
}
242255

243256
/// Prevents any commands submitted afterward to this queue from executing
@@ -249,33 +262,20 @@ class __SYCL_EXPORT queue {
249262
/// \param CodeLoc is the code location of the submit call (default argument)
250263
/// \return a SYCL event object, which corresponds to the queue the command
251264
/// group is being enqueued on.
252-
event submit_barrier(
253-
const vector_class<event> &WaitList
254-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
255-
,
256-
const detail::code_location &CodeLoc = detail::code_location::current()
257-
#endif
258-
) {
265+
event submit_barrier(const vector_class<event> &WaitList
266+
_CODELOCPARAM(&CodeLoc)) {
259267
return submit([=](handler &CGH) { CGH.barrier(WaitList); }
260-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
261-
, CodeLoc
262-
#endif
263-
);
268+
_CODELOCFW(CodeLoc));
264269
}
265270

266271
/// Performs a blocking wait for the completion of all enqueued tasks in the
267272
/// queue.
268273
///
269274
/// Synchronous errors will be reported through SYCL exceptions.
270275
/// @param CodeLoc is the code location of the submit call (default argument)
271-
void wait(
272-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
273-
const detail::code_location &CodeLoc = detail::code_location::current()
274-
#endif
275-
) {
276-
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
277-
const detail::code_location &CodeLoc = {};
278-
#endif
276+
void wait(_CODELOCPARAM(&CodeLoc)) {
277+
_CODELOCARG(&CodeLoc)
278+
279279
wait_proxy(CodeLoc);
280280
}
281281

@@ -287,14 +287,9 @@ class __SYCL_EXPORT queue {
287287
/// construction. If no async_handler was provided then asynchronous
288288
/// exceptions will be lost.
289289
/// @param CodeLoc is the code location of the submit call (default argument)
290-
void wait_and_throw(
291-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
292-
const detail::code_location &CodeLoc = detail::code_location::current()
293-
#endif
294-
) {
295-
#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA
296-
const detail::code_location &CodeLoc = {};
297-
#endif
290+
void wait_and_throw(_CODELOCPARAM(&CodeLoc)) {
291+
_CODELOCARG(&CodeLoc);
292+
298293
wait_and_throw_proxy(CodeLoc);
299294
}
300295

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

376-
// having _TWO_ mid-param #ifdefs makes the functions very difficult to read.
377-
// Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and
378-
// _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be
379-
// _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined,
380-
// these macros are #undef immediately.
381-
382-
// replace _CODELOCPARAM(&CodeLoc) with nothing
383-
// or : , const detail::code_location &CodeLoc =
384-
// detail::code_location::current()
385-
// replace _CODELOCARG(&CodeLoc) with nothing
386-
// or : const detail::code_location &CodeLoc = {}
387-
388-
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
389-
#define _CODELOCPARAM(a) \
390-
, const detail::code_location a = detail::code_location::current()
391-
392-
#define _CODELOCARG(a)
393-
#else
394-
#define _CODELOCPARAM(a)
395-
396-
#define _CODELOCARG(a) const detail::code_location a = {}
397-
#endif
398-
// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc
399-
// or const KernelType &KernelFunc
400-
#ifdef __SYCL_NONCONST_FUNCTOR__
401-
#define _KERNELFUNCPARAM(a) KernelType a
402-
#else
403-
#define _KERNELFUNCPARAM(a) const KernelType &a
404-
#endif
405-
406371
/// single_task version with a kernel represented as a lambda.
407372
///
408373
/// \param KernelFunc is the Kernel functor or lambda

0 commit comments

Comments
 (0)