1 /* PR middle-end/110270 */
3 /* Same as target-implicit-map-3.c but uses the following requiement
4 and for not mapping the stack variables 'A' and 'B' (not mapped
5 but accessible -> USM makes this tested feature even more important.) */
7 #pragma omp requires unified_shared_memory
9 /* Ensure that defaultmap(default : pointer) uses correct OpenMP 5.2
10 semantic, i.e. keeping the pointer value even if not mapped;
11 before OpenMP 5.0/5.1 required that it is NULL. */
21 int *p1
= (int*) 0x12345;
22 int *p1a
= (int*) 0x67890;
23 int *p2
= (int*) omp_target_alloc (sizeof (int) * 5, dev
);
24 int *p2a
= (int*) omp_target_alloc (sizeof (int) * 10, dev
);
25 intptr_t ip
= (intptr_t) p2
;
26 intptr_t ipa
= (intptr_t) p2a
;
29 int B
[5] = {4,5,6,7,8};
33 const omp_alloctrait_t traits
[]
34 = { { omp_atk_alignment
, 128 },
35 { omp_atk_pool_size
, 1024 }};
36 omp_allocator_handle_t a
= omp_init_allocator (omp_default_mem_space
, 2, traits
);
38 int *p4
= (int*) malloc (sizeof (int) * 5);
39 int *p4a
= (int*) omp_alloc (sizeof (int) * 10, a
);
40 intptr_t ip4
= (intptr_t) p4
;
41 intptr_t ip4a
= (intptr_t) p4a
;
43 for (int i
= 0; i
< 5; i
++)
46 for (int i
= 0; i
< 10; i
++)
49 /* Note: 'A' is not mapped but USM accessible. */
50 #pragma omp target device(dev) /* defaultmap(default:pointer) */
52 /* The pointees aren't mapped. */
53 /* OpenMP 5.2 -> same value as before the target region. */
54 if ((intptr_t) p1
!= 0x12345) abort ();
55 if ((intptr_t) p2
!= ip
) abort ();
56 for (int i
= 0; i
< 5; i
++)
59 for (int i
= 0; i
< 10; i
++)
60 ((int *)ipa
)[i
] = 7*i
;
62 /* OpenMP: Points to 'A'. */
63 if (p3
[0] != 1 || p3
[1] != 2 || p3
[2] != 3)
65 p3
[0] = -11; p3
[1] = -22; p3
[2] = -33;
67 /* USM accesible allocated host memory. */
68 if ((intptr_t) p4
!= ip4
)
70 for (int i
= 0; i
< 5; i
++)
73 for (int i
= 0; i
< 10; i
++)
74 if (((int *)ip4a
)[i
] != -43*i
)
76 for (int i
= 0; i
< 5; i
++)
78 for (int i
= 0; i
< 10; i
++)
79 ((int *)ip4a
)[i
] = 18*i
;
82 if (p3
[0] != -11 || p3
[1] != -22 || p3
[2] != -33)
85 for (int i
= 0; i
< 5; i
++)
88 for (int i
= 0; i
< 10; i
++)
91 for (int i
= 0; i
< 5; i
++)
93 for (int i
= 0; i
< 10; i
++)
98 /* Note: 'B' is not mapped but USM accessible. */
99 #pragma omp target device(dev) defaultmap(default:pointer)
101 /* The pointees aren't mapped. */
102 /* OpenMP 5.2 -> same value as before the target region. */
103 if ((intptr_t) p1a
!= 0x67890) abort ();
104 if ((intptr_t) p2a
!= ipa
) abort ();
106 for (int i
= 0; i
< 5; i
++)
107 ((int *)ip
)[i
] = 13*i
;
109 for (int i
= 0; i
< 10; i
++)
112 /* USM accesible allocated host memory. */
113 if ((intptr_t) p4a
!= ip4a
) abort ();
115 /* OpenMP: Points to 'B'. */
116 if (p3a
[0] != 4 || p3a
[1] != 5 || p3a
[2] != 6 || p3a
[3] != 7 || p3a
[4] != 8)
118 p3a
[0] = -44; p3a
[1] = -55; p3a
[2] = -66; p3a
[3] = -77; p3a
[4] = -88;
120 /* USM accesible allocated host memory. */
121 if ((intptr_t) p4a
!= ip4a
)
123 for (int i
= 0; i
< 5; i
++)
124 if (((int *)ip4
)[i
] != -77*i
)
126 for (int i
= 0; i
< 10; i
++)
129 for (int i
= 0; i
< 5; i
++)
131 for (int i
= 0; i
< 10; i
++)
132 ((int *)ip4a
)[i
] = 4*i
;
135 if (p3a
[0] != -44 || p3a
[1] != -55 || p3a
[2] != -66 || p3a
[3] != -77 || p3a
[4] != -88)
138 for (int i
= 0; i
< 5; i
++)
141 for (int i
= 0; i
< 10; i
++)
145 omp_target_free (p2
, dev
);
146 omp_target_free (p2a
, dev
);
149 omp_destroy_allocator (a
);
155 int ntgts
= omp_get_num_devices();
156 for (int i
= 0; i
<= ntgts
; i
++)