Minor update: Main change is to use 'char' more consistently
(e.g. for omp_get_fr_id_from_name and GOMP_INTEROP_IFR_UNKNOWN etc.)
in the hope that it will fix the build bot issues for ARM.
Additionally, I fixed some indentation "issues" in one testcase and
in for C++, the __GOMP_UINTPTR_T_ENUM macro definitions.
Otherwise it is unchanged.
Tobias
Tobias Burnus wrote:
Background:
omp interop device(1) init(prefer_type("cuda"), targetsync: obj)
depend(inout: x) nowait
…
omp interop destroy(obj)
initializes the omp_interop_t / integer(omp_interop_kind) variable for device
'1'
and (thanks to 'targetsync') creates a stream object. 'obj' can then be used as
follows: first, we have to check the returned type (e.g. CUDA as wished for or
something else including N/A alias omp_interop_fr_none).
The (CUDA) stream, (cuda) device number etc. can then be extracted and used with
CUDA calls.
In terms of the parser, that's quite boring if there wasn't the prefer_type
modifier.
Besides taking a list of strings and constant integer expressions, OpenMP 6.0
also
permits:
prefer_type( {fr("cuda"), attr("ompx_1", "ompx_2")},
{attr("ompx_2"), attr("ompx_4")} )
i.e. the same to 'fr' and a string to 'attr' that must start with 'ompx_'. There
can be 0 or 1 'fr' and >= 0 'attr' per curly brace (but at least one 'fr'/'attr'
must be specified).
* * *
The attached patch add the C parser, which in turn means that there is now a
middle-end representation for it. Additionally, it fixes the Fortran compiler
for issues found while doing so - and for a newer OpenMP 6 spec change, i.e.
only one 'fr' value permitted per {…} and the constant integer value to 'fr'
may be any const integer expr not only an identifier, which is the same as
for the old, simpler 'prefer_type("hip",int_expr,"sycl")' syntax.
Comments, remarks, concerns, suggestions before I commit it?
Tobias
* * *
PS: Once 'omp interop' has returned the object, the
https://gcc.gnu.org/onlinedocs/libgomp/Interoperability-Routines.html
can be used to access it. See libgomp.*/interop-routines*.{F,F90,c} for
some testcases. - Proper combined testcases will be added once the
compiler middle-end + libgomp parts have been implemented to connect the
two. → TODO: C++ parser, middle-end code including calling new libgomp function.
Once done, the AMD GPU (gcn) and Nvidia GPU libgomp plugins need to handle
it to return an interop object for CUDA/CUDA_DRIVER/HIP/HSA; I posted an
RFC patch the other day, which should mostly work once (↑) is done; it still
requires some updates, cleanups and additions, but otherwise … :-)
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/661207.htmlOpenMP: 'interop' construct - add C parser support, improve Fortran pasing
Add middle end support for the 'interop' directive and the 'init', 'use',
and 'destroy' clauses - but fail with a sorry, unimplemented in gimplify.cc.
For Fortran, generate the tree code, update the internal representation,
add some more diagnostic checks and update for newer specification changes
('fr' only takes a single value, but it integer expressions are permitted
again [like with the old syntax] not only constant identifiers).
For C, this patch adds the full parser support for 'interop'.
Still missing (later commit) is parsing support in C++ and actually
handling the directive in the middle end and in libgomp.
The GOMP_INTEROP_IFR_* internal values have been changed to have space
for vendor specific values that are adjacent to the existing values
but negative, if needed.
gcc/c-family/ChangeLog:
* c-common.h (c_omp_interop_t_p): New prototype.
* c-omp.cc (c_omp_interop_t_p): Check whether the type is
omp_interop_t.
(c_omp_directives): Uncomment 'interop'.
* c-pragma.cc (omp_pragmas): Add 'interop'.
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_INTEROP.
(enum pragma_omp_clause): Add init, use, and destroy clauses.
gcc/c/ChangeLog:
* c-parser.cc (INCLUDE_STRING): Define.
(c_parser_pragma): Handle 'interop' directive.
(c_parser_omp_clause_name, c_parser_omp_all_clauses): Handle init,
use, and destroy clauses.
(c_parser_omp_clause_destroy, c_parser_omp_modifier_prefer_type,
c_parser_omp_clause_init, c_parser_omp_clause_use,
OMP_INTEROP_CLAUSE_MASK, c_parser_omp_interop): New.
* c-typeck.cc (c_finish_omp_clauses): Add missing OPT_Wopenmp to
a warning; handle new clauses.
gcc/fortran/ChangeLog:
* gfortran.h (gfc_omp_namelist): Cleanup interop internal
representation.
* dump-parse-tree.cc (show_omp_namelist): Update for changed
internal representation.
* match.cc (gfc_free_omp_namelist): Likewise.
* openmp.cc (gfc_match_omp_prefer_type, gfc_match_omp_init):
Likewise; also handle some corner cases better and update for
newer 6.0 changes related to 'fr'.
(resolve_omp_clauses): Add type-check for interop variables.
* trans-openmp.cc (gfc_trans_omp_clauses): Handle init, use
and destroy clauses.
(gfc_trans_openmp_interop): New.
(gfc_trans_omp_directive): Call it.
gc