aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-6.c
blob: 1cda442b00134fdc1203c4ccb6428d1a5bc3a455 (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
/* Call 'acc_memcpy_from_device' inside '#pragma acc host_data'.  */

/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */

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

int
main ()
{
  const int SIZE = 318;
  const int c0 = 22;
  const int c1 = 112;

  char *h = (char *) malloc (SIZE);

  memset (h, c0, SIZE);

#pragma acc data create (h[0:SIZE - 44])
  {
#pragma acc update device (h[0:SIZE - 44])

    memset (h, c1, 67);

    void *d = h;
#pragma acc host_data use_device (d)
    {
      acc_memcpy_from_device (h, d, 12);
    }
  }

  for (int i = 0; i < SIZE; ++i)
    {
      if (i < 12)
	assert (h[i] == c0);
      else if (i < 67)
	assert (h[i] == c1);
      else
	assert (h[i] == c0);
    }

  free (h);

  return 0;
}