Debian Codegraph @

libgomp/testsuite/libgomp.c++/target-map-class-1.C

raw
1 /* PR middle-end/109816 */
2
3 /* This variant: without -flto, see target-map-class-2.C for -flto. */
4
5 /* iostream.h adds 'globl _ZSt21ios_base_library_initv' with _GLIBCXX_SYMVER_GNU,
6 but it shouldn't end up in the offload assembly but only in the host assembly. */
7
8 /* Example based on sollve_vv's test_target_data_map_classes.cpp; however,
9 relevant is only the 'include' and not the actual executable code. */
10
11 #include <iostream>
12 #include <omp.h>
13
14 using namespace std;
15
16 #define N 1000
17
18 struct A
19 {
20 int *h_array;
21 int size, sum;
22
23 A (int *array, const int s) : h_array(array), size(s), sum(0) { }
24 ~A() { h_array = NULL; }
25 };
26
27 void
28 test_map_tofrom_class_heap ()
29 {
30 int *array = new int[N];
31 A *obj = new A (array, N);
32
33 #pragma omp target map(from: array[:N]) map(tofrom: obj[:1])
34 {
35 int *tmp_h_array = obj->h_array;
36 obj->h_array = array;
37 int tmp = 0;
38 for (int i = 0; i < N; ++i)
39 {
40 obj->h_array[i] = 4*i;
41 tmp += 3;
42 }
43 obj->h_array = tmp_h_array;
44 obj->sum = tmp;
45 }
46
47 for (int i = 0; i < N; ++i)
48 if (obj->h_array[i] != 4*i)
49 __builtin_abort ();
50
51 if (3*N != obj->sum)
52 {
53 std::cout << "sum: " << obj->sum << std::endl;
54 __builtin_abort ();
55 }
56
57 delete obj;
58 delete[] array;
59 }
60
61 void
62 test_map_tofrom_class_stack ()
63 {
64 int array[N];
65 A obj(array, N);
66
67 #pragma omp target map(from: array[:N]) map(tofrom: obj)
68 {
69 int *tmp_h_array = obj.h_array;
70 obj.h_array = array;
71 int tmp = 0;
72 for (int i = 0; i < N; ++i)
73 {
74 obj.h_array[i] = 7*i;
75 tmp += 5;
76 }
77 obj.h_array = tmp_h_array;
78 obj.sum = tmp;
79 }
80
81 for (int i = 0; i < N; ++i)
82 if (obj.h_array[i] != 7*i)
83 __builtin_abort ();
84
85 if (5*N != obj.sum)
86 {
87 std::cout << "sum: " << obj.sum << std::endl;
88 __builtin_abort ();
89 }
90 }
91
92 int
93 main()
94 {
95 test_map_tofrom_class_heap();
96 test_map_tofrom_class_stack();
97 return 0;
98 }