This is based on Chung-Lin's patch at https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563393.html This is about code like: #pragma omp requires unified_shared_memory !$omp requires reverse_offload which before was rejected with a sorry during parsing and is now handled in libgomp (by excluding the devices from the available device list). Note: The requires-directive consistency check is nonfatal, i.e. the program continues after the libgomp: requires-directive clause inconsistency between compilation units detected: 'unified_shared_memory' vs. 'reverse_offload' message. Changes compared to Chung-Lin's patch: - I take the omp_* device API calls into account - Rediffed because of changes done in the past year - Included Thomas' fix for !ENABLE_OFFLOADING + intelmic, i.e. OG11 commit https://gcc.gnu.org/g:6da4ffd4a790f5f0abf290147217ca46a36f981e On the libgomp side: The devices which do not fulfill the requirements are now filtered out. That's in line how I understood the spec – and to make it clearer, I spelled this out explicitly when adding (for other reasons) two glossary items (passed 2nd vote but not yet in a released OpenMP spec): - "accessible devices The host device and all non-host devices accessible for execution." - "supported devices The host device and all non-host devices supported by the implementation for execution of target code for which the device-related requirements of the 'requires' directive are fulfilled." Note: * The FE only generates the requirement clauses when there is at least one declare target variable or function and offloading is used (target region, API call etc.) In particular, this implies that for !ENABLE_OFFLOADING, none is generated. * libgomp only checks whether those values are consistent when env var OMP_TARGET_OFFLOAD != disable. => Thus, I protected the check for this (libgomp.c-c++-common/requires-1.c) by { dg-skip-if "" { ! offloading_enabled } } (and assume that OMP_TARGET_OFFLOAD is not set). If env var OMP_TARGET_OFFLOAD != disable, it then runs for all configured plugins and checks first whether devices are actually available and then whether the requirement mask is fulfilled. Currently, none of the clauses is supported (neither unified_shared_memory nor unified_shared_address nor reverse_offload) even though there are patches submitted (and being worked on), which add support for those. I then unconditionally print a note like: libgomp: note: nvptx devices present but 'omp requires unified_shared_memory' cannot be fulfilled This note is printed if env var OMP_TARGET_OFFLOAD != disable, libgomp supports the device type, a device was found but omp requires could not fulfilled. This means that this message is also printed when compiled with -foffload=disable or 'omp target if(0)' was used throught or ... I think that's acceptable, but it could also be optimized further; however, the initialization (e.g. GOMP_offload_register_ver) happens much later such that the knowledge that a device is not needed (as with -foffload=disable) is not available. I hope the note is not too confusing, but otherwise: * it could be postponed and then printed in context (requires device type <-> name association) * it could only be printed with GOMP_DEBUG set but for the common case (why did it not run?), outputting it unconditionally surely helps to understand what went "wrong". Thoughts? Comments? OK? Tobias PS: I have not fully tested the intelmic version. PPS: I have not tried to implement the compile-time check to impose consistent 'omp requires' – as proposed in the last review. I think I will open a PR to track that proposal. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955