Skip to content

[SYCL][Bindless][E2E] fix unsampled images test failure #13007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions sycl/test-e2e/bindless_images/bindless_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,48 @@
#include <random>
#include <sycl/sycl.hpp>

template <typename DType, int NChannels>
std::ostream &operator<<(std::ostream &os,
const sycl::vec<DType, NChannels> &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 <typename DType, int NChannel>
constexpr sycl::vec<DType, NChannel> init_vector(DType val) {
if constexpr (NChannel == 1) {
return sycl::vec<DType, NChannel>{val};
} else if constexpr (NChannel == 2) {
return sycl::vec<DType, NChannel>{val, val};
} else if constexpr (NChannel == 4) {
return sycl::vec<DType, NChannel>{val, val, val, val};
} else {
std::cerr << "Unsupported number of channels " << NChannel << "\n";
exit(-1);
}
}

template <typename DType, int NChannels>
bool equal_vec(sycl::vec<DType, NChannels> v1, sycl::vec<DType, NChannels> v2) {
for (int i = 0; i < NChannels; ++i) {
if (v1[i] != v2[i]) {
return false;
}
}
return true;
}

template <typename DType, int NChannels>
static void fill_rand(std::vector<sycl::vec<DType, NChannels>> &v,
int seed = std::default_random_engine::default_seed) {
assert(!v.empty());
std::default_random_engine generator;
generator.seed(seed);
auto distribution = [&]() {
Expand Down
22 changes: 13 additions & 9 deletions sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sycl/sycl.hpp>

#include "../bindless_helpers.hpp"
#include "vulkan_common.hpp"

namespace syclexp = sycl::ext::oneapi::experimental;
Expand Down Expand Up @@ -163,13 +164,13 @@ bool run_sycl(sycl::range<NDims> globalSize, sycl::range<NDims> localSize,
float norm_coord_z = ((k + 0.5f) / (float)depth);
int z = norm_coord_z * (depth >> 1);

VecType expected =
initVector<DType, NChannels>(i + width * (j + height * k)) +
initVector<DType, NChannels>(x + (width / 2) *
(y + (height / 2) * z));
VecType expected = bindless_helpers::init_vector<DType, NChannels>(
i + width * (j + height * k)) +
bindless_helpers::init_vector<DType, NChannels>(
x + (width / 2) * (y + (height / 2) * z));

if (!equal_vec<DType, NChannels>(out[i + width * (j + height * k)],
expected)) {
if (!bindless_helpers::equal_vec<DType, NChannels>(
out[i + width * (j + height * k)], expected)) {
mismatch = true;
validated = false;
}
Expand All @@ -194,8 +195,10 @@ bool run_sycl(sycl::range<NDims> globalSize, sycl::range<NDims> localSize,
float norm_coord_y = ((j + 0.5f) / (float)height);
int y = norm_coord_y * (height >> 1);

VecType expected = initVector<DType, NChannels>(j + (width * i)) +
initVector<DType, NChannels>(y + (width / 2 * x));
VecType expected =
bindless_helpers::init_vector<DType, NChannels>(j + (width * i)) +
bindless_helpers::init_vector<DType, NChannels>(y +
(width / 2 * x));

if (!equal_vec<DType, NChannels>(out[j + (width * i)], expected)) {
mismatch = true;
Expand Down Expand Up @@ -289,7 +292,8 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> 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<DType, NChannels>(j);
inputStagingData[j + offset] =
bindless_helpers::init_vector<DType, NChannels>(j);
}
offset += mipElems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sycl/sycl.hpp>

#include "../bindless_helpers.hpp"
#include "vulkan_common.hpp"

namespace syclexp = sycl::ext::oneapi::experimental;
Expand Down Expand Up @@ -147,9 +148,9 @@ bool run_sycl(sycl::range<NDims> globalSize, sycl::range<NDims> localSize,
bool validated = true;
for (int i = 0; i < globalSize.size(); i++) {
bool mismatch = false;
VecType expected =
initVector<DType, NChannels>(i) * static_cast<DType>(10.1f);
if (!equal_vec<DType, NChannels>(out[i], expected)) {
VecType expected = bindless_helpers::init_vector<DType, NChannels>(i) *
static_cast<DType>(10.1f);
if (!bindless_helpers::equal_vec<DType, NChannels>(out[i], expected)) {
mismatch = true;
validated = false;
}
Expand Down Expand Up @@ -233,7 +234,7 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> localSize,
imageSizeBytes, 0 /*flags*/,
(void **)&inputStagingData));
for (int i = 0; i < numElems; ++i) {
inputStagingData[i] = initVector<DType, NChannels>(i);
inputStagingData[i] = bindless_helpers::init_vector<DType, NChannels>(i);
}
vkUnmapMemory(vk_device, inputStagingMemory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> local_size,
printString("Populating staging buffer\n");
// Populate staging memory
using VecType = sycl::vec<DType, NChannels>;
std::vector<VecType> input_vector_0;
input_vector_0.reserve(num_elems);
auto init =
bindless_helpers::init_vector<DType, NChannels>(static_cast<DType>(0));

std::vector<VecType> input_vector_0(num_elems, init);
std::srand(seed);
bindless_helpers::fill_rand(input_vector_0);

Expand All @@ -278,8 +280,7 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> local_size,
}
vkUnmapMemory(vk_device, inVkImgRes1.stagingMemory);

std::vector<VecType> input_vector_1;
input_vector_1.reserve(num_elems);
std::vector<VecType> input_vector_1(num_elems, init);
std::srand(seed);
bindless_helpers::fill_rand(input_vector_1);

Expand Down
36 changes: 0 additions & 36 deletions sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,6 @@ void printString(std::string str) {
#endif
}

template <typename DType, int NChannels>
std::ostream &operator<<(std::ostream &os,
const sycl::vec<DType, NChannels> &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 <typename DType, int NChannels>
bool equal_vec(sycl::vec<DType, NChannels> v1, sycl::vec<DType, NChannels> v2) {
for (int i = 0; i < NChannels; ++i) {
if (v1[i] != v2[i]) {
return false;
}
}
return true;
}

template <typename DType, int NChannel>
constexpr sycl::vec<DType, NChannel> initVector(DType val) {
if constexpr (NChannel == 1) {
return sycl::vec<DType, NChannel>{val};
} else if constexpr (NChannel == 2) {
return sycl::vec<DType, NChannel>{val, val};
} else if constexpr (NChannel == 4) {
return sycl::vec<DType, NChannel>{val, val, val, val};
} else {
std::cerr << "unsupported number of channels " << NChannel << "\n";
exit(-1);
}
}

#define VK_CHECK_CALL_RET(call) \
{ \
VkResult err = call; \
Expand Down