Skip to content

Commit

Permalink
[oneDPL][sycl] changes in __dpl_sycl::submit - support setting depend…
Browse files Browse the repository at this point in the history
…encies as __dpl_sycl::__event or sycl::event or std:vector<sycl::event>
  • Loading branch information
MikeDvorskiy committed Nov 7, 2023
1 parent fafff3c commit f1b733d
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,44 +420,66 @@ class __event
{
sycl::event __m_event;
sycl::queue __m_queue;
bool __in_order = false;
bool __m_queue_synch;

public:
__event(sycl::event __e): __m_event(__e) {}
__event() {}

__event(sycl::queue __q): __m_queue(__q), __in_order(true) {}
__event(sycl::event __e = {}): __m_event(__e), __m_queue_synch(false) {}
__event(sycl::queue __q): __m_queue(__q), __m_queue_synch(true)
{
assert(__q.is_in_order());
}

void wait()
{
if(__in_order)
if(__m_queue_synch)
__m_queue.wait_and_throw();
else
__m_event.wait_and_throw();
}

bool has_event() const { return !__in_order; }
operator sycl::event() const
{
assert(has_event());
assert(!__m_queue_synch);
return __m_event;
}
};

template <typename _Body>
template <typename _Body, typename _DependencyInternal, typename _DependencyExternal>
auto
__submit(sycl::queue __queue, _Body __body, __event __e = {})
__submit_impl(sycl::queue __queue, _Body __body, bool __is_implicit_synch, const _DependencyInternal* __dep_int, const _DependencyExternal* __dep_ext)
{
if(__queue.is_in_order())
{
__queue.submit(__body);
if(__queue.is_in_order() || __is_implicit_synch)
{
__queue.submit([&](sycl::handler& __hdl) {
if(__dep_ext)
__hdl.depends_on(*__dep_ext);
__body(__hdl);
});
return __event(__queue);
}
}

return __event(__queue.submit([&](sycl::handler& __hdl) {
assert(!__is_implicit_synch);
if(__dep_ext)
__hdl.depends_on(*__dep_ext);
if(__dep_int)
__hdl.depends_on(*__dep_int);
__body(__hdl);
}));
}

return __event(__queue.submit([&](sycl::handler& __hdl) {
__hdl.depends_on(__e);
__body(__hdl);
}));
template <typename _Body>
auto
__submit(sycl::queue __queue, _Body __body)
{
return __submit_impl(__queue, __body, true);
}

template <typename _Body, typename _Dependency>
auto
__submit(sycl::queue __queue, _Body __body, const _Dependency& __dependency)
{
return __submit_impl(__queue, __body, false, &__dependency, NULL);
}

} // namespace __dpl_sycl
Expand Down

0 comments on commit f1b733d

Please sign in to comment.