From 54c4c49789270ec04df3091461be3f7026b1579b Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 5 Jul 2023 05:04:09 -0700 Subject: [PATCH 1/2] [SYCL][E2E] Fix abs ambiguities ahead of changes to builtins Upcoming changes to SYCL builtins will cause code using namespace sycl implicitly to be ambiguous when using certain builtins that are available in the global scope already. This commit changes uses of `abs` to be namespace qualified to avoid them breaking with future builtin changes. Signed-off-by: Larsen, Steffen --- sycl/test-e2e/ESIMD/Stencil.cpp | 2 +- sycl/test-e2e/ESIMD/api/bin_and_cmp_ops_heavy.cpp | 2 +- sycl/test-e2e/ESIMD/api/unary_ops_heavy.cpp | 2 +- sycl/test-e2e/ESIMD/esimd_test_utils.hpp | 2 +- sycl/test-e2e/ESIMD/ext_math.cpp | 2 +- sycl/test-e2e/ESIMD/kmeans/kmeans.cpp | 5 +++-- sycl/test-e2e/ESIMD/linear/bitmap_helpers.h | 6 +++--- sycl/test-e2e/ESIMD/stencil2.cpp | 2 +- sycl/test-e2e/ESIMD/vadd_half.cpp | 2 +- .../GroupAlgorithm/SYCL2020/reduce_over_group_size.cpp | 2 +- 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sycl/test-e2e/ESIMD/Stencil.cpp b/sycl/test-e2e/ESIMD/Stencil.cpp index 7bc07960e103d..9486eaba555c6 100644 --- a/sycl/test-e2e/ESIMD/Stencil.cpp +++ b/sycl/test-e2e/ESIMD/Stencil.cpp @@ -58,7 +58,7 @@ bool CheckResults(float *out, float *in, unsigned n) { in[(i + 5) * n + (j + 0)] * 0.02f; // check result - if (abs(res - out[i * n + j]) >= 0.0015f) { + if (std::abs(res - out[i * n + j]) >= 0.0015f) { std::cout << "out[" << i << "][" << j << "] = " << out[i * n + j] << " expect result " << res << std::endl; return false; diff --git a/sycl/test-e2e/ESIMD/api/bin_and_cmp_ops_heavy.cpp b/sycl/test-e2e/ESIMD/api/bin_and_cmp_ops_heavy.cpp index 012a2f20cbe94..66b434d9f9cef 100644 --- a/sycl/test-e2e/ESIMD/api/bin_and_cmp_ops_heavy.cpp +++ b/sycl/test-e2e/ESIMD/api/bin_and_cmp_ops_heavy.cpp @@ -212,7 +212,7 @@ template struct verify_n { using Tint = esimd_test::int_type_t; Tint res_bits = *(Tint *)&res; Tint gold_bits = *(Tint *)&gold; - return (abs(gold_bits - res_bits) > n) ? false : true; + return (std::abs(gold_bits - res_bits) > n) ? false : true; } }; diff --git a/sycl/test-e2e/ESIMD/api/unary_ops_heavy.cpp b/sycl/test-e2e/ESIMD/api/unary_ops_heavy.cpp index 50778fef19ff8..f360630478e8e 100644 --- a/sycl/test-e2e/ESIMD/api/unary_ops_heavy.cpp +++ b/sycl/test-e2e/ESIMD/api/unary_ops_heavy.cpp @@ -125,7 +125,7 @@ bool test(Ops ops, queue &q) { ? 1 : 0; - if ((Gold != Res) && (abs(ResBits - GoldBits) > delta)) { + if ((Gold != Res) && (std::abs(ResBits - GoldBits) > delta)) { if (++err_cnt < 10) { std::cout << " failed at index " << (res_off + j) << ", op " << esimd_test::Op2Str(op) << ": " << cast(Res) diff --git a/sycl/test-e2e/ESIMD/esimd_test_utils.hpp b/sycl/test-e2e/ESIMD/esimd_test_utils.hpp index 422b09b62d9da..0de584191bd41 100644 --- a/sycl/test-e2e/ESIMD/esimd_test_utils.hpp +++ b/sycl/test-e2e/ESIMD/esimd_test_utils.hpp @@ -149,7 +149,7 @@ bool cmp_binary_files(const char *testOutFile, const char *referenceFile, double maxRelativeDiff = 0; bool status = true; for (size_t i = 0; i < size; i++) { - const auto diff = abs(testVec[i] - referenceVec[i]); + const auto diff = std::abs(testVec[i] - referenceVec[i]); if (diff > tolerance) { if (!mismatchRateTolerance || (totalMismatches < mismatchReportLimit)) { diff --git a/sycl/test-e2e/ESIMD/ext_math.cpp b/sycl/test-e2e/ESIMD/ext_math.cpp index 215868a367233..47a9e7b251532 100644 --- a/sycl/test-e2e/ESIMD/ext_math.cpp +++ b/sycl/test-e2e/ESIMD/ext_math.cpp @@ -377,7 +377,7 @@ bool test(queue &Q, const std::string &Name, } bool BothFinite = std::isfinite(Test) && std::isfinite(Gold); - if (BothFinite && abs(Test - Gold) > delta) { + if (BothFinite && std::abs(Test - Gold) > delta) { if (++ErrCnt < 10) { std::cout << " failed at index " << I << ", " << Test << " != " << Gold << " (gold)\n"; diff --git a/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp b/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp index 180f2db54a214..7758fcf3f05df 100644 --- a/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp +++ b/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp @@ -80,8 +80,9 @@ bool verify_result(Centroid4 *centroids4, // gpu centroids result float errY = std::fabs(centroids4[j].y[k] - centroids[i].y) / max(std::fabs(centroids4[j].y[k]), std::fabs(centroids[i].y)); float errSize = - abs(centroids4[j].num_points[k] - centroids[i].num_points) / - max(abs(centroids4[j].num_points[k]), abs(centroids[i].num_points)); + std::abs(centroids4[j].num_points[k] - centroids[i].num_points) / + std::max(std::abs(centroids4[j].num_points[k]), + std::abs(centroids[i].num_points)); // std::cout << i << ": Wanted (" << centroids[i].x << ", " << // centroids[i].y // << ", " << centroids[i].num_points << ")" << std::endl; diff --git a/sycl/test-e2e/ESIMD/linear/bitmap_helpers.h b/sycl/test-e2e/ESIMD/linear/bitmap_helpers.h index e6c8863bd4c82..466ecf79f0882 100644 --- a/sycl/test-e2e/ESIMD/linear/bitmap_helpers.h +++ b/sycl/test-e2e/ESIMD/linear/bitmap_helpers.h @@ -255,8 +255,8 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { return false; } - width = abs(*(short *)&header_out[18]); - height = abs(*(short *)&header_out[22]); + width = std::abs(*(short *)&header_out[18]); + height = std::abs(*(short *)&header_out[22]); img_out = (unsigned char *)std::malloc(width * height * 3); img_gold = (unsigned char *)std::malloc(width * height * 3); @@ -276,7 +276,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { fclose(f_gold); for (i = 0; i < width * height * 3; i++) { - if (abs(img_out[i] - img_gold[i]) > tolerance) { + if (std::abs(img_out[i] - img_gold[i]) > tolerance) { return false; } } diff --git a/sycl/test-e2e/ESIMD/stencil2.cpp b/sycl/test-e2e/ESIMD/stencil2.cpp index 0589b446b1911..c7969ce2c1398 100644 --- a/sycl/test-e2e/ESIMD/stencil2.cpp +++ b/sycl/test-e2e/ESIMD/stencil2.cpp @@ -59,7 +59,7 @@ bool CheckResults(float *out, float *in, unsigned n) { in[(i + 5) * n + (j + 0)] * 0.02f; // check result - if (abs(res - out[i * n + j]) >= 0.0015f) { + if (std::abs(res - out[i * n + j]) >= 0.0015f) { std::cout << "out[" << i << "][" << j << "] = " << out[i * n + j] << " expect result " << res << std::endl; return false; diff --git a/sycl/test-e2e/ESIMD/vadd_half.cpp b/sycl/test-e2e/ESIMD/vadd_half.cpp index 23a0e1944c6ba..dde3e845e5cbf 100644 --- a/sycl/test-e2e/ESIMD/vadd_half.cpp +++ b/sycl/test-e2e/ESIMD/vadd_half.cpp @@ -98,7 +98,7 @@ int main(int argc, char **argv) { Tint ResBits = *(Tint *)&Res; Tint GoldBits = *(Tint *)&Gold; - if (abs(ResBits - GoldBits) > 1) { + if (std::abs(ResBits - GoldBits) > 1) { if (++err_cnt < 100) { std::cout << "failed at index " << i << ": " << cast(Res) << "(0x" << std::hex << ResBits << ")" diff --git a/sycl/test-e2e/GroupAlgorithm/SYCL2020/reduce_over_group_size.cpp b/sycl/test-e2e/GroupAlgorithm/SYCL2020/reduce_over_group_size.cpp index 40e2b4fa04794..47dca77127e27 100644 --- a/sycl/test-e2e/GroupAlgorithm/SYCL2020/reduce_over_group_size.cpp +++ b/sycl/test-e2e/GroupAlgorithm/SYCL2020/reduce_over_group_size.cpp @@ -91,7 +91,7 @@ int main() { } for (int j = 0; j < NV; j++) { auto d = s[j] - r[k * NV + j]; - if (abs(d) > 1e-10) { + if (std::abs(d) > 1e-10) { printf("partial fail "); printf("%i\t%i\t%g\t%g\n", k, j, s[j], r[k * NV + j]); fails++; From 47cb7b66299c70150a864109c5996b4ce3a54297 Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 5 Jul 2023 06:22:38 -0700 Subject: [PATCH 2/2] Remove conflicting max change Signed-off-by: Larsen, Steffen --- sycl/test-e2e/ESIMD/kmeans/kmeans.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp b/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp index 7758fcf3f05df..50328431ea0c0 100644 --- a/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp +++ b/sycl/test-e2e/ESIMD/kmeans/kmeans.cpp @@ -81,8 +81,8 @@ bool verify_result(Centroid4 *centroids4, // gpu centroids result max(std::fabs(centroids4[j].y[k]), std::fabs(centroids[i].y)); float errSize = std::abs(centroids4[j].num_points[k] - centroids[i].num_points) / - std::max(std::abs(centroids4[j].num_points[k]), - std::abs(centroids[i].num_points)); + max(std::abs(centroids4[j].num_points[k]), + std::abs(centroids[i].num_points)); // std::cout << i << ": Wanted (" << centroids[i].x << ", " << // centroids[i].y // << ", " << centroids[i].num_points << ")" << std::endl;