aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/target-is-accessible-1.c
blob: 2e75c6300ae622ae495106d39be886a08e37ad26 (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
#include <omp.h>

int
main ()
{
  int d = omp_get_default_device ();
  int id = omp_get_initial_device ();
  int n = omp_get_num_devices ();
  void *p;

  if (d < 0 || d >= n)
    d = id;

  if (!omp_target_is_accessible (p, sizeof (int), n))
    __builtin_abort ();

  if (!omp_target_is_accessible (p, sizeof (int), id))
    __builtin_abort ();

  if (!omp_target_is_accessible (p, sizeof (int), omp_initial_device))
    __builtin_abort ();

  if (omp_target_is_accessible (p, sizeof (int), -5))
    __builtin_abort ();

  if (omp_target_is_accessible (p, sizeof (int), n + 1))
    __builtin_abort ();

  /* Currently, a host pointer is accessible if the device supports shared
     memory or omp_target_is_accessible is executed on the host. This
     test case must be adapted when unified shared memory is avialable.  */
  int a[128];
  for (int d = 0; d <= omp_get_num_devices (); d++)
    {
      int shared_mem = 0;
      #pragma omp target map (alloc: shared_mem) device (d)
	shared_mem = 1;
      if (omp_target_is_accessible (p, sizeof (int), d) != shared_mem)
	__builtin_abort ();

      if (omp_target_is_accessible (a, 128 * sizeof (int), d) != shared_mem)
	__builtin_abort ();

      for (int i = 0; i < 128; i++)
	if (omp_target_is_accessible (&a[i], sizeof (int), d) != shared_mem)
	  __builtin_abort ();
    }

  return 0;
}