[Openmp-commits] [openmp] ac52c8f - [OpenMP] Add missing test for pinned memory API

Carlo Bertolli via Openmp-commits openmp-commits at lists.llvm.org
Thu Dec 15 19:30:35 PST 2022


Author: Carlo Bertolli
Date: 2022-12-15T21:29:15-06:00
New Revision: ac52c8f5897958be2074e079197bf197824d0486

URL: https://github.com/llvm/llvm-project/commit/ac52c8f5897958be2074e079197bf197824d0486
DIFF: https://github.com/llvm/llvm-project/commit/ac52c8f5897958be2074e079197bf197824d0486.diff

LOG: [OpenMP] Add missing test for pinned memory API

I accidentally left out the test for the pinned API introduced by D138933. Adding it back.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D140077

Added: 
    openmp/runtime/test/api/omp_pinned.c

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/test/api/omp_pinned.c b/openmp/runtime/test/api/omp_pinned.c
new file mode 100644
index 0000000000000..31ad6898beaad
--- /dev/null
+++ b/openmp/runtime/test/api/omp_pinned.c
@@ -0,0 +1,29 @@
+// RUN: %libomp-compile-and-run
+// RUN: env OMP_ALLOCATOR=omp_default_mem_space:pinned=true %libomp-run
+
+#include <omp.h>
+
+int main() {
+  omp_alloctrait_t pinned_trait[1] = {{omp_atk_pinned, omp_atv_true}};
+  omp_allocator_handle_t pinned_alloc =
+      omp_init_allocator(omp_default_mem_space, 1, pinned_trait);
+  omp_allocator_handle_t default_alloc = omp_get_default_allocator();
+  double *a = (double *)omp_alloc(10 * sizeof(double), pinned_alloc);
+  double *b = (double *)omp_alloc(10 * sizeof(double), default_alloc);
+
+  if (!a || !b) return 1;
+
+#pragma omp parallel for
+  for (int i = 0; i < 10; i++) {
+    a[i] = 0;
+    b[i] = 1;
+  }
+
+  for (int i = 0; i < 10; i++)
+    if (a[i] != 0 || b[i] != 1) return 1;
+
+  omp_free(a, pinned_alloc);
+  omp_free(b, default_alloc);
+
+  return 0;
+}


        


More information about the Openmp-commits mailing list