aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-84.c
blob: c1ff76372fcbecb2bdc659f917d72b210c518214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* { dg-do run { target openacc_nvidia_accel_selected } } */
/* { dg-additional-options "-lcuda" } */
/* { dg-require-effective-target openacc_cuda } */

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <openacc.h>
#include <cuda.h>

#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?");

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);

  streams = (CUstream *) malloc ((2 + N) * sizeof (void *));
  streams += 2;
  /* "streams[i]" is valid for i in [acc_async_sync..N).  */

  for (i = acc_async_sync; i < N; i++)
    {
      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 ();
	}

      int ret = acc_set_cuda_stream (i, streams[i]);
      if (i == acc_async_sync)
	{
	  if (ret == 1)
	    abort ();
	}
      else
	{
	  if (ret != 1)
	    abort ();
	}
    }

  for (i = acc_async_sync; i < N; i++)
    {
      int j;
      int cnt;

      cnt = 0;

      s = streams[i];

      for (j = acc_async_sync; j < N; j++)
	{
	  if (s == streams[j])
	    cnt++;
	}

      if (cnt != 1)
	abort ();
    }

  acc_shutdown (acc_device_nvidia);

  exit (0);
}

/* { dg-output "" } */