1// RUN: %libomptarget-compilexx-generic -fopenmp-version=51
2// RUN: %libomptarget-run-generic 2>&1 \
3// RUN: | %fcheck-generic
4
5#include <assert.h>
6#include <iostream>
7#include <omp.h>
8
9struct view {
10 const int size = 10;
11 int *data_host;
12 int *data_device;
13 void foo() {
14 std::size_t bytes = size * sizeof(int);
15 const int host_id = omp_get_initial_device();
16 const int device_id = omp_get_default_device();
17 data_host = (int *)malloc(size: bytes);
18 data_device = (int *)omp_target_alloc(bytes, device_id);
19#pragma omp target teams distribute parallel for has_device_addr(data_device[0])
20 for (int i = 0; i < size; ++i)
21 data_device[i] = i;
22 omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
23 for (int i = 0; i < size; ++i)
24 assert(data_host[i] == i);
25 }
26};
27
28int main() {
29 view a;
30 a.foo();
31 // CHECK: PASSED
32 printf(format: "PASSED\n");
33}
34

source code of offload/test/mapping/has_device_addr.cpp