xref: /llvm-project/offload/test/api/omp_dynamic_shared_memory.c (revision 8823448807f3b1a1362d1417e062d763734e02f5)
1 // RUN: %libomptarget-compile-generic
2 // RUN: env LIBOMPTARGET_SHARED_MEMORY_SIZE=256 \
3 // RUN:   %libomptarget-run-generic | %fcheck-generic
4 
5 // RUN: %libomptarget-compileopt-generic
6 // RUN: env LIBOMPTARGET_SHARED_MEMORY_SIZE=256 \
7 // RUN:   %libomptarget-run-generic | %fcheck-generic
8 
9 // REQUIRES: gpu
10 
11 #include <omp.h>
12 #include <stdio.h>
13 
main()14 int main() {
15   int x;
16 #pragma omp target parallel map(from : x)
17   {
18     int *buf = llvm_omp_target_dynamic_shared_alloc() + 252;
19 #pragma omp barrier
20     if (omp_get_thread_num() == 0)
21       *buf = 1;
22 #pragma omp barrier
23     if (omp_get_thread_num() == 1)
24       x = *buf;
25   }
26 
27   // CHECK: PASS
28   if (x == 1 && llvm_omp_target_dynamic_shared_alloc() == NULL)
29     printf("PASS\n");
30 }
31