Skip to content

Commit 0db898c

Browse files
authored
[SYCLomatic] Use the new interface of sycl::queue::ext_oneapi_get_last_event() and keep the code can be built by both new and old oneAPI compiler (#2716)
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent 6ec8da4 commit 0db898c

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -6667,19 +6667,25 @@ KernelPrinter &KernelCallExpr::SubmitStmtsList::print(KernelPrinter &Printer) {
66676667
Printer.line("cgh.depends_on(dpct::get_current_device().get_in_order_"
66686668
"queues_last_events());");
66696669
} else {
6670-
Printer.line("#ifdef __INTEL_LLVM_COMPILER");
6671-
Printer.newLine();
6672-
Printer.line("cgh.depends_on(dpct::get_default_queue().ext_oneapi_get_"
6673-
"last_event());");
6674-
Printer.newLine();
6675-
Printer.line("#else");
6676-
Printer.newLine();
6677-
Printer.line("auto e_opt = dpct::get_default_queue().ext_oneapi_get_last_"
6678-
"event();");
6679-
Printer.newLine();
6680-
Printer.line("if (e_opt) cgh.depends_on(*e_opt);");
6681-
Printer.newLine();
6682-
Printer.line("#endif");
6670+
Printer.line("auto last_event = "
6671+
"dpct::get_default_queue().ext_oneapi_get_last_event();");
6672+
Printer.line("[&](auto &&_e) {");
6673+
{
6674+
Printer.indent();
6675+
Printer.line("if constexpr "
6676+
"(std::is_same_v<std::remove_reference_t<decltype(last_"
6677+
"event)>, sycl::event>)");
6678+
{
6679+
Printer.indent();
6680+
Printer.line("cgh.depends_on(_e);");
6681+
}
6682+
Printer.line("else if (_e.has_value())");
6683+
{
6684+
Printer.indent();
6685+
Printer.line("cgh.depends_on(_e.value());");
6686+
}
6687+
}
6688+
Printer.line("}(last_event);");
66836689
}
66846690
Printer.newLine();
66856691
}

clang/runtime/dpct-rt/include/dpct/device.hpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,15 @@ class device_ext : public sycl::device {
592592
lock.unlock();
593593
for (const auto &q : current_queues) {
594594
if (q->is_in_order()) {
595-
#ifdef __INTEL_LLVM_COMPILER
596-
last_events.push_back(q->ext_oneapi_get_last_event());
597-
#else
598595
auto last_event = q->ext_oneapi_get_last_event();
599-
if (last_event) {
600-
last_events.push_back(*last_event);
601-
}
602-
#endif
596+
[&](auto &&_e) {
597+
if constexpr (std::is_same_v<
598+
std::remove_reference_t<decltype(last_event)>,
599+
sycl::event>)
600+
last_events.push_back(_e);
601+
else if (_e.has_value())
602+
last_events.push_back(_e.value());
603+
}(last_event);
603604
}
604605
}
605606
// Guard the destruct of current_queues to make sure the ref count is safe.

clang/test/dpct/kernel_implicit_sync.cu

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ int main() {
2727

2828
// CHECK: s1->submit(
2929
// CHECK: [&](sycl::handler &cgh) {
30-
// CHECK:#ifdef __INTEL_LLVM_COMPILER
31-
// CHECK: cgh.depends_on(dpct::get_default_queue().ext_oneapi_get_last_event());
32-
// CHECK:#else
33-
// CHECK: auto e_opt = dpct::get_default_queue().ext_oneapi_get_last_event();
34-
// CHECK: if (e_opt) cgh.depends_on(*e_opt);
35-
// CHECK:#endif
30+
// CHECK: auto last_event = dpct::get_default_queue().ext_oneapi_get_last_event();
31+
// CHECK: [&](auto &&_e) {
32+
// CHECK: if constexpr (std::is_same_v<std::remove_reference_t<decltype(last_event)>, sycl::event>)
33+
// CHECK: cgh.depends_on(_e);
34+
// CHECK: else if (_e.has_value())
35+
// CHECK: cgh.depends_on(_e.value());
36+
// CHECK: }(last_event);
3637
// CHECK: cgh.parallel_for(
3738
// CHECK: sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
3839
// CHECK: [=](sycl::nd_item<3> item_ct1) {

0 commit comments

Comments
 (0)