* c-c++-common/Wrestrict.c (test_strcpy_range): Revert latest change.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-73.c
blob43a8b7e6395731da7135399cf357a8a437a39bf7
1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <openacc.h>
8 #include <cuda.h>
10 int
11 main (int argc, char **argv)
13 CUdevice dev;
14 CUfunction delay;
15 CUmodule module;
16 CUresult r;
17 const int N = 10;
18 int i;
19 CUstream streams[N];
20 unsigned long *a, *d_a, dticks;
21 int nbytes;
22 float dtime;
23 void *kargs[2];
24 int clkrate;
25 int devnum, nprocs;
27 acc_init (acc_device_nvidia);
29 devnum = acc_get_device_num (acc_device_nvidia);
31 r = cuDeviceGet (&dev, devnum);
32 if (r != CUDA_SUCCESS)
34 fprintf (stderr, "cuDeviceGet failed: %d\n", r);
35 abort ();
38 r =
39 cuDeviceGetAttribute (&nprocs, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
40 dev);
41 if (r != CUDA_SUCCESS)
43 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
44 abort ();
47 r = cuDeviceGetAttribute (&clkrate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, dev);
48 if (r != CUDA_SUCCESS)
50 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
51 abort ();
54 r = cuModuleLoad (&module, "subr.ptx");
55 if (r != CUDA_SUCCESS)
57 fprintf (stderr, "cuModuleLoad failed: %d\n", r);
58 abort ();
61 r = cuModuleGetFunction (&delay, module, "delay");
62 if (r != CUDA_SUCCESS)
64 fprintf (stderr, "cuModuleGetFunction failed: %d\n", r);
65 abort ();
68 nbytes = nprocs * sizeof (unsigned long);
70 dtime = 200.0;
72 dticks = (unsigned long) (dtime * clkrate);
74 a = (unsigned long *) malloc (nbytes);
75 d_a = (unsigned long *) acc_malloc (nbytes);
77 acc_map_data (a, d_a, nbytes);
79 kargs[0] = (void *) &d_a;
80 kargs[1] = (void *) &dticks;
82 for (i = 0; i < N; i++)
84 streams[i] = (CUstream) acc_get_cuda_stream (i);
85 if (streams[i] != NULL)
86 abort ();
88 r = cuStreamCreate (&streams[i], CU_STREAM_DEFAULT);
89 if (r != CUDA_SUCCESS)
91 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
92 abort ();
95 if (!acc_set_cuda_stream (i, streams[i]))
96 abort ();
99 for (i = 0; i < N; i++)
101 r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, streams[i], kargs, 0);
102 if (r != CUDA_SUCCESS)
104 fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
105 abort ();
110 if (acc_async_test_all () != 0)
112 fprintf (stderr, "asynchronous operation not running\n");
113 abort ();
116 sleep ((int) (dtime / 1000.0f) + 1);
118 if (acc_async_test_all () != 1)
120 fprintf (stderr, "asynchronous operation not running\n");
121 abort ();
124 acc_unmap_data (a);
126 free (a);
127 acc_free (d_a);
129 acc_shutdown (acc_device_nvidia);
131 exit (0);
134 /* { dg-output "" } */