Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit deac1c6

Browse files
authored
[SYCL][ESIMD] Change logic for tests on simd default constructor (#852)
* [SYCL][ESIMD] Change logic for tests on simd default constructor The documentation for simd default constructor has been changed and now values of the constructed object's elements are undefined.
1 parent a621ef9 commit deac1c6

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

SYCL/ESIMD/api/functional/ctors/ctor_default.hpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,30 @@ template <typename DataT, typename SizeT, typename TestCaseT> struct run_test {
8181

8282
bool operator()(sycl::queue &queue, const std::string &data_type) {
8383
bool passed = true;
84-
DataT default_val{};
8584

85+
// We use it to avoid empty functions being optimized out by compiler
86+
// checking the result of the simd calling because values of the constructed
87+
// object's elements are undefined.
8688
shared_vector<DataT> result(NumElems, shared_allocator<DataT>(queue));
87-
88-
queue.submit([&](sycl::handler &cgh) {
89-
DataT *const out = result.data();
90-
cgh.single_task<Kernel<DataT, NumElems, TestCaseT>>(
91-
[=]() SYCL_ESIMD_KERNEL {
92-
TestCaseT::template call_simd_ctor<DataT, NumElems>(out);
93-
});
94-
});
95-
96-
for (size_t i = 0; i < result.size(); ++i) {
97-
if (result[i] != default_val) {
98-
passed = false;
99-
100-
const auto description =
101-
ctors::TestDescription<DataT, NumElems, TestCaseT>(
102-
i, result[i], default_val, data_type);
103-
log::fail(description);
104-
}
89+
// We do not re-throw an exception to test all combinations of types and
90+
// vector sizes.
91+
try {
92+
queue.submit([&](sycl::handler &cgh) {
93+
DataT *const out = result.data();
94+
cgh.single_task<Kernel<DataT, NumElems, TestCaseT>>(
95+
[=]() SYCL_ESIMD_KERNEL {
96+
TestCaseT::template call_simd_ctor<DataT, NumElems>(out);
97+
});
98+
});
99+
queue.wait_and_throw();
100+
} catch (const sycl::exception &e) {
101+
passed = false;
102+
std::string error_msg("A SYCL exception was caught:");
103+
error_msg += std::string(e.what());
104+
error_msg += " for simd<" + data_type;
105+
error_msg += ", " + std::to_string(NumElems) + ">";
106+
error_msg += ", with context: " + TestCaseT::get_description();
107+
log::note(error_msg);
105108
}
106109

107110
return passed;

0 commit comments

Comments
 (0)