Skip to content

Commit 1bbadf1

Browse files
vasilytricbb-sycl
authored andcommitted
[SYCL][ESIMD] Add tests on simd increment and decrement operators (intel#827)
* [SYCL][ESIMD] Add tests on simd increment and decrement operators
1 parent 7c50e3d commit 1bbadf1

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

SYCL/ESIMD/api/functional/operators/operator_decrement_and_increment.hpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#pragma once
17+
<<<<<<< HEAD
1718
#define ESIMD_TESTS_DISABLE_DEPRECATED_TEST_DESCRIPTION_FOR_LOGS
19+
=======
20+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
1821

1922
#include "../mutator.hpp"
2023
#include "common.hpp"
2124

25+
<<<<<<< HEAD
2226
namespace esimd = sycl::ext::intel::esimd;
27+
=======
28+
namespace esimd = sycl::ext::intel::experimental::esimd;
29+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
2330
namespace esimd_functional = esimd_test::api::functional;
2431

2532
namespace esimd_test::api::functional::operators {
@@ -112,6 +119,41 @@ struct post_increment {
112119
static constexpr bool is_increment() { return true; }
113120
};
114121

122+
<<<<<<< HEAD
123+
=======
124+
template <typename DataT, int NumElems, typename TestCaseT>
125+
class IncrementAndDecrementTestDescription : public ITestDescription {
126+
public:
127+
IncrementAndDecrementTestDescription(size_t index, DataT retrieved_val,
128+
DataT expected_val,
129+
const std::string &error_details,
130+
const std::string &data_type)
131+
: m_data_type(data_type), m_retrieved_val(retrieved_val),
132+
m_expected_val(expected_val), m_index(index),
133+
m_error_details(error_details) {}
134+
135+
std::string to_string() const override {
136+
std::string log_msg("Failed for simd<");
137+
138+
log_msg += m_data_type + ", " + std::to_string(NumElems) + ">";
139+
log_msg += ", retrieved: " + std::to_string(m_retrieved_val);
140+
log_msg += ", expected: " + std::to_string(m_expected_val);
141+
log_msg += ", at index: " + std::to_string(m_index);
142+
log_msg += " for " + TestCaseT::get_description() + " operator: ";
143+
log_msg += m_error_details;
144+
145+
return log_msg;
146+
}
147+
148+
private:
149+
const std::string m_data_type;
150+
const DataT m_retrieved_val;
151+
const DataT m_expected_val;
152+
const size_t m_index;
153+
const std::string m_error_details;
154+
};
155+
156+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
115157
struct base_test {
116158
template <typename DataT, int NumElems, typename TestCaseT>
117159
static std::vector<DataT> generate_input_data() {
@@ -168,7 +210,10 @@ template <typename IsAccuracyTestT, typename DataT, typename SizeT,
168210
typename TestCaseT>
169211
class run_test {
170212
static constexpr int NumElems = SizeT::value;
213+
<<<<<<< HEAD
171214
using TestDescriptionT = operators::TestDescription<NumElems, TestCaseT>;
215+
=======
216+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
172217

173218
public:
174219
bool operator()(sycl::queue &queue, const std::string &data_type) {
@@ -198,7 +243,10 @@ class run_test {
198243
"Reference data size is not equal to the simd vector length.");
199244

200245
bool passed = true;
246+
<<<<<<< HEAD
201247
log::trace<TestDescriptionT>(data_type);
248+
=======
249+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
202250

203251
shared_allocator<DataT> allocator(queue);
204252
shared_vector<DataT> source_simd_out(NumElems, allocator);
@@ -226,31 +274,61 @@ class run_test {
226274
TestCaseT::apply_operator(expected_source_value);
227275

228276
passed &= verify_result(i, expected_source_value, source_simd_out[i],
277+
<<<<<<< HEAD
229278
"argument modification", data_type);
230279
passed &= verify_result(i, expected_return_value, result_simd_out[i],
231280
"return value", data_type);
281+
=======
282+
"unexpected argument modification", data_type);
283+
passed &= verify_result(i, expected_return_value, result_simd_out[i],
284+
"unexpected return value", data_type);
285+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
232286
}
233287

234288
return passed;
235289
}
236290

237291
bool verify_result(size_t i, DataT expected, DataT retrieved,
292+
<<<<<<< HEAD
238293
const std::string &value_description,
294+
=======
295+
const std::string &simd_type,
296+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
239297
const std::string &data_type) {
240298
bool passed = true;
241299
if constexpr (type_traits::is_sycl_floating_point_v<DataT>) {
242300
if (std::isnan(expected) && !std::isnan(retrieved)) {
243301
passed = false;
302+
<<<<<<< HEAD
244303
log::fail(TestDescriptionT(data_type), "Unexpected ",
245304
value_description, "at index ", i, ", retrieved: ", retrieved,
246305
", expected: any NaN value");
306+
=======
307+
308+
// TODO: Make ITestDescription architecture more flexible.
309+
// We are assuming that the NaN opcode may differ
310+
std::string log_msg("Failed for simd<");
311+
log_msg += data_type + ", " + std::to_string(NumElems) + ">";
312+
log_msg += ". The element at index: " + std::to_string(i) +
313+
", is not nan, but it should.";
314+
315+
log::note(log_msg);
316+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
247317
}
248318
}
249319
if (!are_bitwise_equal(expected, retrieved)) {
250320
passed = false;
321+
<<<<<<< HEAD
251322
log::fail(TestDescriptionT(data_type), "Unexpected ",
252323
value_description, "at index ", i, ", retrieved: ", retrieved,
253324
", expected: ", expected);
325+
=======
326+
327+
const auto description =
328+
IncrementAndDecrementTestDescription<DataT, NumElems, TestCaseT>(
329+
i, retrieved, expected, simd_type, data_type);
330+
log::fail(description);
331+
>>>>>>> d6527a558 ([SYCL][ESIMD] Add tests on simd increment and decrement operators (#827))
254332
}
255333
return passed;
256334
}

0 commit comments

Comments
 (0)