Skip to content

Commit d740866

Browse files
committed
non-contiguous_update_to_tests
1 parent 97732dd commit d740866

12 files changed

+354
-40
lines changed

clang/test/OpenMP/target_update_strided_messages.c renamed to clang/test/OpenMP/target_update_strided_messages_from.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
22
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
33

4-
void foo(void) {}
5-
64
int main(int argc, char **argv) {
75
int len = 8;
86
double data[len];
@@ -11,9 +9,6 @@ int main(int argc, char **argv) {
119
#pragma omp target update from(data[0:4:2]) // OK
1210
{}
1311

14-
#pragma omp target update to(data[0:len/2:2]) // OK
15-
{}
16-
1712
#pragma omp target update from(data[1:3:2]) // OK
1813
{}
1914

@@ -35,4 +30,4 @@ int main(int argc, char **argv) {
3530
{}
3631

3732
return 0;
38-
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
2+
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
3+
4+
int main(int argc, char **argv) {
5+
int len = 8;
6+
double data[len];
7+
8+
// Valid strided array sections
9+
#pragma omp target update to(data[0:4:2]) // OK
10+
{}
11+
12+
#pragma omp target update to(data[1:3:2]) // OK
13+
{}
14+
15+
// Missing stride (default = 1)
16+
#pragma omp target update to(data[0:4]) // OK
17+
{}
18+
19+
// Invalid stride expressions
20+
#pragma omp target update to(data[0:4:0]) // expected-error {{section stride is evaluated to a non-positive value 0}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
21+
22+
#pragma omp target update to(data[0:4:-1]) // expected-error {{section stride is evaluated to a non-positive value -1}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
23+
24+
// Missing colon
25+
#pragma omp target update to(data[0:4 2]) // expected-error {{expected ']'}} expected-note {{to match this '['}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
26+
{}
27+
28+
// Too many colons
29+
#pragma omp target update to(data[0:4:2:1]) // expected-error {{expected ']'}} expected-note {{to match this '['}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
30+
{}
31+
32+
return 0;
33+
}
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,23 @@
11
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
22
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
33

4-
void foo(void) {}
5-
6-
typedef struct {
7-
int len;
8-
double data[12];
9-
} S;
10-
114
int main(int argc, char **argv) {
125
int len = 12;
136
double data1[len], data2[len];
14-
S s;
157

168
// Valid multiple strided array sections
179
#pragma omp target update from(data1[0:4:2], data2[0:2:5]) // OK
1810
{}
1911

20-
#pragma omp target update to(data1[1:2:3], data2[2:3:2]) // OK
21-
{}
22-
2312
// Mixed strided and regular array sections
2413
#pragma omp target update from(data1[0:len], data2[0:4:2]) // OK
2514
{}
2615

27-
// Struct member arrays with strides
28-
#pragma omp target update from(s.data[0:4:2]) // OK
29-
{}
30-
31-
#pragma omp target update from(s.data[0:s.len/2:2]) // OK
32-
{}
33-
3416
// Invalid stride in one of multiple sections
3517
#pragma omp target update from(data1[0:3:4], data2[0:2:0]) // expected-error {{section stride is evaluated to a non-positive value 0}}
3618

37-
// Complex expressions in multiple arrays
38-
int stride1 = 2, stride2 = 3;
39-
#pragma omp target update from(data1[0:len/2:stride1], data2[1:len/3:stride2]) // OK
40-
{}
41-
4219
// Missing colon
4320
#pragma omp target update from(data1[0:4:2], data2[0:3 4]) // expected-error {{expected ']'}} expected-note {{to match this '['}}
4421

4522
return 0;
46-
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
2+
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
3+
4+
int main(int argc, char **argv) {
5+
int len = 12;
6+
double data1[len], data2[len];
7+
8+
// Valid multiple strided array sections
9+
#pragma omp target update to(data1[0:4:2], data2[0:2:5]) // OK
10+
{}
11+
12+
// Mixed strided and regular array sections
13+
#pragma omp target update to(data1[0:len], data2[0:4:2]) // OK
14+
{}
15+
16+
// Invalid stride in one of multiple sections
17+
#pragma omp target update to(data1[0:3:4], data2[0:2:0]) // expected-error {{section stride is evaluated to a non-positive value 0}}
18+
{}
19+
20+
// Missing colon
21+
#pragma omp target update to(data1[0:4:2], data2[0:3 4]) // expected-error {{expected ']'}} expected-note {{to match this '['}}
22+
{}
23+
24+
return 0;
25+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
22
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
3-
4-
void foo(void) {}
3+
// expected-no-diagnostics
54

65
int main(int argc, char **argv) {
76
int len = 11;
@@ -17,16 +16,10 @@ int main(int argc, char **argv) {
1716

1817
// Valid: complex expressions
1918
int offset = 1;
20-
int count = 3;
21-
int stride = 2;
22-
#pragma omp target update from(data[offset:count:stride]) // OK
23-
{}
24-
19+
2520
// Invalid stride expressions
2621
#pragma omp target update from(data[0:4:offset-1]) // OK if offset > 1
2722
{}
2823

29-
#pragma omp target update from(data[0:count:0]) // expected-error {{section stride is evaluated to a non-positive value 0}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
30-
3124
return 0;
32-
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
2+
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
3+
// expected-no-diagnostics
4+
5+
int main(int argc, char **argv) {
6+
int len = 11;
7+
double data[len];
8+
9+
// Valid partial strided updates
10+
#pragma omp target update to(data[0:4:3]) // OK
11+
{}
12+
13+
// Stride larger than length
14+
#pragma omp target update to(data[0:2:10]) // OK
15+
{}
16+
17+
// Valid: complex expressions
18+
int offset = 1;
19+
20+
// Potentially invalid stride expressions depending on runtime values
21+
#pragma omp target update to(data[0:4:offset-1]) // OK if offset > 1
22+
{}
23+
24+
return 0;
25+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// This test checks that #pragma omp target update to(data1[0:3:4],
2+
// data2[0:2:5]) correctly updates disjoint strided sections of multiple arrays
3+
// from the host to the device.
4+
5+
// RUN: %libomptarget-compile-run-and-check-generic
6+
#include <omp.h>
7+
#include <stdio.h>
8+
9+
int main() {
10+
int len = 12;
11+
double data1[len], data2[len];
12+
13+
// Initialize host arrays
14+
for (int i = 0; i < len; i++) {
15+
data1[i] = i;
16+
data2[i] = i * 10;
17+
}
18+
19+
printf("original host array values:\n");
20+
printf("data1:\n");
21+
for (int i = 0; i < len; i++)
22+
printf("%.1f\n", data1[i]);
23+
printf("data2:\n");
24+
for (int i = 0; i < len; i++)
25+
printf("%.1f\n", data2[i]);
26+
27+
// CHECK: original host array values:
28+
// CHECK-NEXT: data1:
29+
// CHECK-NEXT: 0.0
30+
// CHECK-NEXT: 1.0
31+
// CHECK-NEXT: 2.0
32+
// CHECK-NEXT: 3.0
33+
// CHECK-NEXT: 4.0
34+
// CHECK-NEXT: 5.0
35+
// CHECK-NEXT: 6.0
36+
// CHECK-NEXT: 7.0
37+
// CHECK-NEXT: 8.0
38+
// CHECK-NEXT: 9.0
39+
// CHECK-NEXT: 10.0
40+
// CHECK-NEXT: 11.0
41+
// CHECK-NEXT: data2:
42+
// CHECK-NEXT: 0.0
43+
// CHECK-NEXT: 10.0
44+
// CHECK-NEXT: 20.0
45+
// CHECK-NEXT: 30.0
46+
// CHECK-NEXT: 40.0
47+
// CHECK-NEXT: 50.0
48+
// CHECK-NEXT: 60.0
49+
// CHECK-NEXT: 70.0
50+
// CHECK-NEXT: 80.0
51+
// CHECK-NEXT: 90.0
52+
// CHECK-NEXT: 100.0
53+
// CHECK-NEXT: 110.0
54+
55+
#pragma omp target data map(tofrom : data1[0 : len], data2[0 : len])
56+
{
57+
// Initialize device arrays to 20
58+
#pragma omp target
59+
{
60+
for (int i = 0; i < len; i++) {
61+
data1[i] = 20.0;
62+
data2[i] = 20.0;
63+
}
64+
}
65+
66+
// Modify host arrays for strided elements
67+
data1[0] = 10.0;
68+
data1[4] = 10.0;
69+
data1[8] = 10.0;
70+
data2[0] = 10.0;
71+
data2[5] = 10.0;
72+
73+
// data1[0:3:4] // indices 0,4,8
74+
// data2[0:2:5] // indices 0,5
75+
#pragma omp target update to(data1[0 : 3 : 4], data2[0 : 2 : 5])
76+
77+
// Verify on device by adding 5
78+
#pragma omp target
79+
{
80+
for (int i = 0; i < len; i++)
81+
data1[i] += 5.0;
82+
for (int i = 0; i < len; i++)
83+
data2[i] += 5.0;
84+
}
85+
}
86+
87+
printf("device array values after update to:\n");
88+
printf("data1:\n");
89+
for (int i = 0; i < len; i++)
90+
printf("%.1f\n", data1[i]);
91+
printf("data2:\n");
92+
for (int i = 0; i < len; i++)
93+
printf("%.1f\n", data2[i]);
94+
95+
// CHECK: device array values after update to:
96+
// CHECK-NEXT: data1:
97+
// CHECK-NEXT: 15.0
98+
// CHECK-NEXT: 25.0
99+
// CHECK-NEXT: 25.0
100+
// CHECK-NEXT: 25.0
101+
// CHECK-NEXT: 15.0
102+
// CHECK-NEXT: 25.0
103+
// CHECK-NEXT: 25.0
104+
// CHECK-NEXT: 25.0
105+
// CHECK-NEXT: 15.0
106+
// CHECK-NEXT: 25.0
107+
// CHECK-NEXT: 25.0
108+
// CHECK-NEXT: 25.0
109+
// CHECK-NEXT: data2:
110+
// CHECK-NEXT: 15.0
111+
// CHECK-NEXT: 25.0
112+
// CHECK-NEXT: 25.0
113+
// CHECK-NEXT: 25.0
114+
// CHECK-NEXT: 25.0
115+
// CHECK-NEXT: 15.0
116+
// CHECK-NEXT: 25.0
117+
// CHECK-NEXT: 25.0
118+
// CHECK-NEXT: 25.0
119+
// CHECK-NEXT: 25.0
120+
// CHECK-NEXT: 25.0
121+
// CHECK-NEXT: 25.0
122+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This test checks that #pragma omp target update to(data[0:4:3]) correctly
2+
// updates every third element (stride 3) from the host to the device, partially
3+
// across the array
4+
5+
// RUN: %libomptarget-compile-run-and-check-generic
6+
#include <omp.h>
7+
#include <stdio.h>
8+
9+
int main() {
10+
int len = 11;
11+
double data[len];
12+
13+
// Initialize on host
14+
for (int i = 0; i < len; i++)
15+
data[i] = i;
16+
17+
// Initial values
18+
printf("original host array values:\n");
19+
for (int i = 0; i < len; i++)
20+
printf("%f\n", data[i]);
21+
printf("\n");
22+
23+
// CHECK: 0.000000
24+
// CHECK: 1.000000
25+
// CHECK: 2.000000
26+
// CHECK: 3.000000
27+
// CHECK: 4.000000
28+
// CHECK: 5.000000
29+
// CHECK: 6.000000
30+
// CHECK: 7.000000
31+
// CHECK: 8.000000
32+
// CHECK: 9.000000
33+
// CHECK: 10.000000
34+
35+
#pragma omp target data map(tofrom : data[0 : len])
36+
{
37+
// Initialize device array to 20
38+
#pragma omp target
39+
for (int i = 0; i < len; i++)
40+
data[i] = 20.0;
41+
42+
// Modify host data for strided elements
43+
data[0] = 10.0;
44+
data[3] = 10.0;
45+
data[6] = 10.0;
46+
data[9] = 10.0;
47+
48+
#pragma omp target update to(data[0 : 4 : 3]) // indices 0,3,6,9
49+
50+
// Verify on device by adding 5
51+
#pragma omp target
52+
for (int i = 0; i < len; i++)
53+
data[i] += 5.0;
54+
}
55+
56+
printf("device array values after update to:\n");
57+
for (int i = 0; i < len; i++)
58+
printf("%f\n", data[i]);
59+
printf("\n");
60+
61+
// CHECK: 15.000000
62+
// CHECK: 25.000000
63+
// CHECK: 25.000000
64+
// CHECK: 15.000000
65+
// CHECK: 25.000000
66+
// CHECK: 25.000000
67+
// CHECK: 15.000000
68+
// CHECK: 25.000000
69+
// CHECK: 25.000000
70+
// CHECK: 15.000000
71+
// CHECK: 25.000000
72+
}

0 commit comments

Comments
 (0)