Files
clang-p2996/openmp/libomptarget/test/api/omp_dynamic_shared_memory.c
Joseph Huber 208f900527 [Libomptarget] Add an external interface to dynamic shared memory
This patch adds an external interface to access the dynamic shared
memory buffer in the device runtime. The function introduced is
``llvm_omp_get_dynamic_shared``. This includes a host-side
definition that only returns a null pointer so that it can be used when
host-fallback is enabled without crashing. Support for dynamic shared
memory was also ported to the old device runtime.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D110957
2021-10-08 15:36:57 -04:00

28 lines
678 B
C

// RUN: %libomptarget-compile-nvptx64-nvidia-cuda -fopenmp-target-new-runtime
// RUN: env LIBOMPTARGET_SHARED_MEMORY_SIZE=256 \
// RUN: %libomptarget-run-nvptx64-nvidia-cuda | %fcheck-nvptx64-nvidia-cuda
// REQUIRES: nvptx64-nvidia-cuda
#include <omp.h>
#include <stdio.h>
void *llvm_omp_get_dynamic_shared();
int main() {
int x;
#pragma omp target parallel map(from : x)
{
int *buf = llvm_omp_get_dynamic_shared() + 252;
#pragma omp barrier
if (omp_get_thread_num() == 0)
*buf = 1;
#pragma omp barrier
if (omp_get_thread_num() == 1)
x = *buf;
}
// CHECK: PASS
if (x == 1 && llvm_omp_get_dynamic_shared() == NULL)
printf("PASS\n");
}