summaryrefslogtreecommitdiffstats
path: root/openmp/libomptarget/test/api/omp_get_num_devices.c
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
commit76f3980a205a09fce9e08d954f2ffd34ebd86ef7 (patch)
tree12296fb842565085dc1e40ebd60968e7aa6a74e7 /openmp/libomptarget/test/api/omp_get_num_devices.c
parenta974b33a10745b528c34f0accbd230b0a4e1fb87 (diff)
downloadbcm5719-llvm-76f3980a205a09fce9e08d954f2ffd34ebd86ef7.tar.gz
bcm5719-llvm-76f3980a205a09fce9e08d954f2ffd34ebd86ef7.zip
[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 llvm-svn: 350352
Diffstat (limited to 'openmp/libomptarget/test/api/omp_get_num_devices.c')
-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
OpenPOWER on IntegriCloud