https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94648
Bug ID: 94648
Summary: [OpenMP] DEVICE_HOST_FALLBACK when no actual device +
omp_target_alloc + omp_get_default_device
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: openmp, wrong-code
Severity: normal
Priority: P3
Component: libgomp
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: jakub at gcc dot gnu.org
Target Milestone: ---
That's with sollve_vv, tests/4.5/target_data/test_target_data_map_alloc.c
https://github.com/SOLLVE/sollve_vv.git
If one runs that test case on a system without offloading support compiled it,
it fails:
int *d_sum = (int *)omp_target_alloc(sizeof(int), omp_get_default_device());
#pragma omp target is_device_ptr(d_sum)
* The omp_get_default_device () function returns '0'
* omp_target_alloc contains:
if (device_num == GOMP_DEVICE_HOST_FALLBACK)
return malloc (size);
struct gomp_device_descr *devicep = resolve_device (device_num);
if (devicep == NULL)
return NULL;
As devicep == NULL, it fails.
I wonder whether
omp_get_default_device ()
should return -2 == GOMP_DEVICE_HOST_FALLBACK in this case – namely, if no
devices are available and, possibly, if OMP_DEFAULT_DEVICE is not explicitly
set.
At least that seems to make more sense than "0" and then failing to
return omp_target_alloc.
"TABLE2.1:ICV Initial Values" lists
default-device-var OMP_DEFAULT_DEVICE Implementation defined
Thus, I think it would be permitted. (But I might have missed some fine print.)
* * *
#include <assert.h>
#include <omp.h>
int main()
{
int sum = 0;
int *d_sum = (int *) omp_target_alloc (sizeof (int),
omp_get_default_device ());
assert (d_sum);
#pragma omp target is_device_ptr(d_sum) map(from:sum)
{
*d_sum = 42;
sum = *d_sum;
}
assert (sum == 42);
return 0;
}