From 8aafdab6a7257ccbe686966d95c81ef3dafbe237 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 16 Dec 2021 12:31:16 +0300 Subject: [PATCH 1/8] [SYCL] Adds regression test for reduction resource leak Select variants of reductions currently leak additional resources, such as auxiliary buffers. This commit adds a regression test to ensure this leak does not resurface. Signed-off-by: Steffen Larsen --- SYCL/Regression/reduction_resource_leak.cpp | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SYCL/Regression/reduction_resource_leak.cpp diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak.cpp new file mode 100644 index 0000000000..995f811258 --- /dev/null +++ b/SYCL/Regression/reduction_resource_leak.cpp @@ -0,0 +1,29 @@ +// REQUIRES: level_zero +// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not %s "LEAK" + +// Tests that additional resources required by discard_write reductions od not +// leak. + +#include + +using namespace cl::sycl; + +int main() { + queue Q; + + nd_range<1> NDRange(range<1>{49 * 5}, range<1>{49}); + std::plus<> BOp; + + buffer OutBuf(1); + buffer InBuf(49 * 5); + Q.submit([&](handler &CGH) { + auto In = InBuf.get_access(CGH); + auto Out = OutBuf.get_access(CGH); + auto Redu = ext::oneapi::reduction(Out, 0, BOp); + CGH.parallel_for( + NDRange, Redu, [=](nd_item<1> NDIt, auto &Sum) { + Sum.combine(In[NDIt.get_global_linear_id()]); + }); + }); + return 0; +} From 3c6979e6b4a194afd1065187c4bcd0bc0bdc6ab9 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 16 Dec 2021 17:46:48 +0300 Subject: [PATCH 2/8] Add the build command Signed-off-by: Steffen Larsen --- SYCL/Regression/reduction_resource_leak.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak.cpp index 995f811258..b73300303e 100644 --- a/SYCL/Regression/reduction_resource_leak.cpp +++ b/SYCL/Regression/reduction_resource_leak.cpp @@ -1,4 +1,5 @@ // REQUIRES: level_zero +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not %s "LEAK" // Tests that additional resources required by discard_write reductions od not From 3e1478017c38107b4c4bea302ba481cd4fbfd49b Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 16 Dec 2021 19:03:08 +0300 Subject: [PATCH 3/8] Fix check placement Signed-off-by: Steffen Larsen --- SYCL/Regression/reduction_resource_leak.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak.cpp index b73300303e..6025f01bea 100644 --- a/SYCL/Regression/reduction_resource_leak.cpp +++ b/SYCL/Regression/reduction_resource_leak.cpp @@ -1,6 +1,6 @@ // REQUIRES: level_zero // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not %s "LEAK" +// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not "LEAK" %s // Tests that additional resources required by discard_write reductions od not // leak. From 0a1828c1ea1095ee9880bf6aa74c2364dc57e4c6 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 20 Dec 2021 08:47:34 +0100 Subject: [PATCH 4/8] Fix typo Co-authored-by: Romanov Vlad --- SYCL/Regression/reduction_resource_leak.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak.cpp index 6025f01bea..efc4077c6e 100644 --- a/SYCL/Regression/reduction_resource_leak.cpp +++ b/SYCL/Regression/reduction_resource_leak.cpp @@ -2,7 +2,7 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not "LEAK" %s -// Tests that additional resources required by discard_write reductions od not +// Tests that additional resources required by discard_write reductions do not // leak. #include From b0a4e76ab2cd26c535ca4ff73ed29902aba6b9f8 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Thu, 17 Mar 2022 13:17:23 +0300 Subject: [PATCH 5/8] Attempted fix to test run --- SYCL/Regression/reduction_resource_leak.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak.cpp index efc4077c6e..27de503bc7 100644 --- a/SYCL/Regression/reduction_resource_leak.cpp +++ b/SYCL/Regression/reduction_resource_leak.cpp @@ -1,6 +1,8 @@ -// REQUIRES: level_zero -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --implicit-check-not "LEAK" %s +// REQUIRES: level_zero, level_zero_dev_kit +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %level_zero_options %s -o %t.out +// RUN: env SYCL_DEVICE_FILTER=level_zero ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER +// +// CHECK-NOT: LEAK // Tests that additional resources required by discard_write reductions do not // leak. From f5bdd8ca93748af844583c67e076cd685c1b2e24 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 21 Mar 2022 14:58:15 +0300 Subject: [PATCH 6/8] Add USM test case Signed-off-by: Steffen Larsen --- ...eak.cpp => reduction_resource_leak_dw.cpp} | 0 .../reduction_resource_leak_usm.cpp | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+) rename SYCL/Regression/{reduction_resource_leak.cpp => reduction_resource_leak_dw.cpp} (100%) create mode 100644 SYCL/Regression/reduction_resource_leak_usm.cpp diff --git a/SYCL/Regression/reduction_resource_leak.cpp b/SYCL/Regression/reduction_resource_leak_dw.cpp similarity index 100% rename from SYCL/Regression/reduction_resource_leak.cpp rename to SYCL/Regression/reduction_resource_leak_dw.cpp diff --git a/SYCL/Regression/reduction_resource_leak_usm.cpp b/SYCL/Regression/reduction_resource_leak_usm.cpp new file mode 100644 index 0000000000..ddeacadcfc --- /dev/null +++ b/SYCL/Regression/reduction_resource_leak_usm.cpp @@ -0,0 +1,31 @@ +// REQUIRES: level_zero, level_zero_dev_kit +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %level_zero_options %s -o %t.out +// RUN: env SYCL_DEVICE_FILTER=level_zero ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER +// +// CHECK-NOT: LEAK + +// Tests that additional resources required by USM reductions do not leak. + +#include + +using namespace cl::sycl; + +int main() { + queue Q; + device Dev = Q.get_device(); + context Ctx = Q.get_context(); + + nd_range<1> NDRange(range<1>{49 * 5}, range<1>{49}); + std::plus<> BOp; + + int *Out = malloc_shared(1, Dev, Ctx); + int *In = malloc_shared(49 * 5, Dev, Ctx); + Q.submit([&](handler &CGH) { + auto Redu = ext::oneapi::reduction(Out, 0, BOp); + CGH.parallel_for( + NDRange, Redu, [=](nd_item<1> NDIt, auto &Sum) { + Sum.combine(In[NDIt.get_global_linear_id()]); + }); + }).wait(); + return 0; +} From ee494694f80cbe12b5883bb75d6de926c782b9b5 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 21 Mar 2022 15:07:41 +0300 Subject: [PATCH 7/8] Fix formatting Signed-off-by: Steffen Larsen --- SYCL/Regression/reduction_resource_leak_usm.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SYCL/Regression/reduction_resource_leak_usm.cpp b/SYCL/Regression/reduction_resource_leak_usm.cpp index ddeacadcfc..6d81345c85 100644 --- a/SYCL/Regression/reduction_resource_leak_usm.cpp +++ b/SYCL/Regression/reduction_resource_leak_usm.cpp @@ -21,11 +21,11 @@ int main() { int *Out = malloc_shared(1, Dev, Ctx); int *In = malloc_shared(49 * 5, Dev, Ctx); Q.submit([&](handler &CGH) { - auto Redu = ext::oneapi::reduction(Out, 0, BOp); - CGH.parallel_for( - NDRange, Redu, [=](nd_item<1> NDIt, auto &Sum) { - Sum.combine(In[NDIt.get_global_linear_id()]); - }); - }).wait(); + auto Redu = ext::oneapi::reduction(Out, 0, BOp); + CGH.parallel_for( + NDRange, Redu, [=](nd_item<1> NDIt, auto &Sum) { + Sum.combine(In[NDIt.get_global_linear_id()]); + }); + }).wait(); return 0; } From 72130d1f6826f691d5983811530cf8305befb526 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 21 Mar 2022 16:52:03 +0300 Subject: [PATCH 8/8] Fix top-level USM leak Signed-off-by: Steffen Larsen --- SYCL/Regression/reduction_resource_leak_usm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SYCL/Regression/reduction_resource_leak_usm.cpp b/SYCL/Regression/reduction_resource_leak_usm.cpp index 6d81345c85..e0d32fbc13 100644 --- a/SYCL/Regression/reduction_resource_leak_usm.cpp +++ b/SYCL/Regression/reduction_resource_leak_usm.cpp @@ -12,14 +12,12 @@ using namespace cl::sycl; int main() { queue Q; - device Dev = Q.get_device(); - context Ctx = Q.get_context(); nd_range<1> NDRange(range<1>{49 * 5}, range<1>{49}); std::plus<> BOp; - int *Out = malloc_shared(1, Dev, Ctx); - int *In = malloc_shared(49 * 5, Dev, Ctx); + int *Out = malloc_shared(1, Q); + int *In = malloc_shared(49 * 5, Q); Q.submit([&](handler &CGH) { auto Redu = ext::oneapi::reduction(Out, 0, BOp); CGH.parallel_for( @@ -27,5 +25,7 @@ int main() { Sum.combine(In[NDIt.get_global_linear_id()]); }); }).wait(); + sycl::free(In, Q); + sycl::free(Out, Q); return 0; }