sched1: debug/model: dump predecessor list and BB num [NFC]
[gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / acc_prof-valid_bytes-1.c
blob5b58c51d4c42bbd3a6eb522b05ff47813977a55d
1 /* Test the 'valid_bytes' magic. */
3 #undef NDEBUG
4 #include <assert.h>
6 #include <acc_prof.h>
9 #define DEBUG_printf(...) //__builtin_printf (__VA_ARGS__)
12 static int ev_count_data;
14 static void cb_data_event (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info)
16 DEBUG_printf ("%s %d\n", __FUNCTION__, prof_info->event_type);
18 assert (prof_info->valid_bytes == _ACC_PROF_INFO_VALID_BYTES);
19 assert (event_info->data_event.valid_bytes == _ACC_DATA_EVENT_INFO_VALID_BYTES);
20 assert (api_info->valid_bytes == _ACC_API_INFO_VALID_BYTES);
22 ++ev_count_data;
25 static int ev_count_launch;
27 static void cb_launch_event (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info)
29 DEBUG_printf ("%s %d\n", __FUNCTION__, prof_info->event_type);
31 assert (prof_info->valid_bytes == _ACC_PROF_INFO_VALID_BYTES);
32 assert (event_info->launch_event.valid_bytes == _ACC_LAUNCH_EVENT_INFO_VALID_BYTES);
33 assert (api_info->valid_bytes == _ACC_API_INFO_VALID_BYTES);
35 ++ev_count_launch;
38 static int ev_count_other;
40 static void cb_other_event (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info)
42 DEBUG_printf ("%s %d\n", __FUNCTION__, prof_info->event_type);
44 assert (prof_info->valid_bytes == _ACC_PROF_INFO_VALID_BYTES);
45 assert (event_info->other_event.valid_bytes == _ACC_OTHER_EVENT_INFO_VALID_BYTES);
46 assert (api_info->valid_bytes == _ACC_API_INFO_VALID_BYTES);
48 ++ev_count_other;
52 void acc_register_library (acc_prof_reg reg_, acc_prof_reg unreg_, acc_prof_lookup_func lookup_)
54 DEBUG_printf ("%s\n", __FUNCTION__);
56 reg_ (acc_ev_device_init_start, cb_other_event, acc_reg);
57 reg_ (acc_ev_device_init_end, cb_other_event, acc_reg);
58 reg_ (acc_ev_device_shutdown_start, cb_other_event, acc_reg);
59 reg_ (acc_ev_device_shutdown_end, cb_other_event, acc_reg);
60 reg_ (acc_ev_runtime_shutdown, cb_other_event, acc_reg);
61 reg_ (acc_ev_create, cb_data_event, acc_reg);
62 reg_ (acc_ev_delete, cb_data_event, acc_reg);
63 reg_ (acc_ev_alloc, cb_data_event, acc_reg);
64 reg_ (acc_ev_free, cb_data_event, acc_reg);
65 reg_ (acc_ev_enter_data_start, cb_other_event, acc_reg);
66 reg_ (acc_ev_enter_data_end, cb_other_event, acc_reg);
67 reg_ (acc_ev_exit_data_start, cb_other_event, acc_reg);
68 reg_ (acc_ev_exit_data_end, cb_other_event, acc_reg);
69 reg_ (acc_ev_update_start, cb_other_event, acc_reg);
70 reg_ (acc_ev_update_end, cb_other_event, acc_reg);
71 reg_ (acc_ev_compute_construct_start, cb_other_event, acc_reg);
72 reg_ (acc_ev_compute_construct_end, cb_other_event, acc_reg);
73 reg_ (acc_ev_enqueue_launch_start, cb_launch_event, acc_reg);
74 reg_ (acc_ev_enqueue_launch_end, cb_launch_event, acc_reg);
75 reg_ (acc_ev_enqueue_upload_start, cb_data_event, acc_reg);
76 reg_ (acc_ev_enqueue_upload_end, cb_data_event, acc_reg);
77 reg_ (acc_ev_enqueue_download_start, cb_data_event, acc_reg);
78 reg_ (acc_ev_enqueue_download_end, cb_data_event, acc_reg);
79 reg_ (acc_ev_wait_start, cb_other_event, acc_reg);
80 reg_ (acc_ev_wait_end, cb_other_event, acc_reg);
84 /* Basic struct. */
85 typedef struct A
87 int a;
88 int b;
89 #define VALID_BYTES_A \
90 _ACC_PROF_VALID_BYTES_STRUCT (A, b, \
91 _ACC_PROF_VALID_BYTES_BASICTYPE (int))
92 } A;
94 /* Add a 'char' field. */
95 typedef struct B
97 int a;
98 int b;
99 char c;
100 #define VALID_BYTES_B \
101 _ACC_PROF_VALID_BYTES_STRUCT (B, c, \
102 _ACC_PROF_VALID_BYTES_BASICTYPE (char))
103 } B;
105 /* Add another 'char' field. */
106 typedef struct C
108 int a;
109 int b;
110 char c, d;
111 #define VALID_BYTES_C \
112 _ACC_PROF_VALID_BYTES_STRUCT (C, d, \
113 _ACC_PROF_VALID_BYTES_BASICTYPE (char))
114 } C;
116 /* Add two 'void *' fields. */
117 typedef struct D
119 int a;
120 int b;
121 char c, d;
122 void *e;
123 void *f;
124 #define VALID_BYTES_D \
125 _ACC_PROF_VALID_BYTES_STRUCT (D, f, \
126 _ACC_PROF_VALID_BYTES_BASICTYPE (void *))
127 } D;
129 /* Add another three 'char' fields. */
130 typedef struct E
132 int a;
133 int b;
134 char c, d;
135 void *e;
136 void *f;
137 char g, h, i;
138 #define VALID_BYTES_E \
139 _ACC_PROF_VALID_BYTES_STRUCT (E, i, \
140 _ACC_PROF_VALID_BYTES_BASICTYPE (char))
141 } E;
144 int main()
146 acc_register_library (acc_prof_register, acc_prof_unregister, acc_prof_lookup);
148 A A1;
149 DEBUG_printf ("s=%zd, vb=%zd\n", sizeof A1, VALID_BYTES_A);
150 assert (VALID_BYTES_A <= sizeof A1);
151 DEBUG_printf ("&A1=%p, &A1.b=%p\n", &A1, &A1.b);
152 assert (((char *) &A1) + VALID_BYTES_A == (char *) (&A1.b + 1));
154 B B1;
155 DEBUG_printf ("s=%zd, vb=%zd\n", sizeof B1, VALID_BYTES_B);
156 assert (VALID_BYTES_B <= sizeof B1);
157 DEBUG_printf ("&B1=%p, &B1.c=%p\n", &B1, &B1.c);
158 assert (((char *) &B1) + VALID_BYTES_B == (char *) (&B1.c + 1));
160 assert (VALID_BYTES_B == VALID_BYTES_A + 1 * sizeof (char));
162 C C1;
163 DEBUG_printf ("s=%zd, vb=%zd\n", sizeof C1, VALID_BYTES_C);
164 assert (VALID_BYTES_C <= sizeof C1);
165 DEBUG_printf ("&C1=%p, &C1.d=%p\n", &C1, &C1.d);
166 assert (((char *) &C1) + VALID_BYTES_C == (char *) (&C1.d + 1));
168 assert (VALID_BYTES_C == VALID_BYTES_B + 1 * sizeof (char));
170 D D1;
171 DEBUG_printf ("s=%zd, vb=%zd\n", sizeof D1, VALID_BYTES_D);
172 assert (VALID_BYTES_D <= sizeof D1);
173 DEBUG_printf ("&D1=%p, &D1.f=%p\n", &D1, &D1.f);
174 assert (((char *) &D1) + VALID_BYTES_D == (char *) (&D1.f + 1));
176 assert (VALID_BYTES_D > VALID_BYTES_C);
178 E E1;
179 DEBUG_printf ("s=%zd, vb=%zd\n", sizeof E1, VALID_BYTES_E);
180 assert (VALID_BYTES_E <= sizeof E1);
181 DEBUG_printf ("&E1=%p, &E1.i=%p\n", &E1, &E1.i);
182 assert (((char *) &E1) + VALID_BYTES_E == (char *) (&E1.i + 1));
184 assert (VALID_BYTES_E == VALID_BYTES_D + 3 * sizeof (char));
186 ev_count_data = 0;
187 ev_count_launch = 0;
188 ev_count_other = 0;
190 /* Trigger tests done in 'cb_*' functions. */
191 int host;
192 #pragma acc parallel copyout (host)
194 asm volatile ("" : : : "memory"); // TODO PR90488
196 host = acc_on_device (acc_device_host);
199 DEBUG_printf ("ev_count_data = %d\n", ev_count_data);
200 if (host)
201 assert (ev_count_data == 0);
202 else
204 /* We don't know exactly how many data events to expect, but we at least
205 expect some. */
206 assert (ev_count_data > 0);
209 DEBUG_printf ("ev_count_launch = %d\n", ev_count_launch);
210 if (host)
211 assert (ev_count_data == 0);
212 else
214 /* We expect two launch events, 'acc_ev_enqueue_launch_start',
215 'acc_ev_enqueue_launch_end'. */
216 assert (ev_count_launch == 2);
219 DEBUG_printf ("ev_count_other = %d\n", ev_count_other);
220 /* We don't know exactly how many other events to expect, but we at least
221 expect 'acc_ev_device_init_start', 'acc_ev_device_init_end',
222 'acc_ev_compute_construct_start', 'acc_ev_compute_construct_end'. */
223 assert (ev_count_other >= 4);
225 return 0;