[Patch] OpenMP: Support reverse offload (middle end part)

Tobias Burnus tobias@codesourcery.com
Thu Jul 21 12:33:32 GMT 2022

Ups to quick/wrong patch file. I had found an issue related to 'noclone'
(duplicated entries, dg-scan-dump issues with OpenACC) – but ended up to
attach the wrong file...  Changes: omp-low.cc and
gcc/testsuite/*/goacc/. The rest is the same.


On 21.07.22 12:55, Tobias Burnus wrote:
> This patch does three things:
> (a) It removes a 'sorry' for 'device(ancestor:1)' and passes
>     GOMP_DEVICE_HOST_FALLBACK as device number.
> This is sufficient for full "reverse" offload support with
> being false - and -foffload=disable. And for simple hello-world cases.
> On the libgomp side, the 'requires reverse_offload' currently implies
> that
> the initial device is the only device. While that's all fine, this change
> is insufficient if offloading devices are enabled during compilation as:
> (b.1) The offload-device lto1 should not see the content of the
> ancestor:1 target
> region and all the calls it does. If it does, there will be link
> errors for
> functions not available and it also would pointlessly increase the
> code size.
> Thus, the second part is to create an empty function for devices and a
> full
> version for the host.
> The general idea is: The device version can be used as lookup pointer
> in the
> offload_funcs table; thus, we both need a function on the device and a
> call to
> GOMP_target_ext.
> It turned out to be quite difficult as late in the processing changing a
> FUNCTION_DECL is not that easy – nor removing it after all analysis
> has been
> done. I hope the current version is not too hackish – and maybe
> someone has
> an idea how to best not to assembly the 'nonhost' version on the host.
> (Not critical as it is small (having an empty body) - but still it
> would be
> nicer not to write it to .s file.)
> (b.2) The omp-offload.cc assert showed that cloning and inlining happened
> for the included libgomp example. While inlining should be okay (of
> 'subroutine m2_tg_fn' (and for C/C++ 'tg_fn')) - cloning will break
> the offload_func table lookup - and, hence, had to be excluded →
> "noclone".
> I think it could also affect non-anchestor:1 code - but did not try to
> create an example.
> (c) Prepare for actual reverse offloading
> While (b) already does some prep work for real offloading, at least
> one more
> step is needed: In order to allow that the function pointer can be
> used for
> offload_func table lookup, it has to be passed to libgomp.
> Currently, the 'fn' argument is nullified in on-device calls to
> GOMP_target_ext.
> The third part of this patch nullifies it now only for non-reverse
> offloads.
> OK for mainline?
>  * * *
> Next steps: Implement reverse offloading for devices. In theory, this
> only
> requires libgomp work, but let's see what else will be required.
> Tobias
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: omp-ancestor-ME-v2.diff
Type: text/x-patch
Size: 72200 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220721/2e012466/attachment-0001.bin>

More information about the Gcc-patches mailing list