| 1 |
/* Test the `acc_get_property' and '`acc_get_property_string' library |
| 2 |
functions by printing the results of those functions for all devices |
| 3 |
of all device types mentioned in the OpenACC standard. |
| 4 |
|
| 5 |
See also acc_get_property.f90. */ |
| 6 |
/* { dg-do run } */ |
| 7 |
|
| 8 |
#include <openacc.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdio.h> |
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
/* Print the values of the properties of all devices of the given type |
| 14 |
and do basic device independent validation. */ |
| 15 |
|
| 16 |
void |
| 17 |
print_device_properties (acc_device_t type) |
| 18 |
{ |
| 19 |
const char *s; |
| 20 |
size_t v; |
| 21 |
|
| 22 |
int dev_count = acc_get_num_devices (type); |
| 23 |
|
| 24 |
for (int i = 0; i < dev_count; ++i) |
| 25 |
{ |
| 26 |
printf (" Device %d:\n", i+1); |
| 27 |
|
| 28 |
s = acc_get_property_string (i, type, acc_property_vendor); |
| 29 |
printf (" Vendor: %s\n", s); |
| 30 |
if (s == NULL || *s == 0) |
| 31 |
{ |
| 32 |
fprintf (stderr, "acc_property_vendor should not be null or empty.\n"); |
| 33 |
abort (); |
| 34 |
} |
| 35 |
|
| 36 |
v = acc_get_property (i, type, acc_property_memory); |
| 37 |
printf (" Total memory: %zu\n", v); |
| 38 |
|
| 39 |
v = acc_get_property (i, type, acc_property_free_memory); |
| 40 |
printf (" Free memory: %zu\n", v); |
| 41 |
|
| 42 |
s = acc_get_property_string (i, type, acc_property_name); |
| 43 |
printf (" Name: %s\n", s); |
| 44 |
if (s == NULL || *s == 0) |
| 45 |
{ |
| 46 |
fprintf (stderr, "acc_property_name should not be null or empty.\n"); |
| 47 |
abort (); |
| 48 |
} |
| 49 |
|
| 50 |
s = acc_get_property_string (i, type, acc_property_driver); |
| 51 |
printf (" Driver: %s\n", s); |
| 52 |
if (s == NULL || *s == 0) |
| 53 |
{ |
| 54 |
fprintf (stderr, "acc_property_string should not be null or empty.\n"); |
| 55 |
abort (); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
int |
| 61 |
main () |
| 62 |
{ |
| 63 |
printf ("acc_device_none:\n"); |
| 64 |
/* For completness; not expected to print anything since there |
| 65 |
should be no devices of this type. */ |
| 66 |
print_device_properties (acc_device_none); |
| 67 |
|
| 68 |
printf ("acc_device_default:\n"); |
| 69 |
print_device_properties (acc_device_default); |
| 70 |
|
| 71 |
printf ("acc_device_host:\n"); |
| 72 |
print_device_properties (acc_device_host); |
| 73 |
|
| 74 |
printf ("acc_device_not_host:\n"); |
| 75 |
print_device_properties (acc_device_not_host); |
| 76 |
} |