Check CXXFLAGS, instead of CFLAGS, for NO_PIE_CFLAGS
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-75.c
blob1942211874826e13875bbb8ae07f058f73c2400f
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>
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 int N;
19 int i;
20 CUstream stream;
21 unsigned long *a, *d_a, dticks;
22 int nbytes;
23 float atime, dtime, hitime, lotime;
24 void *kargs[2];
25 int clkrate;
26 int devnum, nprocs;
28 acc_init (acc_device_nvidia);
30 devnum = acc_get_device_num (acc_device_nvidia);
32 r = cuDeviceGet (&dev, devnum);
33 if (r != CUDA_SUCCESS)
35 fprintf (stderr, "cuDeviceGet failed: %d\n", r);
36 abort ();
39 r =
40 cuDeviceGetAttribute (&nprocs, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
41 dev);
42 if (r != CUDA_SUCCESS)
44 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
45 abort ();
48 r = cuDeviceGetAttribute (&clkrate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, dev);
49 if (r != CUDA_SUCCESS)
51 fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
52 abort ();
55 r = cuModuleLoad (&module, "subr.ptx");
56 if (r != CUDA_SUCCESS)
58 fprintf (stderr, "cuModuleLoad failed: %d\n", r);
59 abort ();
62 r = cuModuleGetFunction (&delay, module, "delay");
63 if (r != CUDA_SUCCESS)
65 fprintf (stderr, "cuModuleGetFunction failed: %d\n", r);
66 abort ();
69 nbytes = nprocs * sizeof (unsigned long);
71 dtime = 200.0;
73 dticks = (unsigned long) (dtime * clkrate);
75 N = nprocs;
77 a = (unsigned long *) malloc (nbytes);
78 d_a = (unsigned long *) acc_malloc (nbytes);
80 acc_map_data (a, d_a, nbytes);
82 stream = (CUstream) acc_get_cuda_stream (0);
83 if (stream != NULL)
84 abort ();
86 r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
87 if (r != CUDA_SUCCESS)
89 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
90 abort ();
93 if (!acc_set_cuda_stream (0, stream))
94 abort ();
96 init_timers (1);
98 kargs[0] = (void *) &d_a;
99 kargs[1] = (void *) &dticks;
101 start_timer (0);
103 for (i = 0; i < N; i++)
105 r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);
106 if (r != CUDA_SUCCESS)
108 fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
109 abort ();
112 acc_wait (0);
115 atime = stop_timer (0);
117 hitime = dtime * N;
118 hitime += hitime * 0.02;
120 lotime = dtime * N;
121 lotime -= lotime * 0.02;
123 if (atime > hitime || atime < lotime)
125 fprintf (stderr, "actual time < delay time\n");
126 abort ();
129 acc_unmap_data (a);
131 fini_timers ();
133 free (a);
134 acc_free (d_a);
136 acc_shutdown (acc_device_nvidia);
138 exit (0);
141 /* { dg-output "" } */