|
5 | 5 |
|
6 | 6 | using bfloat16 = sycl::ext::oneapi::bfloat16;
|
7 | 7 |
|
8 |
| -constexpr float BF16_EPSILON = 10e-2; |
9 |
| -constexpr float FLOAT_EPSILON = 10e-3; |
| 8 | +// Most of the time, failures related to floating-point calculations (both float |
| 9 | +// and bfloat16) are caused by accumulation errors rather than the algorithm |
| 10 | +// itself. If it is an algorithm issue, the calculated result gap from the |
| 11 | +// reference would be much bigger. To avoid flaky test results while catching |
| 12 | +// algorithm errors, we are increasing the accuracy threshold. |
| 13 | +// Something like this should be good enough to catch algorithm errors: |
| 14 | +// fabs(ref[i] - val[i])/max(fabs(ref)) < 10e-2 |
| 15 | +constexpr float FLOAT_EPSILON = 10e-2; |
10 | 16 |
|
11 | 17 | template <typename T, size_t NUM_ROWS, size_t NUM_COLS> struct big_matrix {
|
12 | 18 | public:
|
@@ -103,11 +109,11 @@ bool matrix_compare(unsigned int rows, unsigned int cols, T1 *src, T2 *ref) {
|
103 | 109 | for (int j = 0; j < cols; j++) {
|
104 | 110 | if constexpr (std::is_same_v<T1, float> || std::is_same_v<T1, bfloat16>) {
|
105 | 111 | float diff = std::fabs(src[i * cols + j] - (T1)ref[i * cols + j]);
|
106 |
| - if (std::is_same_v<T1, float> && diff > FLOAT_EPSILON || |
107 |
| - std::is_same_v<T1, bfloat16> && diff > BF16_EPSILON) { |
| 112 | + if (diff > FLOAT_EPSILON) { |
108 | 113 | std::cout << "Incorrect result in matrix. Ref: "
|
109 | 114 | << (T1)ref[i * cols + j] << ", Val: " << src[i * cols + j]
|
110 |
| - << ", Diff: " << diff << "\n"; |
| 115 | + << ", Diff: " << diff << ", Epsilon: " << FLOAT_EPSILON |
| 116 | + << "\n"; |
111 | 117 | return false;
|
112 | 118 | }
|
113 | 119 | } else if constexpr (std::is_same_v<T1, int32_t>) {
|
|
0 commit comments