Add support for ARMv8-R architecture
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-72.c
blobe383ba04d6995604d5e84e56758973b0a840ae59
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>
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 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 r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
81 if (r != CUDA_SUCCESS)
83 fprintf (stderr, "cuStreamCreate failed: %d\n", r);
84 abort ();
87 if (!acc_set_cuda_stream (0, stream))
88 abort ();
90 r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);
91 if (r != CUDA_SUCCESS)
93 fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
94 abort ();
97 if (acc_async_test_all () != 0)
99 fprintf (stderr, "asynchronous operation not running\n");
100 abort ();
103 sleep ((int) (dtime / 1000.f) + 1);
105 if (acc_async_test_all () != 1)
107 fprintf (stderr, "found asynchronous operation still running\n");
108 abort ();
111 acc_unmap_data (a);
113 free (a);
114 acc_free (d_a);
116 acc_shutdown (acc_device_nvidia);
118 exit (0);
121 /* { dg-output "" } */