Remove trailing whitespace from invoke.texi
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-91.c
blobd14226c026e433d4de8668eb4910d7de455fde89
1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
3 /* { dg-require-effective-target openacc_cuda } */
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <openacc.h>
8 #include <sys/time.h>
9 #include <stdio.h>
10 #include <cuda.h>
12 int
13 main (int argc, char **argv)
15 const int N = 1024 * 1024;
16 int i;
17 unsigned char *h;
18 void *d;
19 float async, sync;
20 struct timeval start, stop;
21 CUresult r;
22 CUstream s;
24 acc_init (acc_device_nvidia);
26 h = (unsigned char *) malloc (N);
28 for (i = 0; i < N; i++)
30 h[i] = i;
33 d = acc_malloc (N);
35 acc_map_data (h, d, N);
37 gettimeofday (&start, NULL);
39 for (i = 0; i < 100; i++)
41 #pragma acc update device(h[0:N])
44 gettimeofday (&stop, NULL);
46 sync = (float) (stop.tv_sec - start.tv_sec);
47 sync += (float) ((stop.tv_usec - start.tv_usec) / 1000000.0);
49 gettimeofday (&start, NULL);
51 r = cuStreamCreate (&s, CU_STREAM_DEFAULT);
52 if (r != CUDA_SUCCESS)
54 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
55 abort ();
58 if (!acc_set_cuda_stream (0, s))
59 abort ();
61 for (i = 0; i < 100; i++)
63 #pragma acc update device(h[0:N]) async(0)
66 acc_wait_all ();
68 gettimeofday (&stop, NULL);
70 async = (float) (stop.tv_sec - start.tv_sec);
71 async += (float) ((stop.tv_usec - start.tv_usec) / 1000000.0);
73 if (async > (sync * 1.5))
74 abort ();
76 acc_unmap_data (h);
78 acc_free (d);
80 free (h);
82 acc_shutdown (acc_device_nvidia);
84 return 0;
87 /* { dg-output "" } */