Skip to content

Commit 6265a6b

Browse files
authored
[SYCL][E2E][Bindless] Fix input value out-of-range for int8/int16 types (#15086)
globalSize.size() may be larger than maximum value of int8/int16 types. Resolve #14945 (comment)
1 parent ef13a99 commit 6265a6b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// Uncomment to print additional test information
88
// #define VERBOSE_PRINT
99

10+
#ifdef _WIN32
11+
#define NOMINMAX
12+
#endif
13+
1014
#include "../helpers/common.hpp"
1115
#include "vulkan_common.hpp"
1216

@@ -176,11 +180,17 @@ bool run_sycl(InteropHandleT inputInteropMemHandle,
176180

177181
printString("Validating\n");
178182
bool validated = true;
183+
auto getExpectedValue = [&](int i) -> OutType {
184+
if (CType == sycl::image_channel_type::unorm_int8)
185+
return 0.5f;
186+
if constexpr (std::is_integral_v<OutType>)
187+
i = i % std::numeric_limits<OutType>::max();
188+
return i / 2.f;
189+
};
179190
for (int i = 0; i < globalSize.size(); i++) {
180191
bool mismatch = false;
181192
VecType expected =
182-
bindless_helpers::init_vector<OutType, NChannels>(static_cast<OutType>(
183-
CType == sycl::image_channel_type::unorm_int8 ? 0.5f : (i / 2.f)));
193+
bindless_helpers::init_vector<OutType, NChannels>(getExpectedValue(i));
184194
if (!bindless_helpers::equal_vec<OutType, NChannels>(out[i], expected)) {
185195
mismatch = true;
186196
validated = false;
@@ -269,10 +279,16 @@ bool run_test(sycl::range<NDims> dims, sycl::range<NDims> localSize,
269279
VK_CHECK_CALL(vkMapMemory(vk_device, inputStagingMemory, 0 /*offset*/,
270280
imageSizeBytes, 0 /*flags*/,
271281
(void **)&inputStagingData));
282+
auto getInputValue = [&](int i) -> DType {
283+
if (CType == sycl::image_channel_type::unorm_int8)
284+
return 255;
285+
if constexpr (std::is_integral_v<DType>)
286+
i = i % std::numeric_limits<DType>::max();
287+
return i;
288+
};
272289
for (int i = 0; i < numElems; ++i) {
273290
inputStagingData[i] =
274-
bindless_helpers::init_vector<DType, NChannels>(static_cast<DType>(
275-
CType == sycl::image_channel_type::unorm_int8 ? 255 : i));
291+
bindless_helpers::init_vector<DType, NChannels>(getInputValue(i));
276292
}
277293
vkUnmapMemory(vk_device, inputStagingMemory);
278294

0 commit comments

Comments
 (0)