Retro68/gcc/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c

86 lines
1.5 KiB
C
Raw Normal View History

2015-08-28 15:33:40 +00:00
/* { dg-do run { target openacc_nvidia_accel_selected } } */
/* { dg-additional-options "-lcuda" } */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <openacc.h>
#include <cuda.h>
2019-06-02 15:48:37 +00:00
#if !defined __cplusplus
# undef static_assert
# define static_assert _Static_assert
#endif
static_assert (acc_async_sync == -2, "acc_async_sync?");
static_assert (acc_async_noval == -1, "acc_async_noval?");
2015-08-28 15:33:40 +00:00
int
main (int argc, char **argv)
{
const int N = 100;
int i;
CUstream *streams;
CUstream s;
CUresult r;
acc_init (acc_device_nvidia);
(void) acc_get_device_num (acc_device_nvidia);
2019-06-02 15:48:37 +00:00
streams = (CUstream *) malloc ((2 + N) * sizeof (void *));
streams += 2;
/* "streams[i]" is valid for i in [acc_async_sync..N). */
2015-08-28 15:33:40 +00:00
2019-06-02 15:48:37 +00:00
for (i = acc_async_sync; i < N; i++)
2015-08-28 15:33:40 +00:00
{
streams[i] = (CUstream) acc_get_cuda_stream (i);
if (streams[i] != NULL)
abort ();
r = cuStreamCreate (&streams[i], CU_STREAM_DEFAULT);
if (r != CUDA_SUCCESS)
{
fprintf (stderr, "cuStreamCreate failed: %d\n", r);
abort ();
}
2019-06-02 15:48:37 +00:00
int ret = acc_set_cuda_stream (i, streams[i]);
if (i == acc_async_sync)
{
if (ret == 1)
abort ();
}
else
{
if (ret != 1)
abort ();
}
2015-08-28 15:33:40 +00:00
}
2019-06-02 15:48:37 +00:00
for (i = acc_async_sync; i < N; i++)
2015-08-28 15:33:40 +00:00
{
int j;
int cnt;
cnt = 0;
s = streams[i];
2019-06-02 15:48:37 +00:00
for (j = acc_async_sync; j < N; j++)
2015-08-28 15:33:40 +00:00
{
if (s == streams[j])
cnt++;
}
if (cnt != 1)
abort ();
}
acc_shutdown (acc_device_nvidia);
exit (0);
}
/* { dg-output "" } */