Skip to content

Commit f1b733d

Browse files
committed
[oneDPL][sycl] changes in __dpl_sycl::submit - support setting dependencies as __dpl_sycl::__event or sycl::event or std:vector<sycl::event>
1 parent fafff3c commit f1b733d

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,44 +420,66 @@ class __event
420420
{
421421
sycl::event __m_event;
422422
sycl::queue __m_queue;
423-
bool __in_order = false;
423+
bool __m_queue_synch;
424424

425425
public:
426-
__event(sycl::event __e): __m_event(__e) {}
427-
__event() {}
428-
429-
__event(sycl::queue __q): __m_queue(__q), __in_order(true) {}
426+
__event(sycl::event __e = {}): __m_event(__e), __m_queue_synch(false) {}
427+
__event(sycl::queue __q): __m_queue(__q), __m_queue_synch(true)
428+
{
429+
assert(__q.is_in_order());
430+
}
430431

431432
void wait()
432433
{
433-
if(__in_order)
434+
if(__m_queue_synch)
434435
__m_queue.wait_and_throw();
435436
else
436437
__m_event.wait_and_throw();
437438
}
438439

439-
bool has_event() const { return !__in_order; }
440440
operator sycl::event() const
441441
{
442-
assert(has_event());
442+
assert(!__m_queue_synch);
443443
return __m_event;
444444
}
445445
};
446446

447-
template <typename _Body>
447+
template <typename _Body, typename _DependencyInternal, typename _DependencyExternal>
448448
auto
449-
__submit(sycl::queue __queue, _Body __body, __event __e = {})
449+
__submit_impl(sycl::queue __queue, _Body __body, bool __is_implicit_synch, const _DependencyInternal* __dep_int, const _DependencyExternal* __dep_ext)
450450
{
451-
if(__queue.is_in_order())
452-
{
453-
__queue.submit(__body);
451+
if(__queue.is_in_order() || __is_implicit_synch)
452+
{
453+
__queue.submit([&](sycl::handler& __hdl) {
454+
if(__dep_ext)
455+
__hdl.depends_on(*__dep_ext);
456+
__body(__hdl);
457+
});
454458
return __event(__queue);
455-
}
459+
}
460+
461+
return __event(__queue.submit([&](sycl::handler& __hdl) {
462+
assert(!__is_implicit_synch);
463+
if(__dep_ext)
464+
__hdl.depends_on(*__dep_ext);
465+
if(__dep_int)
466+
__hdl.depends_on(*__dep_int);
467+
__body(__hdl);
468+
}));
469+
}
456470

457-
return __event(__queue.submit([&](sycl::handler& __hdl) {
458-
__hdl.depends_on(__e);
459-
__body(__hdl);
460-
}));
471+
template <typename _Body>
472+
auto
473+
__submit(sycl::queue __queue, _Body __body)
474+
{
475+
return __submit_impl(__queue, __body, true);
476+
}
477+
478+
template <typename _Body, typename _Dependency>
479+
auto
480+
__submit(sycl::queue __queue, _Body __body, const _Dependency& __dependency)
481+
{
482+
return __submit_impl(__queue, __body, false, &__dependency, NULL);
461483
}
462484

463485
} // namespace __dpl_sycl

0 commit comments

Comments
 (0)