From d196c7369a157fd09a5779e2bf262e0588984572 Mon Sep 17 00:00:00 2001 From: Ewan Crawford Date: Fri, 6 Dec 2024 17:10:56 +0000 Subject: [PATCH 1/2] [SYCL][Graph] Regression Test for in-order queue submission --- .../in_order_queue_event_dependency.cpp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp diff --git a/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp b/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp new file mode 100644 index 0000000000000..51df0a5377e5e --- /dev/null +++ b/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp @@ -0,0 +1,61 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +// Extra run to check for leaks in Level Zero using UR_L0_LEAKS_DEBUG +// RUN: %if level_zero %{env SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=0 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %} +// Extra run to check for immediate-command-list in Level Zero +// RUN: %if level_zero %{env SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=1 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %} + +#include "../graph_common.hpp" + +#include + +int main() { + queue Queue1{sycl::property::queue::in_order{}}; + queue Queue2(Queue1.get_context(), Queue1.get_device(), + sycl::property::queue::in_order()); + exp_ext::command_graph Graph{Queue1}; + + std::vector Data(Size, 0.0f); + + float *DevicePtr = sycl::malloc_device(Size, Queue1); + + Graph.begin_recording(Queue1); + + Queue1.submit([&](handler &CGH) { + CGH.memcpy(DevicePtr, Data.data(), Size * sizeof(float)); + }); + + Queue1.submit([&](handler &CGH) { + CGH.parallel_for(sycl::range<1>(Size), + [=](sycl::id<1> Id) { DevicePtr[Id] += 1.0f; }); + }); + + Graph.end_recording(Queue1); + + auto GraphExec = Graph.finalize(); + + auto Event = Queue1.ext_oneapi_graph(GraphExec); + + Queue2.submit([&](sycl::handler &CGH) { +#if 1 // Setting to zero hides the fail + CGH.depends_on({Event}); +#endif + +#if 1 // Fail only appears with host-task + CGH.host_task([=]() { volatile float b = 3.0; }); +#else + CGH.parallel_for(sycl::range<1>(Size), + [=](sycl::id<1> Id) { DevicePtr[Id] += 0.0f; }); +#endif + }); + + std::vector HostData(Size, 0.0f); + Queue1.memcpy(HostData.data(), DevicePtr, Size * sizeof(float)).wait(); + for (size_t i = 0; i < Size; ++i) { + assert(HostData[i] == 1.0f); + } + + sycl::free(DevicePtr, Queue1); + + return 0; +} From 30e121ef3f29d9ead92f5f45146006fc73677084 Mon Sep 17 00:00:00 2001 From: Ben Tracy Date: Tue, 14 Jan 2025 13:09:10 +0000 Subject: [PATCH 2/2] Modify test to remove assert and return failure on incorrect results --- .../in_order_queue_event_dependency.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp b/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp index 51df0a5377e5e..a22061749a807 100644 --- a/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp +++ b/sycl/test-e2e/Graph/RecordReplay/in_order_queue_event_dependency.cpp @@ -15,7 +15,7 @@ int main() { sycl::property::queue::in_order()); exp_ext::command_graph Graph{Queue1}; - std::vector Data(Size, 0.0f); + std::vector Data(Size, 1.0f); float *DevicePtr = sycl::malloc_device(Size, Queue1); @@ -49,13 +49,18 @@ int main() { #endif }); - std::vector HostData(Size, 0.0f); + std::vector HostData(Size, 7.0f); Queue1.memcpy(HostData.data(), DevicePtr, Size * sizeof(float)).wait(); + bool IncorrectResult = false; for (size_t i = 0; i < Size; ++i) { - assert(HostData[i] == 1.0f); + IncorrectResult |= !(HostData[i] == 2.0f); + if (IncorrectResult) + { + std::cout << "INCORRECT RESULT DETECTED! Value at " << i << " was " << HostData[i] << std::endl; } - + } + sycl::free(DevicePtr, Queue1); - return 0; + return IncorrectResult; }