| 1 |
/* Test the `acc_get_property' and '`acc_get_property_string' library |
| 2 |
functions on Nvidia devices by comparing property values with |
| 3 |
those obtained through the CUDA API. */ |
| 4 |
/* { dg-additional-sources acc_get_property-aux.c } */ |
| 5 |
/* { dg-additional-options "-lcuda -lcudart" } */ |
| 6 |
/* { dg-do run { target openacc_nvidia_accel_selected } } */ |
| 7 |
/* { dg-require-effective-target openacc_cudart } */ |
| 8 |
|
| 9 |
#include <openacc.h> |
| 10 |
#include <cuda.h> |
| 11 |
#include <cuda_runtime_api.h> |
| 12 |
#include <string.h> |
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
void expect_device_properties (acc_device_t dev_type, int dev_num, |
| 16 |
size_t expected_memory, |
| 17 |
const char* expected_vendor, |
| 18 |
const char* expected_name, |
| 19 |
const char* expected_driver); |
| 20 |
|
| 21 |
int |
| 22 |
main () |
| 23 |
{ |
| 24 |
int dev_count; |
| 25 |
cudaGetDeviceCount (&dev_count); |
| 26 |
|
| 27 |
for (int dev_num = 0; dev_num < dev_count; ++dev_num) |
| 28 |
{ |
| 29 |
if (cudaSetDevice (dev_num) != cudaSuccess) |
| 30 |
{ |
| 31 |
fprintf (stderr, "cudaSetDevice failed.\n"); |
| 32 |
abort (); |
| 33 |
} |
| 34 |
|
| 35 |
printf ("Checking device %d\n", dev_num); |
| 36 |
|
| 37 |
const char *vendor = "Nvidia"; |
| 38 |
size_t free_mem; |
| 39 |
size_t total_mem; |
| 40 |
if (cudaMemGetInfo (&free_mem, &total_mem) != cudaSuccess) |
| 41 |
{ |
| 42 |
fprintf (stderr, "cudaMemGetInfo failed.\n"); |
| 43 |
abort (); |
| 44 |
} |
| 45 |
|
| 46 |
struct cudaDeviceProp p; |
| 47 |
if (cudaGetDeviceProperties (&p, dev_num) != cudaSuccess) |
| 48 |
{ |
| 49 |
fprintf (stderr, "cudaGetDeviceProperties failed.\n"); |
| 50 |
abort (); |
| 51 |
} |
| 52 |
|
| 53 |
int driver_version; |
| 54 |
if (cudaDriverGetVersion (&driver_version) != cudaSuccess) |
| 55 |
{ |
| 56 |
fprintf (stderr, "cudaDriverGetVersion failed.\n"); |
| 57 |
abort (); |
| 58 |
} |
| 59 |
/* The version string should contain the version of the CUDA Toolkit |
| 60 |
in the same MAJOR.MINOR format that is used by Nvidia. |
| 61 |
The format string below is the same that is used by the deviceQuery |
| 62 |
program, which belongs to Nvidia's CUDA samples, to print the version. */ |
| 63 |
char driver[30]; |
| 64 |
snprintf (driver, sizeof driver, "CUDA Driver %u.%u", |
| 65 |
driver_version / 1000, driver_version % 1000 / 10); |
| 66 |
|
| 67 |
/* Note that this check relies on the fact that the device numbering |
| 68 |
used by the nvptx plugin agrees with the CUDA device ordering. */ |
| 69 |
expect_device_properties (acc_device_nvidia, dev_num, |
| 70 |
total_mem, vendor, p.name, driver); |
| 71 |
} |
| 72 |
} |