| 1 |
/* { dg-do run { target openacc_nvidia_accel_selected } } */ |
| 2 |
/* { dg-additional-options "-lcuda" } */ |
| 3 |
/* { dg-require-effective-target openacc_cuda } */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <openacc.h> |
| 9 |
#include <cuda.h> |
| 10 |
|
| 11 |
#if !defined __cplusplus |
| 12 |
# undef static_assert |
| 13 |
# define static_assert _Static_assert |
| 14 |
#endif |
| 15 |
|
| 16 |
static_assert (acc_async_sync == -2, "acc_async_sync?"); |
| 17 |
static_assert (acc_async_noval == -1, "acc_async_noval?"); |
| 18 |
|
| 19 |
int |
| 20 |
main (int argc, char **argv) |
| 21 |
{ |
| 22 |
const int N = 100; |
| 23 |
int i; |
| 24 |
CUstream *streams; |
| 25 |
CUstream s; |
| 26 |
CUresult r; |
| 27 |
|
| 28 |
acc_init (acc_device_nvidia); |
| 29 |
|
| 30 |
(void) acc_get_device_num (acc_device_nvidia); |
| 31 |
|
| 32 |
streams = (CUstream *) malloc ((2 + N) * sizeof (void *)); |
| 33 |
streams += 2; |
| 34 |
/* "streams[i]" is valid for i in [acc_async_sync..N). */ |
| 35 |
|
| 36 |
for (i = acc_async_sync; i < N; i++) |
| 37 |
{ |
| 38 |
streams[i] = (CUstream) acc_get_cuda_stream (i); |
| 39 |
if (streams[i] != NULL) |
| 40 |
abort (); |
| 41 |
|
| 42 |
r = cuStreamCreate (&streams[i], CU_STREAM_DEFAULT); |
| 43 |
if (r != CUDA_SUCCESS) |
| 44 |
{ |
| 45 |
fprintf (stderr, "cuStreamCreate failed: %d\n", r); |
| 46 |
abort (); |
| 47 |
} |
| 48 |
|
| 49 |
int ret = acc_set_cuda_stream (i, streams[i]); |
| 50 |
if (i == acc_async_sync) |
| 51 |
{ |
| 52 |
if (ret == 1) |
| 53 |
abort (); |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
if (ret != 1) |
| 58 |
abort (); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
for (i = acc_async_sync; i < N; i++) |
| 63 |
{ |
| 64 |
int j; |
| 65 |
int cnt; |
| 66 |
|
| 67 |
cnt = 0; |
| 68 |
|
| 69 |
s = streams[i]; |
| 70 |
|
| 71 |
for (j = acc_async_sync; j < N; j++) |
| 72 |
{ |
| 73 |
if (s == streams[j]) |
| 74 |
cnt++; |
| 75 |
} |
| 76 |
|
| 77 |
if (cnt != 1) |
| 78 |
abort (); |
| 79 |
} |
| 80 |
|
| 81 |
acc_shutdown (acc_device_nvidia); |
| 82 |
|
| 83 |
exit (0); |
| 84 |
} |
| 85 |
|
| 86 |
/* { dg-output "" } */ |