From 4744b568ae1481c669ee0adca7308021902a703d Mon Sep 17 00:00:00 2001 From: Rafal Bielski Date: Tue, 7 Jan 2025 17:18:28 +0000 Subject: [PATCH 1/4] Add e2e test for queue::fill with a range of pattern sizes Add a new e2e test to validate queue::fill outputs for any pattern size between 1 and 32 bytes. Backend implementations of this feature commonly branch on the pattern size to implement an optimized path for specific values. This test ensures a wide range of cases is tested, including also odd numbers of bytes. --- sycl/test-e2e/USM/fill_any_size.cpp | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 sycl/test-e2e/USM/fill_any_size.cpp diff --git a/sycl/test-e2e/USM/fill_any_size.cpp b/sycl/test-e2e/USM/fill_any_size.cpp new file mode 100644 index 0000000000000..349d7bc0c82fc --- /dev/null +++ b/sycl/test-e2e/USM/fill_any_size.cpp @@ -0,0 +1,83 @@ +// RUN: %{build} -o %t1.out +// RUN: %{run} %t1.out +// UNSUPPORTED: (opencl && cpu) +// clang-format off +// UNSUPPORTED-TRACKER: https://github.com/oneapi-src/unified-runtime/issues/2440 +// clang-format on + +/** + * Test of the queue::fill interface with a range of pattern sizes and values. + * + * Loops over pattern sizes from 1 to MaxPatternSize bytes and calls queue::fill + * with std::array for the pattern. Two pattern values are tested, + * all zeros and value=index+42. The output is copied back to host and + * validated. + */ + +#include +#include +#include +#include + +constexpr size_t MaxPatternSize{32}; // Bytes. +constexpr size_t NumElements{10}; +constexpr size_t NumRepeats{1}; +constexpr bool verbose{false}; + +template +int test(sycl::queue &q, uint8_t firstValue = 0) { + using T = std::array; + T value{}; + for (size_t i{0}; i < PatternSize; ++i) { + if constexpr (SameValue) { + value[i] = firstValue; + } else { + value[i] = firstValue + i; + } + } + + T *dptr{sycl::malloc_device(NumElements, q)}; + for (size_t repeat{0}; repeat < NumRepeats; ++repeat) { + q.fill(dptr, value, NumElements).wait(); + } + + std::array host{}; + q.copy(dptr, host.data(), NumElements).wait(); + bool pass{true}; + for (size_t i{0}; i < NumElements; ++i) { + for (size_t j{0}; j < PatternSize; ++j) { + if (host[i][j] != value[j]) { + pass = false; + } + } + } + sycl::free(dptr, q); + + if (!pass || verbose) { + printf("Pattern size %3zu bytes, %s values (initial %3u) %s\n", PatternSize, + (SameValue ? " equal" : "varied"), firstValue, + (pass ? "== PASS ==" : "== FAIL ==")); + } + + return !pass; +} + +template int testOneSize(sycl::queue &q) { + return test(q, 0) + test(q, 42); +} + +template +int testSizes(sycl::queue &q, std::index_sequence) { + return (testOneSize<1u + Sizes>(q) + ...); +} + +int main() { + sycl::queue q{}; + int failures = testSizes(q, std::make_index_sequence{}); + if (failures > 0) { + printf("%d / %zu tests failed\n", failures, 2u * MaxPatternSize); + } else { + printf("All %zu tests passed\n", 2u * MaxPatternSize); + } + return failures; +} From f108690a371ab0f8c6aaeff41e798d1b9a547d02 Mon Sep 17 00:00:00 2001 From: Rafal Bielski Date: Tue, 7 Jan 2025 18:52:39 +0000 Subject: [PATCH 2/4] Remove redundant loop over NumRepeats=1 --- sycl/test-e2e/USM/fill_any_size.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sycl/test-e2e/USM/fill_any_size.cpp b/sycl/test-e2e/USM/fill_any_size.cpp index 349d7bc0c82fc..3b4527803ccec 100644 --- a/sycl/test-e2e/USM/fill_any_size.cpp +++ b/sycl/test-e2e/USM/fill_any_size.cpp @@ -21,7 +21,6 @@ constexpr size_t MaxPatternSize{32}; // Bytes. constexpr size_t NumElements{10}; -constexpr size_t NumRepeats{1}; constexpr bool verbose{false}; template @@ -37,9 +36,7 @@ int test(sycl::queue &q, uint8_t firstValue = 0) { } T *dptr{sycl::malloc_device(NumElements, q)}; - for (size_t repeat{0}; repeat < NumRepeats; ++repeat) { - q.fill(dptr, value, NumElements).wait(); - } + q.fill(dptr, value, NumElements).wait(); std::array host{}; q.copy(dptr, host.data(), NumElements).wait(); From 603dab98af6bb10190daf3e07c4e213190fd12df Mon Sep 17 00:00:00 2001 From: Rafal Bielski Date: Tue, 7 Jan 2025 19:04:12 +0000 Subject: [PATCH 3/4] Add comments explaining sections of the test function --- sycl/test-e2e/USM/fill_any_size.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sycl/test-e2e/USM/fill_any_size.cpp b/sycl/test-e2e/USM/fill_any_size.cpp index 3b4527803ccec..39dab02f4aa7d 100644 --- a/sycl/test-e2e/USM/fill_any_size.cpp +++ b/sycl/test-e2e/USM/fill_any_size.cpp @@ -27,6 +27,8 @@ template int test(sycl::queue &q, uint8_t firstValue = 0) { using T = std::array; T value{}; + + // Initialize the pattern value on host. for (size_t i{0}; i < PatternSize; ++i) { if constexpr (SameValue) { value[i] = firstValue; @@ -35,11 +37,17 @@ int test(sycl::queue &q, uint8_t firstValue = 0) { } } + // Allocate memory on the device. T *dptr{sycl::malloc_device(NumElements, q)}; + + // Fill the device memory with the pattern. q.fill(dptr, value, NumElements).wait(); + // Copy back the filled memory to host. std::array host{}; q.copy(dptr, host.data(), NumElements).wait(); + + // Validate whether the filled memory contains the expected values. bool pass{true}; for (size_t i{0}; i < NumElements; ++i) { for (size_t j{0}; j < PatternSize; ++j) { @@ -48,8 +56,11 @@ int test(sycl::queue &q, uint8_t firstValue = 0) { } } } + + // Release the device memory allocation. sycl::free(dptr, q); + // Print info on failure or in verbose mode. if (!pass || verbose) { printf("Pattern size %3zu bytes, %s values (initial %3u) %s\n", PatternSize, (SameValue ? " equal" : "varied"), firstValue, From 4c228960af0dc3e896f139ff89f7e2442460a307 Mon Sep 17 00:00:00 2001 From: Rafal Bielski Date: Wed, 8 Jan 2025 00:23:43 +0000 Subject: [PATCH 4/4] Fix UNSUPPORTED statements Move "clang-format: off" to ensure UNSUPPORTED-TRACKER follows directly after UNSUPPORTED Co-authored-by: Udit Kumar Agarwal --- sycl/test-e2e/USM/fill_any_size.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test-e2e/USM/fill_any_size.cpp b/sycl/test-e2e/USM/fill_any_size.cpp index 39dab02f4aa7d..101802324c225 100644 --- a/sycl/test-e2e/USM/fill_any_size.cpp +++ b/sycl/test-e2e/USM/fill_any_size.cpp @@ -1,7 +1,7 @@ // RUN: %{build} -o %t1.out // RUN: %{run} %t1.out -// UNSUPPORTED: (opencl && cpu) // clang-format off +// UNSUPPORTED: (opencl && cpu) // UNSUPPORTED-TRACKER: https://github.com/oneapi-src/unified-runtime/issues/2440 // clang-format on