Hi, This patch adds support for omp_get_max_teams, omp_set_num_teams, and omp_{gs}et_teams_thread_limit on offload devices. The patch builds on the following patches which are submitted, but not yet approved/committed: - [PATCH] OpenMP, libgomp: Environment variable syntax extension. https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588728.html - [PATCH] OpenMP, libgomp: Add new runtime routine omp_get_mapped_ptr. https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591556.html The OpenMP runtime routines omp_get_max_teams, omp_set_num_teams, and omp_{gs}et_teams_thread_limit were introduced in OpenMP 5.1 and where already implemented for the host usage with patch https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581283.html The new patch extends the functionality of these OpenMP runtime routines by the usage also on the device, i.e. device-specific values for nteams-var and teams-thread-limit-var ICVs can now be retrieved and set also on the device. The updated number of teams/threads are then used when launching the kernel. The following main aspects are considered: (a) Implemented the functions in the according icv-device files. (b) Added structures to not only store initial device-specific values (they have to be kept for omp_display_env) but also device-specific ICV values that can be changed on the device at runtime. (c) Changed the gimplification: (c.1) Introduced integer_minus_two_node. (c.2) For target regions that do not include teams constructs, now the clause num_teams(-2) is added instead num_teams(1). This was necessary as num_teams(1) is ambigious: it can also mean that a teams construct with explicit num_teams(1) clause was specified inside the target region. The disambiguation is needed in order to choose the correct thread limit: teams-thread-limit-var is only intended for teams constructs such that if there is no teams construct, then the number of threads is limited by thread-limit-var. (d) Extend GOMP_target_ext. The host needs to set the device-specific ICV values before the kernel is launched. The number of teams and threads are members of the args list and are modified when no value was specified in an explicit clause and the computation of the value was not postponed due to mapped variables. (d.1) The arguments list is copied in order to guarantee immutability. (e) Added copy back mechanism for ICVs which are modified on the device. The only way to change device-specific ICVs is to do it on the device. As the device-specific values are sometimes needed also on the host when the kernel is launched (particularly number of teams and threads) they have to be copied back. The patch was tested on x86_64-linux with nvptx and gcn offloading. All with no regressions. Marcel ----------------- 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