Skip to content

Commit b125ddf

Browse files
cppchedykbenzie
authored andcommitted
[SYCL][Bindless][E2E] fix unsampled images test failure (intel#13007)
* Update the test to initialize the input vectors with 0s to match `bindless_helpers::fill_rand` requirement of non empty vector. * Change the name of function `initVector` to `init_vector`. * move `init_vector`, `equal_vec` and `operator<<` in header `bindless_helpers.hpp`.
1 parent 92e0423 commit b125ddf

File tree

5 files changed

+60
-53
lines changed

5 files changed

+60
-53
lines changed

sycl/test-e2e/bindless_images/bindless_helpers.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,48 @@
22
#include <random>
33
#include <sycl/sycl.hpp>
44

5+
template <typename DType, int NChannels>
6+
std::ostream &operator<<(std::ostream &os,
7+
const sycl::vec<DType, NChannels> &vec) {
8+
std::string str{""};
9+
for (int i = 0; i < NChannels; ++i) {
10+
str += std::to_string(vec[i]) + ",";
11+
}
12+
str.pop_back();
13+
os << str;
14+
return os;
15+
}
16+
517
namespace bindless_helpers {
618

19+
template <typename DType, int NChannel>
20+
constexpr sycl::vec<DType, NChannel> init_vector(DType val) {
21+
if constexpr (NChannel == 1) {
22+
return sycl::vec<DType, NChannel>{val};
23+
} else if constexpr (NChannel == 2) {
24+
return sycl::vec<DType, NChannel>{val, val};
25+
} else if constexpr (NChannel == 4) {
26+
return sycl::vec<DType, NChannel>{val, val, val, val};
27+
} else {
28+
std::cerr << "Unsupported number of channels " << NChannel << "\n";
29+
exit(-1);
30+
}
31+
}
32+
33+
template <typename DType, int NChannels>
34+
bool equal_vec(sycl::vec<DType, NChannels> v1, sycl::vec<DType, NChannels> v2) {
35+
for (int i = 0; i < NChannels; ++i) {
36+
if (v1[i] != v2[i]) {
37+
return false;
38+
}
39+
}
40+
return true;
41+
}
42+
743
template <typename DType, int NChannels>
844
static void fill_rand(std::vector<sycl::vec<DType, NChannels>> &v,
945
int seed = std::default_random_engine::default_seed) {
46+
assert(!v.empty());
1047
std::default_random_engine generator;
1148
generator.seed(seed);
1249
auto distribution = [&]() {

sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sycl/sycl.hpp>
1212

13+
#include "../bindless_helpers.hpp"
1314
#include "vulkan_common.hpp"
1415

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

166-
VecType expected =
167-
initVector<DType, NChannels>(i + width * (j + height * k)) +
168-
initVector<DType, NChannels>(x + (width / 2) *
169-
(y + (height / 2) * z));
167+
VecType expected = bindless_helpers::init_vector<DType, NChannels>(
168+
i + width * (j + height * k)) +
169+
bindless_helpers::init_vector<DType, NChannels>(
170+
x + (width / 2) * (y + (height / 2) * z));
170171

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

197-
VecType expected = initVector<DType, NChannels>(j + (width * i)) +
198-
initVector<DType, NChannels>(y + (width / 2 * x));
198+
VecType expected =
199+
bindless_helpers::init_vector<DType, NChannels>(j + (width * i)) +
200+
bindless_helpers::init_vector<DType, NChannels>(y +
201+
(width / 2 * x));
199202

200203
if (!equal_vec<DType, NChannels>(out[j + (width * i)], expected)) {
201204
mismatch = true;
@@ -289,7 +292,8 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> localSize,
289292
std::max(height >> i, (uint32_t)1) *
290293
std::max(depth >> i, (uint32_t)1));
291294
for (int j = 0; j < mipElems; ++j) {
292-
inputStagingData[j + offset] = initVector<DType, NChannels>(j);
295+
inputStagingData[j + offset] =
296+
bindless_helpers::init_vector<DType, NChannels>(j);
293297
}
294298
offset += mipElems;
295299
}

sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sycl/sycl.hpp>
1212

13+
#include "../bindless_helpers.hpp"
1314
#include "vulkan_common.hpp"
1415

1516
namespace syclexp = sycl::ext::oneapi::experimental;
@@ -147,9 +148,9 @@ bool run_sycl(sycl::range<NDims> globalSize, sycl::range<NDims> localSize,
147148
bool validated = true;
148149
for (int i = 0; i < globalSize.size(); i++) {
149150
bool mismatch = false;
150-
VecType expected =
151-
initVector<DType, NChannels>(i) * static_cast<DType>(10.1f);
152-
if (!equal_vec<DType, NChannels>(out[i], expected)) {
151+
VecType expected = bindless_helpers::init_vector<DType, NChannels>(i) *
152+
static_cast<DType>(10.1f);
153+
if (!bindless_helpers::equal_vec<DType, NChannels>(out[i], expected)) {
153154
mismatch = true;
154155
validated = false;
155156
}
@@ -233,7 +234,7 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> localSize,
233234
imageSizeBytes, 0 /*flags*/,
234235
(void **)&inputStagingData));
235236
for (int i = 0; i < numElems; ++i) {
236-
inputStagingData[i] = initVector<DType, NChannels>(i);
237+
inputStagingData[i] = bindless_helpers::init_vector<DType, NChannels>(i);
237238
}
238239
vkUnmapMemory(vk_device, inputStagingMemory);
239240

sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> local_size,
264264
printString("Populating staging buffer\n");
265265
// Populate staging memory
266266
using VecType = sycl::vec<DType, NChannels>;
267-
std::vector<VecType> input_vector_0;
268-
input_vector_0.reserve(num_elems);
267+
auto init =
268+
bindless_helpers::init_vector<DType, NChannels>(static_cast<DType>(0));
269+
270+
std::vector<VecType> input_vector_0(num_elems, init);
269271
std::srand(seed);
270272
bindless_helpers::fill_rand(input_vector_0);
271273

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

281-
std::vector<VecType> input_vector_1;
282-
input_vector_1.reserve(num_elems);
283+
std::vector<VecType> input_vector_1(num_elems, init);
283284
std::srand(seed);
284285
bindless_helpers::fill_rand(input_vector_1);
285286

sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,6 @@ void printString(std::string str) {
1111
#endif
1212
}
1313

14-
template <typename DType, int NChannels>
15-
std::ostream &operator<<(std::ostream &os,
16-
const sycl::vec<DType, NChannels> &vec) {
17-
std::string str{""};
18-
for (int i = 0; i < NChannels; ++i) {
19-
str += std::to_string(vec[i]) + ",";
20-
}
21-
str.pop_back();
22-
os << str;
23-
return os;
24-
}
25-
26-
template <typename DType, int NChannels>
27-
bool equal_vec(sycl::vec<DType, NChannels> v1, sycl::vec<DType, NChannels> v2) {
28-
for (int i = 0; i < NChannels; ++i) {
29-
if (v1[i] != v2[i]) {
30-
return false;
31-
}
32-
}
33-
return true;
34-
}
35-
36-
template <typename DType, int NChannel>
37-
constexpr sycl::vec<DType, NChannel> initVector(DType val) {
38-
if constexpr (NChannel == 1) {
39-
return sycl::vec<DType, NChannel>{val};
40-
} else if constexpr (NChannel == 2) {
41-
return sycl::vec<DType, NChannel>{val, val};
42-
} else if constexpr (NChannel == 4) {
43-
return sycl::vec<DType, NChannel>{val, val, val, val};
44-
} else {
45-
std::cerr << "unsupported number of channels " << NChannel << "\n";
46-
exit(-1);
47-
}
48-
}
49-
5014
#define VK_CHECK_CALL_RET(call) \
5115
{ \
5216
VkResult err = call; \

0 commit comments

Comments
 (0)