aboutsummaryrefslogtreecommitdiff
path: root/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
commita999c520ac8aa107ea9ef4253ee1a6f1d6e4a40d (patch)
tree48f34df379d1d5d41428951b95e0695bc6189bd7 /libomptarget
parentc0c737ac56d8031e83118d231bb273a54493a489 (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 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@350352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'libomptarget')
-rw-r--r--libomptarget/test/api/omp_get_num_devices.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libomptarget/test/api/omp_get_num_devices.c b/libomptarget/test/api/omp_get_num_devices.c
new file mode 100644
index 0000000..d0e84db
--- /dev/null
+++ b/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