xref: /llvm-project/offload/test/api/omp_dynamic_shared_memory.c (revision 8823448807f3b1a1362d1417e062d763734e02f5)
1330d8983SJohannes Doerfert // RUN: %libomptarget-compile-generic
2330d8983SJohannes Doerfert // RUN: env LIBOMPTARGET_SHARED_MEMORY_SIZE=256 \
3330d8983SJohannes Doerfert // RUN:   %libomptarget-run-generic | %fcheck-generic
4330d8983SJohannes Doerfert 
5330d8983SJohannes Doerfert // RUN: %libomptarget-compileopt-generic
6330d8983SJohannes Doerfert // RUN: env LIBOMPTARGET_SHARED_MEMORY_SIZE=256 \
7330d8983SJohannes Doerfert // RUN:   %libomptarget-run-generic | %fcheck-generic
8330d8983SJohannes Doerfert 
9*88234488SEthan Luis McDonough // REQUIRES: gpu
10330d8983SJohannes Doerfert 
11330d8983SJohannes Doerfert #include <omp.h>
12330d8983SJohannes Doerfert #include <stdio.h>
13330d8983SJohannes Doerfert 
main()14330d8983SJohannes Doerfert int main() {
15330d8983SJohannes Doerfert   int x;
16330d8983SJohannes Doerfert #pragma omp target parallel map(from : x)
17330d8983SJohannes Doerfert   {
18330d8983SJohannes Doerfert     int *buf = llvm_omp_target_dynamic_shared_alloc() + 252;
19330d8983SJohannes Doerfert #pragma omp barrier
20330d8983SJohannes Doerfert     if (omp_get_thread_num() == 0)
21330d8983SJohannes Doerfert       *buf = 1;
22330d8983SJohannes Doerfert #pragma omp barrier
23330d8983SJohannes Doerfert     if (omp_get_thread_num() == 1)
24330d8983SJohannes Doerfert       x = *buf;
25330d8983SJohannes Doerfert   }
26330d8983SJohannes Doerfert 
27330d8983SJohannes Doerfert   // CHECK: PASS
28330d8983SJohannes Doerfert   if (x == 1 && llvm_omp_target_dynamic_shared_alloc() == NULL)
29330d8983SJohannes Doerfert     printf("PASS\n");
30330d8983SJohannes Doerfert }
31