Add support for ARMv8-R architecture
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-74.c
blob0726ee420c3fb528982418b16368e9cf0ca6fdfc
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);
107 atime = stop_timer (0);
109 if (atime < dtime)
111 fprintf (stderr, "actual time < delay time\n");
112 abort ();
115 start_timer (0);
117 acc_wait (0);
119 atime = stop_timer (0);
121 if (0.010 < atime)
123 fprintf (stderr, "actual time too long\n");
124 abort ();
127 acc_unmap_data (a);
129 fini_timers ();
131 free (a);
132 acc_free (d_a);
134 acc_shutdown (acc_device_nvidia);
136 exit (0);
139 /* { dg-output "" } */