| 1 |
/* Check OMP_TARGET_OFFLOAD on systems with non-host devices but no executable |
| 2 |
code due to -foffload=disable. |
| 3 |
|
| 4 |
Note: While one might expect that -foffload=disable implies no non-host |
| 5 |
devices, libgomp actually detects the devices and only fails when trying to |
| 6 |
run as no executable code is availale for that device. |
| 7 |
(Without MANDATORY it simply uses host fallback, which should usually be fine |
| 8 |
but might have issues in corner cases.) |
| 9 |
|
| 10 |
We have default-device-var = 0 (default but also explicitly set), which will |
| 11 |
fail at runtime. For -foffload=disable without non-host devices, see |
| 12 |
target-50.c testcase. */ |
| 13 |
|
| 14 |
/* { dg-do run { target offload_device } } */ |
| 15 |
|
| 16 |
/* { dg-additional-options "-foffload=disable" } */ |
| 17 |
/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */ |
| 18 |
/* { dg-set-target-env-var OMP_DEFAULT_DEVICE "0" } */ |
| 19 |
/* { dg-set-target-env-var OMP_DISPLAY_ENV "true" } */ |
| 20 |
|
| 21 |
/* { dg-output ".*OMP_DEFAULT_DEVICE = '0'.*OMP_TARGET_OFFLOAD = 'MANDATORY'.*" } */ |
| 22 |
|
| 23 |
#include <omp.h> |
| 24 |
|
| 25 |
int |
| 26 |
main () |
| 27 |
{ |
| 28 |
int x; |
| 29 |
/* We know that there are non-host devices. With GCC, we still find them as |
| 30 |
available devices, hence, check for it. */ |
| 31 |
if (omp_get_num_devices() <= 0) |
| 32 |
__builtin_abort (); |
| 33 |
|
| 34 |
/* But due to -foffload=disable, there are no binary code for (default) device '0' */ |
| 35 |
|
| 36 |
/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but device cannot be used for offloading.*" } */ |
| 37 |
/* { dg-shouldfail "OMP_TARGET_OFFLOAD=mandatory and no binary code for a non-host device" } */ |
| 38 |
#pragma omp target map(tofrom:x) |
| 39 |
x = 5; |
| 40 |
if (x != 5) |
| 41 |
__builtin_abort (); |
| 42 |
return 0; |
| 43 |
} |