1 /* Test dispatch of events to callbacks. */
9 /* Use explicit 'copyin' clauses, to work around "'firstprivate'
10 optimizations", which will cause the value at the point of call to be used
11 (*before* any potential modifications done in callbacks), as opposed to its
12 address being taken, which then later gets dereferenced (*after* any
13 modifications done in callbacks). */
14 #define COPYIN(...) copyin(__VA_ARGS__)
17 #define DEBUG_printf(...) //__builtin_printf (__VA_ARGS__)
20 static int state
= -1;
22 #define STATE_OP(state, op) \
25 typeof (state) state_o = (state); \
28 DEBUG_printf("state: %d -> %d\n", state_o, (state)); \
33 static void cb_compute_construct_start_1 (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
35 DEBUG_printf ("%s\n", __FUNCTION__
);
48 static void cb_compute_construct_start_2 (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
50 DEBUG_printf ("%s\n", __FUNCTION__
);
62 static void cb_compute_construct_end_1 (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
64 DEBUG_printf ("%s\n", __FUNCTION__
);
76 static void cb_compute_construct_end_2 (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
78 DEBUG_printf ("%s\n", __FUNCTION__
);
87 static void cb_compute_construct_end_3 (acc_prof_info
*prof_info
, acc_event_info
*event_info
, acc_api_info
*api_info
)
89 DEBUG_printf ("%s\n", __FUNCTION__
);
102 static acc_prof_reg reg
;
103 static acc_prof_reg unreg
;
104 static acc_prof_lookup_func lookup
;
105 void acc_register_library (acc_prof_reg reg_
, acc_prof_reg unreg_
, acc_prof_lookup_func lookup_
)
107 DEBUG_printf ("%s\n", __FUNCTION__
);
117 acc_register_library (acc_prof_register
, acc_prof_unregister
, acc_prof_lookup
);
119 STATE_OP (state
, = 0);
120 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
121 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
122 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_2
, acc_reg
);
125 #pragma acc parallel COPYIN(state) copyout(state_init)
129 assert (state_init
== 2);
133 STATE_OP (state
, = 10);
134 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_reg
);
135 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
136 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
137 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
138 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
139 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
142 #pragma acc parallel COPYIN(state) copyout(state_init)
146 assert (state_init
== 12);
148 assert (state
== 15);
150 STATE_OP (state
, = 20);
151 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_toggle
);
152 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_2
, acc_toggle
);
153 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
154 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_2
, acc_reg
);
155 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_toggle
);
156 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_toggle
);
157 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_toggle
);
158 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
159 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
160 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_toggle
);
161 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_toggle
);
164 #pragma acc parallel COPYIN(state) copyout(state_init)
168 assert (state_init
== 20);
170 assert (state
== 20);
172 STATE_OP (state
, = 30);
173 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_toggle
);
174 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_2
, acc_toggle
);
175 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_toggle
);
176 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_toggle
);
177 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_toggle
);
180 #pragma acc parallel COPYIN(state) copyout(state_init)
184 assert (state_init
== 31);
186 assert (state
== 33);
188 STATE_OP (state
, = 40);
189 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_2
, acc_reg
);
190 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
191 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
192 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
193 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
194 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
195 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_reg
);
196 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_reg
);
199 #pragma acc parallel COPYIN(state) copyout(state_init)
203 assert (state_init
== 42);
205 assert (state
== 45);
207 STATE_OP (state
, = 50);
208 unreg (acc_ev_compute_construct_end
, NULL
, acc_toggle
);
211 #pragma acc parallel COPYIN(state) copyout(state_init)
215 assert (state_init
== 52);
217 assert (state
== 52);
219 STATE_OP (state
, = 60);
220 unreg (acc_ev_compute_construct_end
, NULL
, acc_toggle
);
221 unreg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
222 unreg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
225 #pragma acc parallel COPYIN(state) copyout(state_init)
229 assert (state_init
== 60);
231 assert (state
== 60);
233 STATE_OP (state
, = 70);
234 unreg (acc_ev_compute_construct_start
, NULL
, acc_toggle
);
235 reg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
238 #pragma acc parallel COPYIN(state) copyout(state_init)
242 assert (state_init
== 70);
244 assert (state
== 70);
246 STATE_OP (state
, = 80);
247 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
248 reg (acc_ev_compute_construct_end
, NULL
, acc_toggle
);
249 reg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
252 #pragma acc parallel COPYIN(state) copyout(state_init)
256 assert (state_init
== 80);
258 assert (state
== 82);
260 STATE_OP (state
, = 90);
261 reg (acc_ev_compute_construct_start
, NULL
, acc_toggle
);
262 unreg (acc_ev_compute_construct_end
, NULL
, acc_toggle
);
263 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_2
, acc_reg
);
266 #pragma acc parallel COPYIN(state) copyout(state_init)
270 assert (state_init
== 92);
272 assert (state
== 92);
274 STATE_OP (state
, = 100);
275 reg (acc_ev_compute_construct_end
, NULL
, acc_toggle
);
278 #pragma acc parallel COPYIN(state) copyout(state_init)
282 assert (state_init
== 102);
284 assert (state
== 105);
286 STATE_OP (state
, = 110);
287 unreg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle
);
288 unreg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle
);
291 #pragma acc parallel COPYIN(state) copyout(state_init)
295 assert (state_init
== 110);
297 assert (state
== 110);
299 STATE_OP (state
, = 120);
300 unreg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
303 #pragma acc parallel COPYIN(state) copyout(state_init)
307 assert (state_init
== 120);
309 assert (state
== 120);
311 STATE_OP (state
, = 130);
312 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
313 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_3
, acc_reg
);
314 reg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle
);
317 #pragma acc parallel COPYIN(state) copyout(state_init)
321 assert (state_init
== 130);
323 assert (state
== 130);
325 STATE_OP (state
, = 140);
326 unreg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
327 reg (acc_ev_compute_construct_start
, cb_compute_construct_start_1
, acc_reg
);
328 unreg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_reg
);
329 reg (acc_ev_compute_construct_end
, cb_compute_construct_end_1
, acc_reg
);
332 #pragma acc parallel COPYIN(state) copyout(state_init)
336 assert (state_init
== 140);
338 assert (state
== 140);
340 STATE_OP (state
, = 150);
341 reg (/* TODO */ (acc_event_t
) 0, NULL
, acc_toggle_per_thread
);
344 #pragma acc parallel COPYIN(state) copyout(state_init)
348 assert (state_init
== 152);
350 assert (state
== 155);