On Thu, Oct 15, 2020 at 12:50:18PM +0200, Jakub Jelinek via Gcc-patches wrote: > If nothing of this is valid (i.e. mandatory forbids all the fallback), then > your patch implements it, but if e.g. only if (false) is allowed and nothing > else, then we are ATM in trouble (we pass -2 for if false as well as it is > returned from omp_get_initial_device (); thankfully, OpenMP 5.0 changed it > (something that should be implemented in libgomp too), so that > omp_get_initial_device () is now required to be omp_get_num_devices (), > i.e. the host device is always the last one; so, we would do fallback > for -2 and not for anything else), if also omp_get_initial_device () > number is valid, then we should allow fallback for devices -2 and > omp_get_initial_device () and punt on everything else.
Ok, the first response indicates that both if (false) and omp_get_initial_device () are valid. Therefore, I think until omp_get_initial_device () value is changed, we want in resolve_device: if (device_id < 0 || device_id >= gomp_get_num_devices ()) { if (device_id != GOMP_DEVICE_HOST_FALLBACK) gomp_fatal (...); return NULL; } and do gomp_fatal also for further return NULLs in the function. And then in if (devicep == NULL || !(devicep->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) /* All shared memory devices should use the GOMP_target_ext function. */ || devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM || !(fn_addr = gomp_get_target_fn_addr (devicep, fn))) return gomp_target_fallback (fn, hostaddrs); and similar do gomp_fatal before the gomp_target_fallback call if target-offload-var ICV is mandatory and devicep != NULL. And when we change omp_get_initial_device (), we'd use device_id > gomp_get_num_devices () above instead, and call gomp_fatal there only for (device_id != GOMP_DEVICE_HOST_FALLBACK && device_id != gomp_get_num_devices ()) Jakub