aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libgomp/target.c10
-rw-r--r--libgomp/testsuite/libgomp.c/target-55.c20
-rw-r--r--libgomp/testsuite/libgomp.c/target-55a.c23
3 files changed, 50 insertions, 3 deletions
diff --git a/libgomp/target.c b/libgomp/target.c
index e39ef8f..b6a7214 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -138,6 +138,10 @@ gomp_get_num_devices (void)
static struct gomp_device_descr *
resolve_device (int device_id, bool remapped)
{
+ /* Get number of devices and thus ensure that 'gomp_init_targets_once' was
+ called, which must be done before using default_device_var. */
+ int num_devices = gomp_get_num_devices ();
+
if (remapped && device_id == GOMP_DEVICE_ICV)
{
struct gomp_task_icv *icv = gomp_icv (false);
@@ -151,7 +155,7 @@ resolve_device (int device_id, bool remapped)
: omp_initial_device))
return NULL;
if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY
- && gomp_get_num_devices () == 0)
+ && num_devices == 0)
gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, "
"but only the host device is available");
else if (device_id == omp_invalid_device)
@@ -162,10 +166,10 @@ resolve_device (int device_id, bool remapped)
return NULL;
}
- else if (device_id >= gomp_get_num_devices ())
+ else if (device_id >= num_devices)
{
if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY
- && device_id != num_devices_openmp)
+ && device_id != num_devices)
gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, "
"but device not found");
diff --git a/libgomp/testsuite/libgomp.c/target-55.c b/libgomp/testsuite/libgomp.c/target-55.c
new file mode 100644
index 0000000..1314b3c
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/target-55.c
@@ -0,0 +1,20 @@
+/* { dg-do run { target { offload_device } } } */
+/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */
+
+/* Should pass - see target-55a.c for !offload_device */
+
+/* Check OMP_TARGET_OFFLOAD - it shall run on systems with offloading
+ devices available and fail otherwise. Note that this did always
+ fail - as the device handling wasn't initialized before doing the
+ mandatory checking. */
+
+int
+main ()
+{
+ int x = 1;
+ #pragma omp target map(tofrom: x)
+ x = 5;
+ if (x != 5)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/target-55a.c b/libgomp/testsuite/libgomp.c/target-55a.c
new file mode 100644
index 0000000..53978c3
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/target-55a.c
@@ -0,0 +1,23 @@
+/* { dg-do run { target { ! offload_device } } } */
+/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */
+
+/* Should fail - see target-55a.c for offload_device */
+
+/* { dg-shouldfail "omp_invalid_device" } */
+/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but only the host device is available.*" } */
+
+/* Check OMP_TARGET_OFFLOAD - it shall run on systems with offloading
+ devices available and fail otherwise. Note that this did always
+ fail - as the device handling wasn't initialized before doing the
+ mandatory checking. */
+
+int
+main ()
+{
+ int x = 1;
+ #pragma omp target map(tofrom: x)
+ x = 5;
+ if (x != 5)
+ __builtin_abort ();
+ return 0;
+}