1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
11 main (int argc
, char **argv
)
18 unsigned long *a
, *d_a
, dticks
;
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
);
37 cuDeviceGetAttribute (&nprocs
, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT
,
39 if (r
!= CUDA_SUCCESS
)
41 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
45 r
= cuDeviceGetAttribute (&clkrate
, CU_DEVICE_ATTRIBUTE_CLOCK_RATE
, dev
);
46 if (r
!= CUDA_SUCCESS
)
48 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
52 r
= cuModuleLoad (&module
, "subr.ptx");
53 if (r
!= CUDA_SUCCESS
)
55 fprintf (stderr
, "cuModuleLoad failed: %d\n", r
);
59 r
= cuModuleGetFunction (&delay
, module
, "delay");
60 if (r
!= CUDA_SUCCESS
)
62 fprintf (stderr
, "cuModuleGetFunction failed: %d\n", r
);
66 nbytes
= nprocs
* sizeof (unsigned long);
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);
84 r
= cuStreamCreate (&stream
, CU_STREAM_DEFAULT
);
85 if (r
!= CUDA_SUCCESS
)
87 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
91 if (!acc_set_cuda_stream (0, stream
))
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
);
106 /* Test unseen async-argument. */
109 atime
= stop_timer (0);
113 fprintf (stderr
, "actual time < delay time\n");
120 /* Test unseen async-argument. */
123 atime
= stop_timer (0);
127 fprintf (stderr
, "actual time too long\n");
138 acc_shutdown (acc_device_nvidia
);
143 /* { dg-output "" } */