diff --git a/sycl/test-e2e/bindless_images/bindless_helpers.hpp b/sycl/test-e2e/bindless_images/bindless_helpers.hpp index 29770196ff2d0..bf088db4e9e80 100644 --- a/sycl/test-e2e/bindless_images/bindless_helpers.hpp +++ b/sycl/test-e2e/bindless_images/bindless_helpers.hpp @@ -2,11 +2,48 @@ #include #include +template +std::ostream &operator<<(std::ostream &os, + const sycl::vec &vec) { + std::string str{""}; + for (int i = 0; i < NChannels; ++i) { + str += std::to_string(vec[i]) + ","; + } + str.pop_back(); + os << str; + return os; +} + namespace bindless_helpers { +template +constexpr sycl::vec init_vector(DType val) { + if constexpr (NChannel == 1) { + return sycl::vec{val}; + } else if constexpr (NChannel == 2) { + return sycl::vec{val, val}; + } else if constexpr (NChannel == 4) { + return sycl::vec{val, val, val, val}; + } else { + std::cerr << "Unsupported number of channels " << NChannel << "\n"; + exit(-1); + } +} + +template +bool equal_vec(sycl::vec v1, sycl::vec v2) { + for (int i = 0; i < NChannels; ++i) { + if (v1[i] != v2[i]) { + return false; + } + } + return true; +} + template static void fill_rand(std::vector> &v, int seed = std::default_random_engine::default_seed) { + assert(!v.empty()); std::default_random_engine generator; generator.seed(seed); auto distribution = [&]() { diff --git a/sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp b/sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp index 052cb1994ce68..1b1ae31785eb4 100644 --- a/sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp +++ b/sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp @@ -10,6 +10,7 @@ #include +#include "../bindless_helpers.hpp" #include "vulkan_common.hpp" namespace syclexp = sycl::ext::oneapi::experimental; @@ -163,13 +164,13 @@ bool run_sycl(sycl::range globalSize, sycl::range localSize, float norm_coord_z = ((k + 0.5f) / (float)depth); int z = norm_coord_z * (depth >> 1); - VecType expected = - initVector(i + width * (j + height * k)) + - initVector(x + (width / 2) * - (y + (height / 2) * z)); + VecType expected = bindless_helpers::init_vector( + i + width * (j + height * k)) + + bindless_helpers::init_vector( + x + (width / 2) * (y + (height / 2) * z)); - if (!equal_vec(out[i + width * (j + height * k)], - expected)) { + if (!bindless_helpers::equal_vec( + out[i + width * (j + height * k)], expected)) { mismatch = true; validated = false; } @@ -194,8 +195,10 @@ bool run_sycl(sycl::range globalSize, sycl::range localSize, float norm_coord_y = ((j + 0.5f) / (float)height); int y = norm_coord_y * (height >> 1); - VecType expected = initVector(j + (width * i)) + - initVector(y + (width / 2 * x)); + VecType expected = + bindless_helpers::init_vector(j + (width * i)) + + bindless_helpers::init_vector(y + + (width / 2 * x)); if (!equal_vec(out[j + (width * i)], expected)) { mismatch = true; @@ -289,7 +292,8 @@ bool run_test(sycl::range dims, sycl::range localSize, std::max(height >> i, (uint32_t)1) * std::max(depth >> i, (uint32_t)1)); for (int j = 0; j < mipElems; ++j) { - inputStagingData[j + offset] = initVector(j); + inputStagingData[j + offset] = + bindless_helpers::init_vector(j); } offset += mipElems; } diff --git a/sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp b/sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp index 973f27095bf32..5f279e12383a9 100644 --- a/sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp +++ b/sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp @@ -10,6 +10,7 @@ #include +#include "../bindless_helpers.hpp" #include "vulkan_common.hpp" namespace syclexp = sycl::ext::oneapi::experimental; @@ -147,9 +148,9 @@ bool run_sycl(sycl::range globalSize, sycl::range localSize, bool validated = true; for (int i = 0; i < globalSize.size(); i++) { bool mismatch = false; - VecType expected = - initVector(i) * static_cast(10.1f); - if (!equal_vec(out[i], expected)) { + VecType expected = bindless_helpers::init_vector(i) * + static_cast(10.1f); + if (!bindless_helpers::equal_vec(out[i], expected)) { mismatch = true; validated = false; } @@ -233,7 +234,7 @@ bool run_test(sycl::range dims, sycl::range localSize, imageSizeBytes, 0 /*flags*/, (void **)&inputStagingData)); for (int i = 0; i < numElems; ++i) { - inputStagingData[i] = initVector(i); + inputStagingData[i] = bindless_helpers::init_vector(i); } vkUnmapMemory(vk_device, inputStagingMemory); diff --git a/sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp b/sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp index 7f01281f7e678..8baceaa9b34ff 100644 --- a/sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp +++ b/sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp @@ -264,8 +264,10 @@ bool run_test(sycl::range dims, sycl::range local_size, printString("Populating staging buffer\n"); // Populate staging memory using VecType = sycl::vec; - std::vector input_vector_0; - input_vector_0.reserve(num_elems); + auto init = + bindless_helpers::init_vector(static_cast(0)); + + std::vector input_vector_0(num_elems, init); std::srand(seed); bindless_helpers::fill_rand(input_vector_0); @@ -278,8 +280,7 @@ bool run_test(sycl::range dims, sycl::range local_size, } vkUnmapMemory(vk_device, inVkImgRes1.stagingMemory); - std::vector input_vector_1; - input_vector_1.reserve(num_elems); + std::vector input_vector_1(num_elems, init); std::srand(seed); bindless_helpers::fill_rand(input_vector_1); diff --git a/sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp b/sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp index 65eeea0f7f307..e6d703e2cc0eb 100644 --- a/sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp +++ b/sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp @@ -11,42 +11,6 @@ void printString(std::string str) { #endif } -template -std::ostream &operator<<(std::ostream &os, - const sycl::vec &vec) { - std::string str{""}; - for (int i = 0; i < NChannels; ++i) { - str += std::to_string(vec[i]) + ","; - } - str.pop_back(); - os << str; - return os; -} - -template -bool equal_vec(sycl::vec v1, sycl::vec v2) { - for (int i = 0; i < NChannels; ++i) { - if (v1[i] != v2[i]) { - return false; - } - } - return true; -} - -template -constexpr sycl::vec initVector(DType val) { - if constexpr (NChannel == 1) { - return sycl::vec{val}; - } else if constexpr (NChannel == 2) { - return sycl::vec{val, val}; - } else if constexpr (NChannel == 4) { - return sycl::vec{val, val, val, val}; - } else { - std::cerr << "unsupported number of channels " << NChannel << "\n"; - exit(-1); - } -} - #define VK_CHECK_CALL_RET(call) \ { \ VkResult err = call; \