1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
10 main (int argc
, char **argv
)
17 unsigned long *a
, *d_a
, dticks
;
24 acc_init (acc_device_nvidia
);
26 devnum
= acc_get_device_num (acc_device_nvidia
);
28 r
= cuDeviceGet (&dev
, devnum
);
29 if (r
!= CUDA_SUCCESS
)
31 fprintf (stderr
, "cuDeviceGet failed: %d\n", r
);
36 cuDeviceGetAttribute (&nprocs
, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT
,
38 if (r
!= CUDA_SUCCESS
)
40 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
44 r
= cuDeviceGetAttribute (&clkrate
, CU_DEVICE_ATTRIBUTE_CLOCK_RATE
, dev
);
45 if (r
!= CUDA_SUCCESS
)
47 fprintf (stderr
, "cuDeviceGetAttribute failed: %d\n", r
);
51 r
= cuModuleLoad (&module
, "subr.ptx");
52 if (r
!= CUDA_SUCCESS
)
54 fprintf (stderr
, "cuModuleLoad failed: %d\n", r
);
58 r
= cuModuleGetFunction (&delay
, module
, "delay");
59 if (r
!= CUDA_SUCCESS
)
61 fprintf (stderr
, "cuModuleGetFunction failed: %d\n", r
);
65 nbytes
= nprocs
* sizeof (unsigned long);
69 dticks
= (unsigned long) (dtime
* clkrate
);
71 a
= (unsigned long *) malloc (nbytes
);
72 d_a
= (unsigned long *) acc_malloc (nbytes
);
74 acc_map_data (a
, d_a
, nbytes
);
76 kargs
[0] = (void *) &d_a
;
77 kargs
[1] = (void *) &dticks
;
79 r
= cuStreamCreate (&stream
, CU_STREAM_DEFAULT
);
80 if (r
!= CUDA_SUCCESS
)
82 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
86 acc_set_cuda_stream (0, stream
);
88 r
= cuLaunchKernel (delay
, 1, 1, 1, 1, 1, 1, 0, stream
, kargs
, 0);
89 if (r
!= CUDA_SUCCESS
)
91 fprintf (stderr
, "cuLaunchKernel failed: %d\n", r
);
95 fprintf (stderr
, "CheCKpOInT\n");
96 if (acc_async_test (1) != 0)
98 fprintf (stderr
, "asynchronous operation not running\n");
102 sleep ((int) (dtime
/ 1000.0f
) + 1);
104 if (acc_async_test (1) != 1)
106 fprintf (stderr
, "found asynchronous operation still running\n");
115 acc_shutdown (acc_device_nvidia
);
120 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
121 /* { dg-output "unknown async \[0-9\]+" } */
122 /* { dg-shouldfail "" } */