PR c++/86342 - -Wdeprecated-copy and system headers.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-78.c
blob4f58fb23cfe612ac026626cada638655ac0fd363
1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <openacc.h>
8 #include <cuda.h>
9 #include "timer.h"
11 int
12 main (int argc, char **argv)
14 CUdevice dev;
15 CUfunction delay;
16 CUmodule module;
17 CUresult r;
18 CUstream stream;
19 unsigned long *a, *d_a, dticks;
20 int nbytes;
21 float atime, dtime;
22 void *kargs[2];
23 int clkrate;
24 int devnum, nprocs;
26 acc_init (acc_device_nvidia);
28 devnum = acc_get_device_num (acc_device_nvidia);
30 r = cuDeviceGet (&dev, devnum);
31 if (r != CUDA_SUCCESS)
33 fprintf (stderr, "cuDeviceGet failed: %d\n", r);
34 abort ();
37 r =
38 cuDeviceGetAttribute (&nprocs, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
39 dev);
40 if (r != CUDA_SUCCESS)
42 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
43 abort ();
46 r = cuDeviceGetAttribute (&clkrate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, dev);
47 if (r != CUDA_SUCCESS)
49 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
50 abort ();
53 r = cuModuleLoad (&module, "subr.ptx");
54 if (r != CUDA_SUCCESS)
56 fprintf (stderr, "cuModuleLoad failed: %d\n", r);
57 abort ();
60 r = cuModuleGetFunction (&delay, module, "delay");
61 if (r != CUDA_SUCCESS)
63 fprintf (stderr, "cuModuleGetFunction failed: %d\n", r);
64 abort ();
67 nbytes = nprocs * sizeof (unsigned long);
69 dtime = 200.0;
71 dticks = (unsigned long) (dtime * clkrate);
73 a = (unsigned long *) malloc (nbytes);
74 d_a = (unsigned long *) acc_malloc (nbytes);
76 acc_map_data (a, d_a, nbytes);
78 kargs[0] = (void *) &d_a;
79 kargs[1] = (void *) &dticks;
81 stream = (CUstream) acc_get_cuda_stream (0);
82 if (stream != NULL)
83 abort ();
85 r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
86 if (r != CUDA_SUCCESS)
88 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
89 abort ();
92 if (!acc_set_cuda_stream (0, stream))
93 abort ();
95 init_timers (1);
97 start_timer (0);
99 r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);
100 if (r != CUDA_SUCCESS)
102 fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
103 abort ();
106 acc_wait_all ();
108 atime = stop_timer (0);
110 if (atime < dtime)
112 fprintf (stderr, "actual time < delay time\n");
113 abort ();
116 start_timer (0);
118 acc_wait_all ();
120 atime = stop_timer (0);
122 if (0.010 < atime)
124 fprintf (stderr, "actual time too long\n");
125 abort ();
128 acc_unmap_data (a);
130 fini_timers ();
132 free (a);
133 acc_free (d_a);
135 acc_shutdown (acc_device_nvidia);
137 exit (0);
140 /* { dg-output "" } */