aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_get_property.c
blob: 3460035f0035016940d417d2f887f7335e713f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Test the `acc_get_property' and '`acc_get_property_string' library
   functions by printing the results of those functions for all devices
   of all device types mentioned in the OpenACC standard.

   See also acc_get_property.f90. */
/* { dg-do run } */

#include <openacc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* Print the values of the properties of all devices of the given type
   and do basic device independent validation. */

void
print_device_properties (acc_device_t type)
{
  const char *s;
  size_t v;

  int dev_count = acc_get_num_devices (type);

  for (int i = 0; i < dev_count; ++i)
    {
      printf ("  Device %d:\n", i+1);

      s = acc_get_property_string (i, type, acc_property_vendor);
      printf ("    Vendor: %s\n", s);
      if (s == NULL || *s == 0)
	{
	  fprintf (stderr, "acc_property_vendor should not be null or empty.\n");
	  abort ();
	}

      v = acc_get_property (i, type,  acc_property_memory);
      printf ("    Total memory: %zu\n", v);

      v = acc_get_property (i, type, acc_property_free_memory);
      printf ("    Free memory: %zu\n", v);

      s = acc_get_property_string (i, type, acc_property_name);
      printf ("    Name: %s\n", s);
      if (s == NULL || *s == 0)
	{
	  fprintf (stderr, "acc_property_name should not be null or empty.\n");
	  abort ();
	}

      s = acc_get_property_string (i, type, acc_property_driver);
      printf ("    Driver: %s\n", s);
      if (s == NULL || *s == 0)
	{
	  fprintf (stderr, "acc_property_string should not be null or empty.\n");
	  abort ();
	}
    }
}

int
main ()
{
  printf ("acc_device_none:\n");
  /* For completness; not expected to print anything since there
     should be no devices of this type. */
  print_device_properties (acc_device_none);

  printf ("acc_device_default:\n");
  print_device_properties (acc_device_default);

  printf ("acc_device_host:\n");
  print_device_properties (acc_device_host);

  printf ("acc_device_not_host:\n");
  print_device_properties (acc_device_not_host);
}