[Openmp-commits] [PATCH] D158736: [OpenMP][AA][NFC] Add passing test from issue 64797

Gheorghe-Teodor Bercea via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 24 07:18:47 PDT 2023


doru1004 created this revision.
doru1004 added reviewers: jdoerfert, ronl, carlo.bertolli.
doru1004 added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
doru1004 requested review of this revision.
Herald added subscribers: openmp-commits, jplehr, sstefan1.

This test is fixed by commit:
https://reviews.llvm.org/rG78b8f1f78f1203baf56b2b25a9dc41b90cf0957b

the following issue was happening:
https://github.com/llvm/llvm-project/issues/64797


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158736

Files:
  openmp/libomptarget/test/offloading/back2back_distribute.c


Index: openmp/libomptarget/test/offloading/back2back_distribute.c
===================================================================
--- /dev/null
+++ openmp/libomptarget/test/offloading/back2back_distribute.c
@@ -0,0 +1,75 @@
+// RUN: %libomptarget-compile-generic -O3 && %libomptarget-run-generic | %fcheck-generic
+
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_N 25000
+
+void reset_input(double *a, double *a_h, double *b, double *c) {
+  for(int i = 0 ; i < MAX_N ; i++) {
+    a[i] = a_h[i] = i;
+    b[i] = i*2;
+    c[i] = i-3;
+  }
+}
+
+int main(int argc, char *argv[]) {
+  double * a = (double *) malloc(MAX_N * sizeof(double));
+  double * a_h = (double *) malloc(MAX_N * sizeof(double));
+  double * d = (double *) malloc(MAX_N * sizeof(double));
+  double * d_h = (double *) malloc(MAX_N * sizeof(double));
+  double * b = (double *) malloc(MAX_N * sizeof(double));
+  double * c = (double *) malloc(MAX_N * sizeof(double));
+
+#pragma omp target enter data map(to:a[:MAX_N],b[:MAX_N],c[:MAX_N],d[:MAX_N])
+
+  for (int n = 32 ; n < 33 ; n+=5000) {
+    reset_input(a, a_h, b, c);
+
+#pragma omp target update to(a[:n],b[:n],c[:n],d[:n])
+    int t = 0;
+    for (int tms = 256 ; tms <= 256 ; tms *= 2) { // 8 times
+      for (int ths = 1024 ; ths <= 1024 ; ths *= 2) { // 6 times
+        t++;
+#pragma omp target
+#pragma omp teams num_teams(tms) thread_limit(ths)
+        {
+#pragma omp distribute parallel for
+          for (int i = 0; i < n; ++i) {
+            a[i] += b[i] + c[i];
+          }
+#pragma omp distribute parallel for
+          for (int i = 0; i < n; ++i) {
+           d[i] -= b[i] + c[i];
+          }
+        }
+      } // loop over 'ths'
+    } // loop over 'tms'
+
+    // check results for each 'n'
+    for (int times = 0 ; times < t ; times++) {
+      for (int i = 0; i < n; ++i) {
+        a_h[i] += b[i] + c[i];
+      }
+      for (int i = 0; i < n; ++i)
+        d_h[i] -= b[i] + c[i];
+    }
+#pragma omp target update from(a[:n],d[:n])
+
+    for (int i = 0; i < n; ++i) {
+      if (a_h[i] != a[i]) {
+        printf("A Error at n = %d, i = %d: host = %f, device = %f\n", n, i, a_h[i], a[i]);
+        return 1;
+      }
+      if (d_h[i] != d[i]) {
+        printf("D Error at n = %d, i = %d: host = %lf, device = %lf\n", n, i, d_h[i], d[i]);
+        return 1;
+      }
+    }
+  } // loop over 'n'
+
+  // CHECK: Succeeded
+  printf("Succeeded\n");
+  return 0;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158736.553116.patch
Type: text/x-patch
Size: 2454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230824/a2c7fd99/attachment-0001.bin>


More information about the Openmp-commits mailing list