Not very often, but do I keep running into issues (fails, segfaults) related to testing programs compiled with a GCC without offload configured and then using the system libraries. - That's equivalent to having the system compiler (or any offload compiler) and compiling with -foffload=disable.
The problem is that while the program only contains host code, the run-time library still initializes devices when an API routine - such as omp_get_num_devices - is invoked. This can lead to odd bugs as target regions, obviously, will use host fallback (for any device number) but the API routines will happily operate on the actual devices, which can lead to odd errors. (Likewise issue when compiling for one offload target type and running on a system which has devices of an other type.) I assume that that's not a very common problem, but it can be rather confusing when hitting this issue. Maybe the proposed wording will help others to avoid this pitfall. (Or is this superfluous as -foffload= is not much used and, even if, no one then remembers or finds this none?) Thoughts? * * * It was not clear to me how to refer to libgomp.texi - Should it be 'libgomp' as in 'info libgomp' or the URL https://gcc.gnu.org/onlinedocs/libgomp/ (or filename of the PDF) implies? - Or as 'GNU Offloading and Multi Processing Runtime Library Manual' as named linked to at https://gcc.gnu.org/onlinedocs or on the title page of the the PDF - but that name is not repeated in the info file or the HTML file. - Or even 'GNU libgomp' to mirror a substring in the <title> of the HTML file. I now ended up only implicitly referring that document. Aside: Shouldn't all the HTML documents start with a <h1> and <title> before the table of content? Currently, it has: <title>Top (GNU libgomp)</title> and the body starts with <h2>Short Table of Contents</h2> Tobias PS: In the testsuite, it mostly happens when iterating over omp_get_num_devices() or when mixing calls to API routines with device code ('omp target', compute constructs).
invoke.texi: Add note that -foffload= does not affect device detection gcc/ChangeLog: * doc/invoke.texi (-foffload): Add note that the flag does not affect whether offload devices are detected. gcc/doc/invoke.texi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index dc5fd863ca4..4153863020b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2736,38 +2736,45 @@ targets using ms-abi. @opindex foffload @cindex Offloading targets @cindex OpenACC offloading targets @cindex OpenMP offloading targets @item -foffload=disable @itemx -foffload=default @itemx -foffload=@var{target-list} Specify for which OpenMP and OpenACC offload targets code should be generated. The default behavior, equivalent to @option{-foffload=default}, is to generate code for all supported offload targets. The @option{-foffload=disable} form generates code only for the host fallback, while @option{-foffload=@var{target-list}} generates code only for the specified comma-separated list of offload targets. Offload targets are specified in GCC's internal target-triplet format. You can run the compiler with @option{-v} to show the list of configured offload targets under @code{OFFLOAD_TARGET_NAMES}. +Note that this option does not affect the available offload devices detected by +the run-time library and, hence, the values returned by the OpenMP/OpenACC API +routines or access to devices using those routines. The run-time library +itself can be tuned using environment variables; in particular, to fully disable +the device detection, set the @code{OMP_TARGET_OFFLOAD} environment variable to +@code{disabled}. + @opindex foffload-options @cindex Offloading options @cindex OpenACC offloading options @cindex OpenMP offloading options @item -foffload-options=@var{options} @itemx -foffload-options=@var{target-triplet-list}=@var{options} With @option{-foffload-options=@var{options}}, GCC passes the specified @var{options} to the compilers for all enabled offloading targets. You can specify options that apply only to a specific target or targets by using the @option{-foffload-options=@var{target-list}=@var{options}} form. The @var{target-list} is a comma-separated list in the same format as for the @option{-foffload=} option. Typical command lines are @smallexample -foffload-options='-fno-math-errno -ffinite-math-only' -foffload-options=nvptx-none=-latomic -foffload-options=amdgcn-amdhsa=-march=gfx906