| 1 |
/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */ |
| 2 |
|
| 3 |
#include <pthread.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include <errno.h> |
| 7 |
#include <ctype.h> |
| 8 |
#include <openacc.h> |
| 9 |
|
| 10 |
unsigned char **x; |
| 11 |
void **d_x; |
| 12 |
const int N = 32; |
| 13 |
const int NTHREADS = 32; |
| 14 |
|
| 15 |
static void * |
| 16 |
test (void *arg) |
| 17 |
{ |
| 18 |
int i; |
| 19 |
int tid; |
| 20 |
unsigned char *p; |
| 21 |
int devnum; |
| 22 |
|
| 23 |
tid = (int) (long) arg; |
| 24 |
|
| 25 |
devnum = acc_get_device_num (acc_device_default); |
| 26 |
acc_set_device_num (devnum, acc_device_default); |
| 27 |
|
| 28 |
#if ACC_DEVICE_TYPE_nvidia |
| 29 |
if (acc_get_current_cuda_context () == NULL) |
| 30 |
abort (); |
| 31 |
#else |
| 32 |
if (acc_get_current_cuda_context () != NULL) |
| 33 |
abort (); |
| 34 |
#endif |
| 35 |
|
| 36 |
acc_copyout (x[tid], N); |
| 37 |
|
| 38 |
p = x[tid]; |
| 39 |
|
| 40 |
for (i = 0; i < N; i++) |
| 41 |
{ |
| 42 |
if (p[i] != i) |
| 43 |
abort (); |
| 44 |
} |
| 45 |
|
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
main (int argc, char **argv) |
| 51 |
{ |
| 52 |
int i; |
| 53 |
pthread_attr_t attr; |
| 54 |
pthread_t *tid; |
| 55 |
unsigned char *p; |
| 56 |
|
| 57 |
acc_init (acc_device_default); |
| 58 |
|
| 59 |
x = (unsigned char **) malloc (NTHREADS * N); |
| 60 |
d_x = (void **) malloc (NTHREADS * N); |
| 61 |
|
| 62 |
for (i = 0; i < N; i++) |
| 63 |
{ |
| 64 |
int j; |
| 65 |
|
| 66 |
p = (unsigned char *) malloc (N); |
| 67 |
|
| 68 |
x[i] = p; |
| 69 |
|
| 70 |
for (j = 0; j < N; j++) |
| 71 |
{ |
| 72 |
p[j] = j; |
| 73 |
} |
| 74 |
|
| 75 |
d_x[i] = acc_copyin (p, N); |
| 76 |
} |
| 77 |
|
| 78 |
if (pthread_attr_init (&attr) != 0) |
| 79 |
perror ("pthread_attr_init failed"); |
| 80 |
|
| 81 |
tid = (pthread_t *) malloc (NTHREADS * sizeof (pthread_t)); |
| 82 |
|
| 83 |
acc_get_cuda_stream (1); |
| 84 |
|
| 85 |
for (i = 0; i < NTHREADS; i++) |
| 86 |
{ |
| 87 |
if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i)) |
| 88 |
!= 0) |
| 89 |
perror ("pthread_create failed"); |
| 90 |
} |
| 91 |
|
| 92 |
if (pthread_attr_destroy (&attr) != 0) |
| 93 |
perror ("pthread_attr_destroy failed"); |
| 94 |
|
| 95 |
for (i = 0; i < NTHREADS; i++) |
| 96 |
{ |
| 97 |
void *res; |
| 98 |
|
| 99 |
if (pthread_join (tid[i], &res) != 0) |
| 100 |
perror ("pthread join failed"); |
| 101 |
} |
| 102 |
|
| 103 |
for (i = 0; i < NTHREADS; i++) |
| 104 |
{ |
| 105 |
if (acc_is_present (x[i], N) != 0) |
| 106 |
abort (); |
| 107 |
} |
| 108 |
|
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
/* { dg-output "" } */ |