From 8d247bb64f128543270457abc040b3aea778743a Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 22 Nov 2024 15:49:26 -0800 Subject: [PATCH 1/4] [E2E][SYCL] Test for empty command group behavior We currently have a bug here and ignore some required dependencies. That will be addressed in a separate functional PR. --- sycl/test-e2e/Basic/empty_command.cpp | 120 ++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 sycl/test-e2e/Basic/empty_command.cpp diff --git a/sycl/test-e2e/Basic/empty_command.cpp b/sycl/test-e2e/Basic/empty_command.cpp new file mode 100644 index 0000000000000..bca60b419e089 --- /dev/null +++ b/sycl/test-e2e/Basic/empty_command.cpp @@ -0,0 +1,120 @@ +// RUN: %{build} -o %t.out %cxx_std_optionc++20 +// RUN: %{run} %t.out + +#include + +#include +#include + +using namespace sycl; + +void test_host_task_dep() { + queue q; + + std::latch start_execution{1}; + + int x = 0; + + auto host_event = q.submit([&](handler &cgh) { + cgh.host_task([&]() { + start_execution.wait(); + x = 42; + }); + }); + + auto empty_cg_event = + q.submit([&](handler &cgh) { cgh.depends_on(host_event); }); + + // FIXME: This should deadlock, but the dependency is ignored currently. + empty_cg_event.wait(); + + assert(x == 0); + start_execution.count_down(); + + empty_cg_event.wait(); + // FIXME: uncomment once the bug mentioned above is fixed. + // assert(x == 42); + + // I'm seeing some weird hang without this: + host_event.wait(); +} + +void test_device_event_dep() { + queue q; + + std::latch start_execution{1}; + auto *p = sycl::malloc_shared(1, q); + *p = 0; + + auto host_event = q.submit([&](handler &cgh) { + cgh.host_task([&]() { + start_execution.wait(); + }); + }); + auto device_event = q.single_task(host_event, [=]() { *p = 42; }); + auto empty_cg_event = + q.submit([&](handler &cgh) { cgh.depends_on(device_event); }); + + // FIXME: This should deadlock, but the dependency is ignored currently. + empty_cg_event.wait(); + + assert(*p == 0); + start_execution.count_down(); + + empty_cg_event.wait(); + // FIXME: uncomment once the bug mentioned above is fixed. + // assert(*p == 42); + + q.wait(); + sycl::free(p, q); +} + +void test_accessor_dep() { + queue q; + + std::latch start_execution{1}; + auto *p = sycl::malloc_shared(1, q); + *p = 0; + + auto host_event = q.submit([&](handler &cgh) { + cgh.host_task([&]() { + start_execution.wait(); + }); + }); + + sycl::buffer b{1}; + auto device_event = q.submit([&](auto &cgh) { + cgh.depends_on(host_event); + sycl::accessor a{b, cgh}; + + cgh.single_task([=]() { + *p = 42; + a[0] = 42; + }); + }); + auto empty_cg_event = q.submit([&](handler &cgh) { + sycl::accessor a{b}; + // TODO: Clarify with spec people that it should create a dependency indeed. + cgh.require(a); + }); + + // FIXME: This should deadlock, but the dependency is ignored currently. + empty_cg_event.wait(); + + assert(*p == 0); + start_execution.count_down(); + + empty_cg_event.wait(); + // FIXME: uncomment once the bug mentioned above is fixed. + // assert(*p == 42); + + q.wait(); + sycl::free(p, q); +} + +int main() { + test_host_task_dep(); + test_device_event_dep(); + test_accessor_dep(); + return 0; +} From a6e672a35eeb519735a1d2b5971c16750bfaec09 Mon Sep 17 00:00:00 2001 From: aelovikov-intel Date: Sun, 24 Nov 2024 20:36:26 -0800 Subject: [PATCH 2/4] Update sycl/test-e2e/Basic/empty_command.cpp --- sycl/test-e2e/Basic/empty_command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test-e2e/Basic/empty_command.cpp b/sycl/test-e2e/Basic/empty_command.cpp index bca60b419e089..eeb2c994382ee 100644 --- a/sycl/test-e2e/Basic/empty_command.cpp +++ b/sycl/test-e2e/Basic/empty_command.cpp @@ -1,7 +1,7 @@ // RUN: %{build} -o %t.out %cxx_std_optionc++20 // RUN: %{run} %t.out -#include +#include #include #include From e10e6de8fad1f68e08eac26c6bcd798582cf07dc Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Mon, 25 Nov 2024 07:08:23 -0800 Subject: [PATCH 3/4] clang-format and usm include --- sycl/test-e2e/Basic/empty_command.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sycl/test-e2e/Basic/empty_command.cpp b/sycl/test-e2e/Basic/empty_command.cpp index eeb2c994382ee..e365a57db7364 100644 --- a/sycl/test-e2e/Basic/empty_command.cpp +++ b/sycl/test-e2e/Basic/empty_command.cpp @@ -2,6 +2,7 @@ // RUN: %{run} %t.out #include +#include #include #include @@ -46,11 +47,8 @@ void test_device_event_dep() { auto *p = sycl::malloc_shared(1, q); *p = 0; - auto host_event = q.submit([&](handler &cgh) { - cgh.host_task([&]() { - start_execution.wait(); - }); - }); + auto host_event = q.submit( + [&](handler &cgh) { cgh.host_task([&]() { start_execution.wait(); }); }); auto device_event = q.single_task(host_event, [=]() { *p = 42; }); auto empty_cg_event = q.submit([&](handler &cgh) { cgh.depends_on(device_event); }); @@ -76,11 +74,8 @@ void test_accessor_dep() { auto *p = sycl::malloc_shared(1, q); *p = 0; - auto host_event = q.submit([&](handler &cgh) { - cgh.host_task([&]() { - start_execution.wait(); - }); - }); + auto host_event = q.submit( + [&](handler &cgh) { cgh.host_task([&]() { start_execution.wait(); }); }); sycl::buffer b{1}; auto device_event = q.submit([&](auto &cgh) { From f3add79beeaef14d04b367ede6c1f20069646a7c Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Mon, 25 Nov 2024 07:09:08 -0800 Subject: [PATCH 4/4] Simplify accessor/remove TODO --- sycl/test-e2e/Basic/empty_command.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sycl/test-e2e/Basic/empty_command.cpp b/sycl/test-e2e/Basic/empty_command.cpp index e365a57db7364..313ca81743c36 100644 --- a/sycl/test-e2e/Basic/empty_command.cpp +++ b/sycl/test-e2e/Basic/empty_command.cpp @@ -87,11 +87,8 @@ void test_accessor_dep() { a[0] = 42; }); }); - auto empty_cg_event = q.submit([&](handler &cgh) { - sycl::accessor a{b}; - // TODO: Clarify with spec people that it should create a dependency indeed. - cgh.require(a); - }); + auto empty_cg_event = + q.submit([&](handler &cgh) { sycl::accessor a{b, cgh}; }); // FIXME: This should deadlock, but the dependency is ignored currently. empty_cg_event.wait();