1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
3 /* { dg-require-effective-target openacc_cuda } */
13 main (int argc
, char **argv
)
20 unsigned long *a
, *d_a
, dticks
;
27 acc_init (acc_device_nvidia
);
29 devnum
= acc_get_device_num (acc_device_nvidia
);
31 r
= cuDeviceGet (&dev
, devnum
);
32 if (r
!= CUDA_SUCCESS
)
34 fprintf (stderr
, "cuDeviceGet failed: %d\n", r
);
39 cuDeviceGetAttribute (&nprocs
, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT
,
41 if (r
!= CUDA_SUCCESS
)
43 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
47 r
= cuDeviceGetAttribute (&clkrate
, CU_DEVICE_ATTRIBUTE_CLOCK_RATE
, dev
);
48 if (r
!= CUDA_SUCCESS
)
50 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
54 r
= cuModuleLoad (&module
, "subr.ptx");
55 if (r
!= CUDA_SUCCESS
)
57 fprintf (stderr
, "cuModuleLoad failed: %d\n", r
);
61 r
= cuModuleGetFunction (&delay
, module
, "delay");
62 if (r
!= CUDA_SUCCESS
)
64 fprintf (stderr
, "cuModuleGetFunction failed: %d\n", r
);
68 nbytes
= nprocs
* sizeof (unsigned long);
72 dticks
= (unsigned long) (dtime
* clkrate
);
74 a
= (unsigned long *) malloc (nbytes
);
75 d_a
= (unsigned long *) acc_malloc (nbytes
);
77 acc_map_data (a
, d_a
, nbytes
);
79 kargs
[0] = (void *) &d_a
;
80 kargs
[1] = (void *) &dticks
;
82 stream
= (CUstream
) acc_get_cuda_stream (0);
86 r
= cuStreamCreate (&stream
, CU_STREAM_DEFAULT
);
87 if (r
!= CUDA_SUCCESS
)
89 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
93 if (!acc_set_cuda_stream (0, stream
))
100 r
= cuLaunchKernel (delay
, 1, 1, 1, 1, 1, 1, 0, stream
, kargs
, 0);
101 if (r
!= CUDA_SUCCESS
)
103 fprintf (stderr
, "cuLaunchKernel failed: %d\n", r
);
109 atime
= stop_timer (0);
113 fprintf (stderr
, "actual time < delay time\n");
121 atime
= stop_timer (0);
125 fprintf (stderr
, "actual time too long\n");
136 acc_shutdown (acc_device_nvidia
);
141 /* { dg-output "" } */