Reset prologue_location before calling code_end
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-74.c
blob0efcf0d52229807eb50ad1bda4ff782c34485dc5
1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <openacc.h>
7 #include <cuda.h>
8 #include "timer.h"
10 int
11 main (int argc, char **argv)
13 CUdevice dev;
14 CUfunction delay;
15 CUmodule module;
16 CUresult r;
17 CUstream stream;
18 unsigned long *a, *d_a, dticks;
19 int nbytes;
20 float atime, dtime;
21 void *kargs[2];
22 int clkrate;
23 int devnum, nprocs;
25 acc_init (acc_device_nvidia);
27 devnum = acc_get_device_num (acc_device_nvidia);
29 r = cuDeviceGet (&dev, devnum);
30 if (r != CUDA_SUCCESS)
32 fprintf (stderr, "cuDeviceGet failed: %d\n", r);
33 abort ();
36 r =
37 cuDeviceGetAttribute (&nprocs, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
38 dev);
39 if (r != CUDA_SUCCESS)
41 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
42 abort ();
45 r = cuDeviceGetAttribute (&clkrate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, dev);
46 if (r != CUDA_SUCCESS)
48 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
49 abort ();
52 r = cuModuleLoad (&module, "subr.ptx");
53 if (r != CUDA_SUCCESS)
55 fprintf (stderr, "cuModuleLoad failed: %d\n", r);
56 abort ();
59 r = cuModuleGetFunction (&delay, module, "delay");
60 if (r != CUDA_SUCCESS)
62 fprintf (stderr, "cuModuleGetFunction failed: %d\n", r);
63 abort ();
66 nbytes = nprocs * sizeof (unsigned long);
68 dtime = 200.0;
70 dticks = (unsigned long) (dtime * clkrate);
72 a = (unsigned long *) malloc (nbytes);
73 d_a = (unsigned long *) acc_malloc (nbytes);
75 acc_map_data (a, d_a, nbytes);
77 kargs[0] = (void *) &d_a;
78 kargs[1] = (void *) &dticks;
80 stream = (CUstream) acc_get_cuda_stream (0);
81 if (stream != NULL)
82 abort ();
84 r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
85 if (r != CUDA_SUCCESS)
87 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
88 abort ();
91 if (!acc_set_cuda_stream (0, stream))
92 abort ();
94 init_timers (1);
96 start_timer (0);
98 r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);
99 if (r != CUDA_SUCCESS)
101 fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
102 abort ();
105 acc_wait (0);
106 /* Test unseen async-argument. */
107 acc_wait (1);
109 atime = stop_timer (0);
111 if (atime < dtime)
113 fprintf (stderr, "actual time < delay time\n");
114 abort ();
117 start_timer (0);
119 acc_wait (0);
120 /* Test unseen async-argument. */
121 acc_wait (1);
123 atime = stop_timer (0);
125 if (0.010 < atime)
127 fprintf (stderr, "actual time too long\n");
128 abort ();
131 acc_unmap_data (a);
133 fini_timers ();
135 free (a);
136 acc_free (d_a);
138 acc_shutdown (acc_device_nvidia);
140 exit (0);
143 /* { dg-output "" } */