Thomas Schwinge | 5fae049 | 2019-05-17 21:13:36 +0200 | [diff] [blame] | 1 | /* Test dispatch of events to callbacks. */ |
| 2 | |
| 3 | #undef NDEBUG |
| 4 | #include <assert.h> |
| 5 | |
| 6 | #include <acc_prof.h> |
| 7 | |
| 8 | |
| 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__) |
| 15 | |
| 16 | |
| 17 | #define DEBUG_printf(...) //__builtin_printf (__VA_ARGS__) |
| 18 | |
| 19 | |
| 20 | static int state = -1; |
| 21 | |
| 22 | #define STATE_OP(state, op) \ |
| 23 | do \ |
| 24 | { \ |
| 25 | typeof (state) state_o = (state); \ |
| 26 | (void) state_o; \ |
| 27 | (state)op; \ |
| 28 | DEBUG_printf("state: %d -> %d\n", state_o, (state)); \ |
| 29 | } \ |
| 30 | while (0) |
| 31 | |
| 32 | |
| 33 | static void cb_compute_construct_start_1 (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 34 | { |
| 35 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 36 | |
| 37 | assert (state == 0 |
| 38 | || state == 10 |
| 39 | || state == 30 |
| 40 | || state == 41 |
| 41 | || state == 51 |
| 42 | || state == 91 |
| 43 | || state == 101 |
| 44 | || state == 151); |
| 45 | STATE_OP (state, ++); |
| 46 | } |
| 47 | |
| 48 | static void cb_compute_construct_start_2 (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 49 | { |
| 50 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 51 | |
| 52 | assert (state == 1 |
| 53 | || state == 11 |
| 54 | || state == 40 |
| 55 | || state == 50 |
| 56 | || state == 90 |
| 57 | || state == 100 |
| 58 | || state == 150); |
| 59 | STATE_OP (state, ++); |
| 60 | } |
| 61 | |
| 62 | static void cb_compute_construct_end_1 (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 63 | { |
| 64 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 65 | |
| 66 | assert (state == 14 |
| 67 | || state == 21 |
| 68 | || state == 32 |
| 69 | || state == 42 |
| 70 | || state == 80 |
| 71 | || state == 103 |
| 72 | || state == 152); |
| 73 | STATE_OP (state, ++); |
| 74 | } |
| 75 | |
| 76 | static void cb_compute_construct_end_2 (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 77 | { |
| 78 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 79 | |
| 80 | assert (state == 13 |
| 81 | || state == 43 |
| 82 | || state == 102 |
| 83 | || state == 154); |
| 84 | STATE_OP (state, ++); |
| 85 | } |
| 86 | |
| 87 | static void cb_compute_construct_end_3 (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 88 | { |
| 89 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 90 | |
| 91 | assert (state == 12 |
| 92 | || state == 20 |
| 93 | || state == 31 |
| 94 | || state == 44 |
| 95 | || state == 81 |
| 96 | || state == 104 |
| 97 | || state == 153); |
| 98 | STATE_OP (state, ++); |
| 99 | } |
| 100 | |
| 101 | |
| 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_) |
| 106 | { |
| 107 | DEBUG_printf ("%s\n", __FUNCTION__); |
| 108 | |
| 109 | reg = reg_; |
| 110 | unreg = unreg_; |
| 111 | lookup = lookup_; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | int main() |
| 116 | { |
| 117 | acc_register_library (acc_prof_register, acc_prof_unregister, acc_prof_lookup); |
| 118 | |
| 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); |
| 123 | { |
| 124 | int state_init; |
| 125 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 126 | { |
| 127 | state_init = state; |
| 128 | } |
| 129 | assert (state_init == 2); |
| 130 | } |
| 131 | assert (state == 2); |
| 132 | |
| 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); |
| 140 | { |
| 141 | int state_init; |
| 142 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 143 | { |
| 144 | state_init = state; |
| 145 | } |
| 146 | assert (state_init == 12); |
| 147 | } |
| 148 | assert (state == 15); |
| 149 | |
| 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); |
| 162 | { |
| 163 | int state_init; |
| 164 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 165 | { |
| 166 | state_init = state; |
| 167 | } |
| 168 | assert (state_init == 20); |
| 169 | } |
| 170 | assert (state == 20); |
| 171 | |
| 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); |
| 178 | { |
| 179 | int state_init; |
| 180 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 181 | { |
| 182 | state_init = state; |
| 183 | } |
| 184 | assert (state_init == 31); |
| 185 | } |
| 186 | assert (state == 33); |
| 187 | |
| 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); |
| 197 | { |
| 198 | int state_init; |
| 199 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 200 | { |
| 201 | state_init = state; |
| 202 | } |
| 203 | assert (state_init == 42); |
| 204 | } |
| 205 | assert (state == 45); |
| 206 | |
| 207 | STATE_OP (state, = 50); |
| 208 | unreg (acc_ev_compute_construct_end, NULL, acc_toggle); |
| 209 | { |
| 210 | int state_init; |
| 211 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 212 | { |
| 213 | state_init = state; |
| 214 | } |
| 215 | assert (state_init == 52); |
| 216 | } |
| 217 | assert (state == 52); |
| 218 | |
| 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); |
| 223 | { |
| 224 | int state_init; |
| 225 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 226 | { |
| 227 | state_init = state; |
| 228 | } |
| 229 | assert (state_init == 60); |
| 230 | } |
| 231 | assert (state == 60); |
| 232 | |
| 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); |
| 236 | { |
| 237 | int state_init; |
| 238 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 239 | { |
| 240 | state_init = state; |
| 241 | } |
| 242 | assert (state_init == 70); |
| 243 | } |
| 244 | assert (state == 70); |
| 245 | |
| 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); |
| 250 | { |
| 251 | int state_init; |
| 252 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 253 | { |
| 254 | state_init = state; |
| 255 | } |
| 256 | assert (state_init == 80); |
| 257 | } |
| 258 | assert (state == 82); |
| 259 | |
| 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); |
| 264 | { |
| 265 | int state_init; |
| 266 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 267 | { |
| 268 | state_init = state; |
| 269 | } |
| 270 | assert (state_init == 92); |
| 271 | } |
| 272 | assert (state == 92); |
| 273 | |
| 274 | STATE_OP (state, = 100); |
| 275 | reg (acc_ev_compute_construct_end, NULL, acc_toggle); |
| 276 | { |
| 277 | int state_init; |
| 278 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 279 | { |
| 280 | state_init = state; |
| 281 | } |
| 282 | assert (state_init == 102); |
| 283 | } |
| 284 | assert (state == 105); |
| 285 | |
| 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); |
| 289 | { |
| 290 | int state_init; |
| 291 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 292 | { |
| 293 | state_init = state; |
| 294 | } |
| 295 | assert (state_init == 110); |
| 296 | } |
| 297 | assert (state == 110); |
| 298 | |
| 299 | STATE_OP (state, = 120); |
| 300 | unreg (/* TODO */ (acc_event_t) 0, NULL, acc_toggle_per_thread); |
| 301 | { |
| 302 | int state_init; |
| 303 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 304 | { |
| 305 | state_init = state; |
| 306 | } |
| 307 | assert (state_init == 120); |
| 308 | } |
| 309 | assert (state == 120); |
| 310 | |
| 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); |
| 315 | { |
| 316 | int state_init; |
| 317 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 318 | { |
| 319 | state_init = state; |
| 320 | } |
| 321 | assert (state_init == 130); |
| 322 | } |
| 323 | assert (state == 130); |
| 324 | |
| 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); |
| 330 | { |
| 331 | int state_init; |
| 332 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 333 | { |
| 334 | state_init = state; |
| 335 | } |
| 336 | assert (state_init == 140); |
| 337 | } |
| 338 | assert (state == 140); |
| 339 | |
| 340 | STATE_OP (state, = 150); |
| 341 | reg (/* TODO */ (acc_event_t) 0, NULL, acc_toggle_per_thread); |
| 342 | { |
| 343 | int state_init; |
| 344 | #pragma acc parallel COPYIN(state) copyout(state_init) |
| 345 | { |
| 346 | state_init = state; |
| 347 | } |
| 348 | assert (state_init == 152); |
| 349 | } |
| 350 | assert (state == 155); |
| 351 | |
| 352 | return 0; |
| 353 | } |