summaryrefslogtreecommitdiff
path: root/openmp/libomptarget
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2019-01-03 21:14:19 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2019-01-03 21:14:19 +0000
commita805ab3e2b261b43944fbca492e0f539b16e5ccb (patch)
tree96d6386b7e3b86ad1b73b4e15f838a5a91576fe9 /openmp/libomptarget
parenta7d37198a7989141101cd82febc31dfd27da209a (diff)
[OpenMP] Add omp_get_device_num() and update several other device API functions
Add omp_get_device_num() function for 5.0 which returns the number of the device the current thread is running on. Currently, we are leaving it to the compiler to handle this properly if it is called inside target. Also, did some cleanup and updating of duplicate device API functions (in both libomp and libomptarget) to make them into weak functions that check for the symbol from libomptarget, and will call the version in libomptarget if it is present. If any additional device API functions are implemented also in libomptarget in the future, we should add the dlsym calls to the host functions. Also, if the omp_target_* functions are to be implemented for the host (this has been requested), they should attempt to call the libomptarget versions as well. Patch by Terry Wilmarth Differential Revision: https://reviews.llvm.org/D55578
Diffstat (limited to 'openmp/libomptarget')
-rw-r--r--openmp/libomptarget/test/api/omp_get_num_devices.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/openmp/libomptarget/test/api/omp_get_num_devices.c b/openmp/libomptarget/test/api/omp_get_num_devices.c
new file mode 100644
index 00000000000..d0e84db6b10
--- /dev/null
+++ b/openmp/libomptarget/test/api/omp_get_num_devices.c
@@ -0,0 +1,36 @@
+// RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
+
+#include <stdio.h>
+#include <omp.h>
+
+int test_omp_get_num_devices()
+{
+ /* checks that omp_get_num_devices() > 0 */
+ int num_devices = omp_get_num_devices();
+ printf("num_devices = %d\n", num_devices);
+
+ #pragma omp target
+ {}
+
+ return (num_devices > 0);
+}
+
+int main()
+{
+ int i;
+ int failed=0;
+
+ if (!test_omp_get_num_devices()) {
+ failed++;
+ }
+ if (failed)
+ printf("FAIL\n");
+ else
+ printf("PASS\n");
+ return failed;
+}
+
+// CHECK: PASS