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

Commit 6bd2803

Browse files
authored
[SYCL][ESIMD] Fix reference generation for fp types (#627)
Any floating point type is signed Signed-off-by: Kochetkov, Yuriy <[email protected]>
1 parent ee4653d commit 6bd2803

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

SYCL/ESIMD/api/functional/value.hpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,24 @@ template <typename DataT, int NumElems> std::vector<DataT> generate_ref_data() {
133133

134134
std::vector<DataT> ref_data{};
135135

136-
if constexpr (std::is_signed_v<DataT>) {
136+
if constexpr (type_traits::is_sycl_floating_point_v<DataT>) {
137+
static const DataT nan = value<DataT>::nan();
138+
static const DataT inf = value<DataT>::inf();
139+
140+
ref_data.reserve((NumElems > 1) ? NumElems : 6);
141+
142+
// We are using the `double` literals to avoid precision loss for case of
143+
// the `double` DataT on unexact values like 0.1
144+
ref_data.insert(ref_data.end(), {-inf, nan, min, max, -0.0, 0.1});
145+
if constexpr (NumElems != 1) {
146+
ref_data.insert(ref_data.end(), {-0.1, +0.0});
147+
for (size_t i = ref_data.size(); i < NumElems; ++i) {
148+
// Store values with exact representation of the fraction part for
149+
// every floating point type
150+
ref_data.push_back(i + 0.25);
151+
}
152+
}
153+
} else if constexpr (std::is_signed_v<DataT>) {
137154
ref_data.reserve((NumElems > 1) ? NumElems : 5);
138155

139156
ref_data.insert(ref_data.end(), {min, min_half, max, max_half, 0});
@@ -143,9 +160,8 @@ template <typename DataT, int NumElems> std::vector<DataT> generate_ref_data() {
143160
ref_data.push_back(i);
144161
}
145162
}
146-
}
147-
148-
if constexpr (std::is_unsigned_v<DataT>) {
163+
} else {
164+
// Unsigned integral type
149165
ref_data.reserve((NumElems > 1) ? NumElems : 3);
150166

151167
ref_data.insert(ref_data.end(), {max, max_half, 0});
@@ -156,26 +172,6 @@ template <typename DataT, int NumElems> std::vector<DataT> generate_ref_data() {
156172
}
157173
}
158174
}
159-
160-
if constexpr (type_traits::is_sycl_floating_point_v<DataT>) {
161-
static const DataT nan = value<DataT>::nan();
162-
static const DataT inf = value<DataT>::inf();
163-
164-
ref_data.reserve((NumElems > 1) ? NumElems : 6);
165-
166-
// We are using the `double` literals to avoid precision loss for case of
167-
// the `double` DataT on unexact values like 0.1
168-
ref_data.insert(ref_data.end(), {-inf, nan, min, max, -0.0, 0.1});
169-
if constexpr (NumElems != 1) {
170-
ref_data.insert(ref_data.end(), {-0.1, +0.0});
171-
for (size_t i = ref_data.size(); i < NumElems; ++i) {
172-
// Store values with exact representation of the fraction part for
173-
// every floating point type
174-
ref_data.push_back(i + 0.25);
175-
}
176-
}
177-
}
178-
179175
return ref_data;
180176
}
181177

0 commit comments

Comments
 (0)