Debian Codegraph @

libgomp/testsuite/libgomp.c++/allocator-2.C

raw
1 // { dg-do run }
2 // { dg-additional-options "-Wno-psabi" }
3
4 #include <omp.h>
5 #include <vector>
6
7 template<typename T>
8 bool ptr_is_aligned(T *ptr, std::size_t alignment)
9 {
10 /* ALIGNMENT must be a power of 2. */
11 if ((alignment & (alignment - 1)) != 0)
12 __builtin_abort ();
13 __UINTPTR_TYPE__ ptr_value
14 = reinterpret_cast<__UINTPTR_TYPE__>(static_cast<void*>(ptr));
15 return (ptr_value % alignment) == 0;
16 }
17
18 template<typename T, template<typename> class Alloc>
19 void f (T v0, T v1, T v2, T v3)
20 {
21 std::vector<T, Alloc<T>> vec;
22 vec.push_back (v0);
23 vec.push_back (v1);
24 vec.push_back (v2);
25 vec.push_back (v3);
26 if (vec.at (0) != v0)
27 __builtin_abort ();
28 if (vec.at (1) != v1)
29 __builtin_abort ();
30 if (vec.at (2) != v2)
31 __builtin_abort ();
32 if (vec.at (3) != v3)
33 __builtin_abort ();
34 if (!ptr_is_aligned (&vec.at (0), alignof (T)))
35 __builtin_abort ();
36 if (!ptr_is_aligned (&vec.at (1), alignof (T)))
37 __builtin_abort ();
38 if (!ptr_is_aligned (&vec.at (2), alignof (T)))
39 __builtin_abort ();
40 if (!ptr_is_aligned (&vec.at (3), alignof (T)))
41 __builtin_abort ();
42 }
43
44 struct S0
45 {
46 int _v0;
47 bool _v1;
48 float _v2;
49
50 bool operator== (S0 const& other) const noexcept {
51 return _v0 == other._v0
52 && _v1 == other._v1
53 && _v2 == other._v2;
54 }
55 bool operator!= (S0 const& other) const noexcept {
56 return !this->operator==(other);
57 }
58 };
59
60 struct alignas(128) S1
61 {
62 int _v0;
63 bool _v1;
64 float _v2;
65
66 bool operator== (S1 const& other) const noexcept {
67 return _v0 == other._v0
68 && _v1 == other._v1
69 && _v2 == other._v2;
70 }
71 bool operator!= (S1 const& other) const noexcept {
72 return !this->operator==(other);
73 }
74 };
75
76 /* Note: the test for const_mem should be disabled in the future. */
77
78 int main ()
79 {
80 f<int, omp::allocator::null_allocator >(0, 1, 2, 3);
81 f<int, omp::allocator::default_mem >(0, 1, 2, 3);
82 f<int, omp::allocator::large_cap_mem >(0, 1, 2, 3);
83 f<int, omp::allocator::const_mem >(0, 1, 2, 3);
84 f<int, omp::allocator::high_bw_mem >(0, 1, 2, 3);
85 f<int, omp::allocator::low_lat_mem >(0, 1, 2, 3);
86 f<int, omp::allocator::cgroup_mem >(0, 1, 2, 3);
87 f<int, omp::allocator::pteam_mem >(0, 1, 2, 3);
88 f<int, omp::allocator::thread_mem >(0, 1, 2, 3);
89 #ifdef __gnu_linux__
90 /* Pinning not implemented on other targets. */
91 f<int, ompx::allocator::gnu_pinned_mem>(0, 1, 2, 3);
92 #endif
93
94 f<long long, omp::allocator::null_allocator >(0, 1, 2, 3);
95 f<long long, omp::allocator::default_mem >(0, 1, 2, 3);
96 f<long long, omp::allocator::large_cap_mem >(0, 1, 2, 3);
97 f<long long, omp::allocator::const_mem >(0, 1, 2, 3);
98 f<long long, omp::allocator::high_bw_mem >(0, 1, 2, 3);
99 f<long long, omp::allocator::low_lat_mem >(0, 1, 2, 3);
100 f<long long, omp::allocator::cgroup_mem >(0, 1, 2, 3);
101 f<long long, omp::allocator::pteam_mem >(0, 1, 2, 3);
102 f<long long, omp::allocator::thread_mem >(0, 1, 2, 3);
103 #ifdef __gnu_linux__
104 f<long long, ompx::allocator::gnu_pinned_mem>(0, 1, 2, 3);
105 #endif
106
107 S0 s0_0{ 42, true, 111128.f};
108 S0 s0_1{ 142, false, 11128.f};
109 S0 s0_2{ 1142, true, 1128.f};
110 S0 s0_3{11142, false, 128.f};
111 f<S0, omp::allocator::null_allocator >(s0_0, s0_1, s0_2, s0_3);
112 f<S0, omp::allocator::default_mem >(s0_0, s0_1, s0_2, s0_3);
113 f<S0, omp::allocator::large_cap_mem >(s0_0, s0_1, s0_2, s0_3);
114 f<S0, omp::allocator::const_mem >(s0_0, s0_1, s0_2, s0_3);
115 f<S0, omp::allocator::high_bw_mem >(s0_0, s0_1, s0_2, s0_3);
116 f<S0, omp::allocator::low_lat_mem >(s0_0, s0_1, s0_2, s0_3);
117 f<S0, omp::allocator::cgroup_mem >(s0_0, s0_1, s0_2, s0_3);
118 f<S0, omp::allocator::pteam_mem >(s0_0, s0_1, s0_2, s0_3);
119 f<S0, omp::allocator::thread_mem >(s0_0, s0_1, s0_2, s0_3);
120 #ifdef __gnu_linux__
121 f<S0, ompx::allocator::gnu_pinned_mem>(s0_0, s0_1, s0_2, s0_3);
122 #endif
123
124 S1 s1_0{ 42, true, 111128.f};
125 S1 s1_1{ 142, false, 11128.f};
126 S1 s1_2{ 1142, true, 1128.f};
127 S1 s1_3{11142, false, 128.f};
128
129 f<S1, omp::allocator::null_allocator >(s1_0, s1_1, s1_2, s1_3);
130 f<S1, omp::allocator::default_mem >(s1_0, s1_1, s1_2, s1_3);
131 f<S1, omp::allocator::large_cap_mem >(s1_0, s1_1, s1_2, s1_3);
132 f<S1, omp::allocator::const_mem >(s1_0, s1_1, s1_2, s1_3);
133 f<S1, omp::allocator::high_bw_mem >(s1_0, s1_1, s1_2, s1_3);
134 f<S1, omp::allocator::low_lat_mem >(s1_0, s1_1, s1_2, s1_3);
135 f<S1, omp::allocator::cgroup_mem >(s1_0, s1_1, s1_2, s1_3);
136 f<S1, omp::allocator::pteam_mem >(s1_0, s1_1, s1_2, s1_3);
137 f<S1, omp::allocator::thread_mem >(s1_0, s1_1, s1_2, s1_3);
138 #ifdef __gnu_linux__
139 f<S1, ompx::allocator::gnu_pinned_mem>(s1_0, s1_1, s1_2, s1_3);
140 #endif
141 }