From 04c5da2fd0ee33d3d8da332a6f8c9d13992fb061 Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Fri, 21 Feb 2025 18:47:50 +0100 Subject: [PATCH 1/4] Fixing memory corruption --- .../statistics/sliding_window1d.hpp | 30 +++++++++++++++---- dpnp/tests/test_usm_type.py | 3 -- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/dpnp/backend/extensions/statistics/sliding_window1d.hpp b/dpnp/backend/extensions/statistics/sliding_window1d.hpp index be9bd85f8faf..215370fc6bf1 100644 --- a/dpnp/backend/extensions/statistics/sliding_window1d.hpp +++ b/dpnp/backend/extensions/statistics/sliding_window1d.hpp @@ -574,9 +574,18 @@ void submit_sliding_window1d(const PaddedSpan &a, } auto *const out_ptr = out.begin(); - auto *const out_end = out.end(); - results.store(&out_ptr[glid], - [out_end](auto &&ptr) { return ptr < out_end; }); + // auto *const out_end = out.end(); + + auto y_start = glid; + auto y_stop = std::min(y_start + WorkPI*results.size_x(), out.size()); + int32_t i = 0; + for (uint32_t y = y_start; y < y_stop; y+=results.size_x()) + { + out_ptr[y] = results[i++]; + } + // due to excessive optimizations this code results in memory corruption + // results.store(&out_ptr[glid], + // [out_end](auto &&ptr) { return ptr < out_end; }); }); } @@ -635,9 +644,18 @@ void submit_sliding_window1d_small_kernel(const PaddedSpan &a, red); auto *const out_ptr = out.begin(); - auto *const out_end = out.end(); - results.store(&out_ptr[glid], - [out_end](auto &&ptr) { return ptr < out_end; }); + // auto *const out_end = out.end(); + + auto y_start = glid; + auto y_stop = std::min(y_start + WorkPI*results.size_x(), out.size()); + int32_t i = 0; + for (uint32_t y = y_start; y < y_stop; y+=results.size_x()) + { + out_ptr[y] = results[i++]; + } + // due to excessive optimizations this code results in memory corruption + // results.store(&out_ptr[glid], + // [out_end](auto &&ptr) { return ptr < out_end; }); }); } diff --git a/dpnp/tests/test_usm_type.py b/dpnp/tests/test_usm_type.py index 74fdd28d1272..213f618f187d 100644 --- a/dpnp/tests/test_usm_type.py +++ b/dpnp/tests/test_usm_type.py @@ -800,9 +800,6 @@ def test_1in_1out(func, data, usm_type): @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types) @pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types) def test_2in_1out(func, data1, data2, usm_type_x, usm_type_y): - if func == "correlate" and is_win_platform(): - pytest.skip("due to SAT-7693") - x = dp.array(data1, usm_type=usm_type_x) y = dp.array(data2, usm_type=usm_type_y) z = getattr(dp, func)(x, y) From edf8ef82ae22da3800313fb2321126dbe6fab70f Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Fri, 21 Feb 2025 20:12:28 +0100 Subject: [PATCH 2/4] pre-commit --- .../statistics/sliding_window1d.hpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dpnp/backend/extensions/statistics/sliding_window1d.hpp b/dpnp/backend/extensions/statistics/sliding_window1d.hpp index 215370fc6bf1..954752c71897 100644 --- a/dpnp/backend/extensions/statistics/sliding_window1d.hpp +++ b/dpnp/backend/extensions/statistics/sliding_window1d.hpp @@ -577,14 +577,14 @@ void submit_sliding_window1d(const PaddedSpan &a, // auto *const out_end = out.end(); auto y_start = glid; - auto y_stop = std::min(y_start + WorkPI*results.size_x(), out.size()); + auto y_stop = + std::min(y_start + WorkPI * results.size_x(), out.size()); int32_t i = 0; - for (uint32_t y = y_start; y < y_stop; y+=results.size_x()) - { + for (uint32_t y = y_start; y < y_stop; y += results.size_x()) { out_ptr[y] = results[i++]; } - // due to excessive optimizations this code results in memory corruption - // results.store(&out_ptr[glid], + // due to excessive optimizations this code results in memory + // corruption results.store(&out_ptr[glid], // [out_end](auto &&ptr) { return ptr < out_end; }); }); } @@ -647,14 +647,14 @@ void submit_sliding_window1d_small_kernel(const PaddedSpan &a, // auto *const out_end = out.end(); auto y_start = glid; - auto y_stop = std::min(y_start + WorkPI*results.size_x(), out.size()); + auto y_stop = + std::min(y_start + WorkPI * results.size_x(), out.size()); int32_t i = 0; - for (uint32_t y = y_start; y < y_stop; y+=results.size_x()) - { + for (uint32_t y = y_start; y < y_stop; y += results.size_x()) { out_ptr[y] = results[i++]; } - // due to excessive optimizations this code results in memory corruption - // results.store(&out_ptr[glid], + // due to excessive optimizations this code results in memory + // corruption results.store(&out_ptr[glid], // [out_end](auto &&ptr) { return ptr < out_end; }); }); } From c678bdec19584d84af1fd784c90d47d3bbe92b27 Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Tue, 25 Feb 2025 18:24:22 +0100 Subject: [PATCH 3/4] Update comment & small fixes --- dpnp/backend/extensions/statistics/sliding_window1d.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dpnp/backend/extensions/statistics/sliding_window1d.hpp b/dpnp/backend/extensions/statistics/sliding_window1d.hpp index 954752c71897..c06e74ba699c 100644 --- a/dpnp/backend/extensions/statistics/sliding_window1d.hpp +++ b/dpnp/backend/extensions/statistics/sliding_window1d.hpp @@ -436,7 +436,7 @@ class PaddedSpan : public Span using size_type = SizeT; PaddedSpan(T *const data, const SizeT size, const SizeT pad) - : Span(data, size), pad_(pad) + : Span(data, size), pad_(pad) { } @@ -579,11 +579,13 @@ void submit_sliding_window1d(const PaddedSpan &a, auto y_start = glid; auto y_stop = std::min(y_start + WorkPI * results.size_x(), out.size()); - int32_t i = 0; + uint32_t i = 0; for (uint32_t y = y_start; y < y_stop; y += results.size_x()) { out_ptr[y] = results[i++]; } - // due to excessive optimizations this code results in memory + // while the code itself seems to be valid, inside correlate + // kernel it results in memory corruption. Further investigation + // is needed. SAT-7693 // corruption results.store(&out_ptr[glid], // [out_end](auto &&ptr) { return ptr < out_end; }); }); From ad73d26c48e68d3fafb95338b1ab36fb34e3aab6 Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Tue, 25 Feb 2025 18:29:57 +0100 Subject: [PATCH 4/4] Update comment in second implementation --- dpnp/backend/extensions/statistics/sliding_window1d.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dpnp/backend/extensions/statistics/sliding_window1d.hpp b/dpnp/backend/extensions/statistics/sliding_window1d.hpp index c06e74ba699c..278fdaaa83c0 100644 --- a/dpnp/backend/extensions/statistics/sliding_window1d.hpp +++ b/dpnp/backend/extensions/statistics/sliding_window1d.hpp @@ -651,11 +651,13 @@ void submit_sliding_window1d_small_kernel(const PaddedSpan &a, auto y_start = glid; auto y_stop = std::min(y_start + WorkPI * results.size_x(), out.size()); - int32_t i = 0; + uint32_t i = 0; for (uint32_t y = y_start; y < y_stop; y += results.size_x()) { out_ptr[y] = results[i++]; } - // due to excessive optimizations this code results in memory + // while the code itself seems to be valid, inside correlate + // kernel it results in memory corruption. Further investigation + // is needed. SAT-7693 // corruption results.store(&out_ptr[glid], // [out_end](auto &&ptr) { return ptr < out_end; }); });