| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-timeout 10 } */ |
| 3 |
|
| 4 |
/* Test the calling of 'acc_get_device_type' from within |
| 5 |
'cb_device_init_start' and 'cb_device_init_end' callbacks. This occurs |
| 6 |
when the CUDA 9.0 'nvprof' tool is used, and previously deadlocked. */ |
| 7 |
|
| 8 |
#include <assert.h> |
| 9 |
#include <stdbool.h> |
| 10 |
#include <acc_prof.h> |
| 11 |
|
| 12 |
static acc_prof_reg reg; |
| 13 |
static acc_prof_reg unreg; |
| 14 |
static acc_prof_lookup_func lookup; |
| 15 |
|
| 16 |
void acc_register_library (acc_prof_reg reg_, acc_prof_reg unreg_, acc_prof_lookup_func lookup_) |
| 17 |
{ |
| 18 |
reg = reg_; |
| 19 |
unreg = unreg_; |
| 20 |
lookup = lookup_; |
| 21 |
} |
| 22 |
|
| 23 |
static bool expect_cb_device_init_start; |
| 24 |
static bool expect_cb_device_init_end; |
| 25 |
|
| 26 |
static void cb_device_init_start (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 27 |
{ |
| 28 |
assert (expect_cb_device_init_start); |
| 29 |
expect_cb_device_init_start = false; |
| 30 |
|
| 31 |
acc_device_t acc_device_type; |
| 32 |
acc_device_type = acc_get_device_type (); |
| 33 |
assert (acc_device_type == acc_device_none); |
| 34 |
|
| 35 |
expect_cb_device_init_end = true; |
| 36 |
} |
| 37 |
|
| 38 |
static void cb_device_init_end (acc_prof_info *prof_info, acc_event_info *event_info, acc_api_info *api_info) |
| 39 |
{ |
| 40 |
assert (expect_cb_device_init_end); |
| 41 |
expect_cb_device_init_end = false; |
| 42 |
|
| 43 |
acc_device_t acc_device_type; |
| 44 |
acc_device_type = acc_get_device_type (); |
| 45 |
assert (acc_device_type == acc_device_none); |
| 46 |
} |
| 47 |
|
| 48 |
int main(void) |
| 49 |
{ |
| 50 |
acc_register_library (acc_prof_register, acc_prof_unregister, acc_prof_lookup); |
| 51 |
|
| 52 |
reg (acc_ev_device_init_start, cb_device_init_start, acc_reg); |
| 53 |
reg (acc_ev_device_init_end, cb_device_init_end, acc_reg); |
| 54 |
|
| 55 |
expect_cb_device_init_start = true; |
| 56 |
expect_cb_device_init_end = false; |
| 57 |
acc_init (acc_device_host); |
| 58 |
assert (!expect_cb_device_init_start); |
| 59 |
assert (!expect_cb_device_init_end); |
| 60 |
{ |
| 61 |
acc_device_t acc_device_type; |
| 62 |
acc_device_type = acc_get_device_type (); |
| 63 |
assert (acc_device_type == acc_device_host); |
| 64 |
} |
| 65 |
acc_shutdown (acc_device_host); |
| 66 |
|
| 67 |
expect_cb_device_init_start = true; |
| 68 |
expect_cb_device_init_end = false; |
| 69 |
acc_init (acc_device_default); |
| 70 |
assert (!expect_cb_device_init_start); |
| 71 |
assert (!expect_cb_device_init_end); |
| 72 |
{ |
| 73 |
acc_device_t acc_device_type; |
| 74 |
acc_device_type = acc_get_device_type (); |
| 75 |
assert (acc_device_type != acc_device_none); |
| 76 |
} |
| 77 |
acc_shutdown (acc_device_default); |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |