[Openmp-commits] [clang] [openmp] [OpenMP][SIMD][FIX] Use conservative "omp simd ordered" lowering (PR #126172)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Feb 6 19:07:20 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 07d496538f5543a8eed5e207148e28e358b7cca4 db39bc22eaf30a479686fb065acba4d676b034a9 --extensions cpp,c -- openmp/runtime/test/misc_bugs/simd_conservative_ordered.c clang/lib/CodeGen/CGStmtOpenMP.cpp clang/test/OpenMP/ordered_codegen.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/openmp/runtime/test/misc_bugs/simd_conservative_ordered.c b/openmp/runtime/test/misc_bugs/simd_conservative_ordered.c
index 40d4203ac4..af0fa66eee 100644
--- a/openmp/runtime/test/misc_bugs/simd_conservative_ordered.c
+++ b/openmp/runtime/test/misc_bugs/simd_conservative_ordered.c
@@ -7,77 +7,78 @@
#include <time.h>
int compare_float(float x1, float x2, float scalar) {
- const float diff = fabsf(x1 - x2);
- x1 = fabsf(x1);
- x2 = fabsf(x2);
- const float l = (x2 > x1) ? x2 : x1;
- if (diff <= l * scalar * FLT_EPSILON)
- return 1;
- else
- return 0;
+ const float diff = fabsf(x1 - x2);
+ x1 = fabsf(x1);
+ x2 = fabsf(x2);
+ const float l = (x2 > x1) ? x2 : x1;
+ if (diff <= l * scalar * FLT_EPSILON)
+ return 1;
+ else
+ return 0;
}
#define ARRAY_SIZE 256
-__attribute__((noinline)) void initialization_loop(
- float X[ARRAY_SIZE][ARRAY_SIZE], float Y[ARRAY_SIZE][ARRAY_SIZE]) {
- const float max = 1000.0;
- srand(time(NULL));
- for (int r = 0; r < ARRAY_SIZE; r++) {
- for (int c = 0; c < ARRAY_SIZE; c++) {
- X[r][c] = ((float)rand() / (float)(RAND_MAX)) * max;
- Y[r][c] = X[r][c];
- }
+__attribute__((noinline)) void
+initialization_loop(float X[ARRAY_SIZE][ARRAY_SIZE],
+ float Y[ARRAY_SIZE][ARRAY_SIZE]) {
+ const float max = 1000.0;
+ srand(time(NULL));
+ for (int r = 0; r < ARRAY_SIZE; r++) {
+ for (int c = 0; c < ARRAY_SIZE; c++) {
+ X[r][c] = ((float)rand() / (float)(RAND_MAX)) * max;
+ Y[r][c] = X[r][c];
}
+ }
}
__attribute__((noinline)) void omp_simd_loop(float X[ARRAY_SIZE][ARRAY_SIZE]) {
- for (int r = 1; r < ARRAY_SIZE; ++r) {
- for (int c = 1; c < ARRAY_SIZE; ++c) {
+ for (int r = 1; r < ARRAY_SIZE; ++r) {
+ for (int c = 1; c < ARRAY_SIZE; ++c) {
#pragma omp simd
- for (int k = 2; k < ARRAY_SIZE; ++k) {
+ for (int k = 2; k < ARRAY_SIZE; ++k) {
#pragma omp ordered simd
- X[r][k] = X[r][k - 2] + sinf((float)(r / c));
- }
- }
+ X[r][k] = X[r][k - 2] + sinf((float)(r / c));
+ }
}
+ }
}
__attribute__((noinline)) int comparison_loop(float X[ARRAY_SIZE][ARRAY_SIZE],
float Y[ARRAY_SIZE][ARRAY_SIZE]) {
- int totalErrors_simd = 0;
- const float scalar = 1.0;
- for (int r = 1; r < ARRAY_SIZE; ++r) {
- for (int c = 1; c < ARRAY_SIZE; ++c) {
- for (int k = 2; k < ARRAY_SIZE; ++k) {
- Y[r][k] = Y[r][k - 2] + sinf((float)(r / c));
- }
- }
- // check row for simd update
- for (int k = 0; k < ARRAY_SIZE; ++k) {
- if (!compare_float(X[r][k], Y[r][k], scalar)) {
- ++totalErrors_simd;
- }
- }
+ int totalErrors_simd = 0;
+ const float scalar = 1.0;
+ for (int r = 1; r < ARRAY_SIZE; ++r) {
+ for (int c = 1; c < ARRAY_SIZE; ++c) {
+ for (int k = 2; k < ARRAY_SIZE; ++k) {
+ Y[r][k] = Y[r][k - 2] + sinf((float)(r / c));
+ }
}
- return totalErrors_simd;
+ // check row for simd update
+ for (int k = 0; k < ARRAY_SIZE; ++k) {
+ if (!compare_float(X[r][k], Y[r][k], scalar)) {
+ ++totalErrors_simd;
+ }
+ }
+ }
+ return totalErrors_simd;
}
int main(void) {
- float X[ARRAY_SIZE][ARRAY_SIZE];
- float Y[ARRAY_SIZE][ARRAY_SIZE];
+ float X[ARRAY_SIZE][ARRAY_SIZE];
+ float Y[ARRAY_SIZE][ARRAY_SIZE];
- initialization_loop(X, Y);
- omp_simd_loop(X);
- const int totalErrors_simd = comparison_loop(X, Y);
+ initialization_loop(X, Y);
+ omp_simd_loop(X);
+ const int totalErrors_simd = comparison_loop(X, Y);
- if (totalErrors_simd) {
- fprintf(stdout, "totalErrors_simd: %d \n", totalErrors_simd);
- fprintf(stdout, "%s : %d - FAIL: error in ordered simd computation.\n",
- __FILE__, __LINE__);
- } else {
- fprintf(stdout, "Success!\n");
- }
+ if (totalErrors_simd) {
+ fprintf(stdout, "totalErrors_simd: %d \n", totalErrors_simd);
+ fprintf(stdout, "%s : %d - FAIL: error in ordered simd computation.\n",
+ __FILE__, __LINE__);
+ } else {
+ fprintf(stdout, "Success!\n");
+ }
- return totalErrors_simd;
+ return totalErrors_simd;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/126172
More information about the Openmp-commits
mailing list