================
@@ -0,0 +1,130 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+// This test checks that #pragma omp target update from(s1.data[0:6:2],
+// s2.data[0:4:3]) correctly updates strided sections covering the full arrays
+// from device to host.
+
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define LEN 12
+
+typedef struct {
+  double data[LEN];
+  int len;
+} T;
+
+int main() {
+  T s1, s2;
+  s1.len = LEN;
+  s2.len = LEN;
+
+  // Initialize struct arrays on host with simple sequential values
+  for (int i = 0; i < LEN; i++) {
+    s1.data[i] = i;
+    s2.data[i] = i;
+  }
+
+  printf("original host struct array values:\n");
+  printf("s1.data:\n");
+  for (int i = 0; i < LEN; i++)
+    printf("%.1f\n", s1.data[i]);
+  printf("s2.data:\n");
+  for (int i = 0; i < LEN; i++)
+    printf("%.1f\n", s2.data[i]);
+
+#pragma omp target data map(tofrom : s1, s2)
+  {
+// Initialize all device values to 20
+#pragma omp target map(tofrom : s1, s2)
+    {
+      for (int i = 0; i < s1.len; i++) {
+        s1.data[i] = 20.0;
+        s2.data[i] = 20.0;
+      }
+    }
+
+// Modify specific strided elements on device to 10
+#pragma omp target map(tofrom : s1, s2)
+    {
+      // s1: modify even indices (0,2,4,6,8,10)
+      for (int i = 0; i < 6; i++) {
+        s1.data[i * 2] = 10.0;
+      }
+      // s2: modify every 3rd index (0,3,6,9)
+      for (int i = 0; i < 4; i++) {
+        s2.data[i * 3] = 10.0;
+      }
+    }
+
+// s1.data[0:6:2] updates only even indices: 0,2,4,6,8,10
+// s2.data[0:4:3] updates only every 3rd: 0,3,6,9
+#pragma omp target update from(s1.data[0 : 6 : 2], s2.data[0 : 4 : 3])
----------------
amitamd7 wrote:

Thanks for pointing it. Fixed this in 2 other tests:

`offload/test/offloading/target_update_strided_struct_partial_from.c`
`offload/test/offloading/target_update_strided_struct_from.c`


https://github.com/llvm/llvm-project/pull/157443
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to