On Wed, Oct 14, 2020 at 09:32:42PM +0100, Kwok Cheung Yeung wrote: > I'm not sure how this can be tested automatically, as the behaviour depends > on whether the compiler has been built with offloading support, and whether > any supported offloading hardware has been installed on the system. I have > not included any testcases for now.
Not testing it is probably fine, unless we added some effective targets that the test would be run only if the offloading is (or is not present) and we would expect failures etc. I'm really not sure what the behavior should be in various cases though, so I've asked on omp-lang and will see what the committee members think. The fuzzy things are e.g.: void foo () {} #pragma omp declare target to (foo) int main () { #pragma omp target if(false) foo (); // Is this ok? omp_set_default_device (omp_get_initial_device ()); #pragma omp target foo (); // What about this? #pragma omp target device (omp_get_initial_device ()) foo (); // Or this? #pragma omp target device (omp_get_num_devices () + 42) foo (); // This one is clearly an error if (omp_get_num_devices () == 3) { #pragma omp target device (1) foo (); // This would be an error if we can't offload to device 1 } } Also, what about the case where there are no offloading devices at all, so the default device defaults to the initial device number? 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. Jakub