1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
17 const int NTHREADS
= 32;
27 tid
= (int) (long) arg
;
29 devnum
= acc_get_device_num (acc_device_nvidia
);
30 acc_set_device_num (devnum
, acc_device_nvidia
);
32 if (acc_get_current_cuda_context () == NULL
)
35 p
= (unsigned char *) malloc (N
);
37 for (i
= 0; i
< N
; i
++)
44 d_x
[tid
] = acc_copyin (p
, N
);
52 main (int argc
, char **argv
)
60 acc_init (acc_device_nvidia
);
62 x
= (unsigned char **) malloc (NTHREADS
* N
);
63 d_x
= (void **) malloc (NTHREADS
* N
);
65 if (pthread_attr_init (&attr
) != 0)
66 perror ("pthread_attr_init failed");
68 tid
= (pthread_t
*) malloc (NTHREADS
* sizeof (pthread_t
));
70 r
= cuStreamCreate (&s
, CU_STREAM_DEFAULT
);
71 if (r
!= CUDA_SUCCESS
)
73 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
77 if (!acc_set_cuda_stream (0, s
))
80 for (i
= 0; i
< NTHREADS
; i
++)
82 if (pthread_create (&tid
[i
], &attr
, &test
, (void *) (unsigned long) (i
))
84 perror ("pthread_create failed");
87 if (pthread_attr_destroy (&attr
) != 0)
88 perror ("pthread_attr_destroy failed");
90 for (i
= 0; i
< NTHREADS
; i
++)
94 if (pthread_join (tid
[i
], &res
) != 0)
95 perror ("pthread join failed");
99 for (i
= 0; i
< NTHREADS
; i
++)
101 if (acc_is_present (x
[i
], N
) != 1)
105 acc_get_cuda_stream (1);
107 for (i
= 0; i
< NTHREADS
; i
++)
110 acc_copyout (x
[i
], N
);
115 for (i
= 0; i
< NTHREADS
; i
++)
122 for (j
= 0; j
< N
; j
++)
128 if (acc_is_present (x
[i
], N
) != 0)
132 acc_shutdown (acc_device_nvidia
);
137 /* { dg-output "" } */