1 /* { dg-do run { target openacc_nvidia_accel_selected } } */
2 /* { dg-additional-options "-lcuda" } */
3 /* { dg-require-effective-target openacc_cuda } */
12 main (int argc
, char **argv
)
21 unsigned long **a
, **d_a
, *tid
, ticks
;
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 (&delay2
, module
, "delay2");
62 if (r
!= CUDA_SUCCESS
)
64 fprintf (stderr
, "cuModuleGetFunction failed: %d\n", r
);
68 nbytes
= sizeof (int);
70 ticks
= (unsigned long) (200.0 * clkrate
);
74 streams
= (CUstream
*) malloc (N
* sizeof (void *));
76 a
= (unsigned long **) malloc (N
* sizeof (unsigned long *));
77 d_a
= (unsigned long **) malloc (N
* sizeof (unsigned long *));
78 tid
= (unsigned long *) malloc (N
* sizeof (unsigned long));
80 for (i
= 0; i
< N
; i
++)
82 a
[i
] = (unsigned long *) malloc (sizeof (unsigned long));
84 d_a
[i
] = (unsigned long *) acc_malloc (nbytes
);
87 acc_map_data (a
[i
], d_a
[i
], nbytes
);
89 streams
[i
] = (CUstream
) acc_get_cuda_stream (i
);
90 if (streams
[i
] != NULL
)
93 r
= cuStreamCreate (&streams
[i
], CU_STREAM_DEFAULT
);
94 if (r
!= CUDA_SUCCESS
)
96 fprintf (stderr
, "cuStreamCreate failed: %d\n", r
);
100 if (!acc_set_cuda_stream (i
, streams
[i
]))
104 for (i
= 0; i
< N
; i
++)
106 kargs
[0] = (void *) &d_a
[i
];
107 kargs
[1] = (void *) &ticks
;
108 kargs
[2] = (void *) &tid
[i
];
110 r
= cuLaunchKernel (delay2
, 1, 1, 1, 1, 1, 1, 0, streams
[i
], kargs
, 0);
111 if (r
!= CUDA_SUCCESS
)
113 fprintf (stderr
, "cuLaunchKernel failed: %d\n", r
);
117 ticks
= (unsigned long) (50.0 * clkrate
);
120 acc_wait_all_async (0);
122 for (i
= 0; i
< N
; i
++)
124 acc_memcpy_from_device (a
[i
], d_a
[i
], nbytes
);
128 acc_unmap_data (a
[i
]);
135 for (i
= 0; i
< N
; i
++)
144 acc_shutdown (acc_device_nvidia
);
149 /* { dg-output "" } */