1 /* Check that the nteams ICV is honored. */
2 /* PR libgomp/109875 */
4 /* This base version of testcases is supposed to be run with all
5 OMP_NUM_TEAMS* env vars being unset.
7 The variants teams-nteams-icv-{2,3,4}.c test it by setting the
8 various OMP_NUM_TEAMS* env vars and #define MY_... for checking.
10 Currently, only <num> 0,1,2 is supported for the envar via #define
11 and with remote execution, dg-set-target-env-var does not work with
12 DejaGNU, hence, gcc/testsuite/lib/gcc-dg.exp marks those tests as
15 #define MY_MAX_DEVICES 3
17 /* OpenMP currently has:
18 - nteams-var ICV is initialized to 0; one ICV per device
19 - OMP_NUM_TEAMS(_DEV(_<dev-num>)) overrides it
20 OMP_NUM_TEAMS_ALL overrides it
22 -> the value specific by num_teams([lower:]upper)
23 with lower := upper if unspecified
24 -> Otherwise, if nteams-var ICV > 0, #teams <= nteams-var ICV
25 -> Otherwise, if nteams-var ICV <= 0, #teams > 1
26 GCC uses 3 as default on the host and 1 for host fallback.
27 For offloading, it is device specific >> 1. */
34 int num_teams_env
= -1, num_teams_env_dev
= -1;
35 int num_teams_env_devs
[MY_MAX_DEVICES
];
37 #ifdef MY_OMP_NUM_TEAMS_ALL
38 num_teams_env
= num_teams_env_dev
= MY_OMP_NUM_TEAMS_ALL
;
41 #ifdef MY_OMP_NUM_TEAMS
42 num_teams_env
= MY_OMP_NUM_TEAMS
;
45 #ifdef MY_OMP_NUM_TEAMS_DEV
46 num_teams_env_dev
= MY_OMP_NUM_TEAMS_DEV
;
49 #if MY_MAX_DEVICES != 3
50 #error "Currently strictly assuming MY_MAX_DEVICES = 3"
53 #if defined(MY_OMP_NUM_TEAMS_DEV_4) || defined(MY_OMP_NUM_TEAMS_DEV_5)
54 #error "Currently strictly assuming MY_MAX_DEVICES = 3"
57 #ifdef MY_OMP_NUM_TEAMS_DEV_0
58 num_teams_env_devs
[0] = MY_OMP_NUM_TEAMS_DEV_0
;
60 num_teams_env_devs
[0] = num_teams_env_dev
;
63 #ifdef MY_OMP_NUM_TEAMS_DEV_1
64 num_teams_env_devs
[1] = MY_OMP_NUM_TEAMS_DEV_1
;
66 num_teams_env_devs
[1] = num_teams_env_dev
;
69 #ifdef MY_OMP_NUM_TEAMS_DEV_2
70 num_teams_env_devs
[2] = MY_OMP_NUM_TEAMS_DEV_2
;
72 num_teams_env_devs
[2] = num_teams_env_dev
;
75 /* Check that the number of teams (initial device and in target) is
76 >= 1 and, if omp_get_max_teams() > 0, it does not
77 exceed omp_get_max_teams (). */
79 int nteams
, num_teams
;
81 /* Assume that omp_get_max_teams (); returns the ICV, i.e. 0 as default init
82 and not the number of teams that would be run; hence: '>='. */
83 nteams
= omp_get_max_teams ();
84 if (nteams
< 0 || (num_teams_env
>= 0 && nteams
!= num_teams_env
))
89 if (omp_get_team_num () == 0)
90 num_teams
= omp_get_num_teams ();
91 if (num_teams
< 1 || (nteams
> 0 && num_teams
> nteams
))
94 /* GCC hard codes 3 teams - check for it. */
95 if (nteams
<= 0 && num_teams
!= 3)
98 /* For each device, including host fallback. */
99 for (int dev
= 0; dev
<= omp_get_num_devices (); dev
++)
101 int num_teams_icv
= num_teams_env_dev
;
102 if (dev
== omp_get_num_devices ())
103 num_teams_icv
= num_teams_env
;
104 else if (dev
< MY_MAX_DEVICES
)
105 num_teams_icv
= num_teams_env_devs
[dev
];
108 #pragma omp target device(dev) map(from: nteams)
109 nteams
= omp_get_max_teams ();
110 if (nteams
< 0 || (num_teams_icv
>= 0 && nteams
!= num_teams_icv
))
114 #pragma omp target teams device(dev) map(from: num_teams)
115 if (omp_get_team_num () == 0)
116 num_teams
= omp_get_num_teams ();
118 if (num_teams
< 1 || (nteams
> 0 && num_teams
> nteams
))
121 /* GCC hard codes 1 team for host fallback - check for it. */
122 if (dev
== omp_get_num_devices () && num_teams
!= 1)
126 /* Now set the nteams-var ICV and check that omp_get_max_teams()
127 returns the set value and that the following holds:
128 num_teams >= 1 and num_teams <= nteams-var ICV.
130 Additionally, implementation defined, assume:
131 - num_teams == (not '<=') nteams-var ICV, except:
132 - num_teams == 1 for host fallback. */
134 omp_set_num_teams (5);
136 nteams
= omp_get_max_teams ();
142 if (omp_get_team_num () == 0)
143 num_teams
= omp_get_num_teams ();
147 /* For each device, including host fallback. */
148 for (int dev
= 0; dev
<= omp_get_num_devices (); dev
++)
150 #pragma omp target device(dev) firstprivate(dev)
151 omp_set_num_teams (7 + dev
);
153 #pragma omp target device(dev) map(from: nteams)
154 nteams
= omp_get_max_teams ();
155 if (nteams
!= 7 + dev
)
159 #pragma omp target teams device(dev) map(from: num_teams)
160 if (omp_get_team_num () == 0)
161 num_teams
= omp_get_num_teams ();
163 if (dev
== omp_get_num_devices ())
170 if (num_teams
!= 7 + dev
)
175 /* Now use the num_teams clause explicitly. */
178 #pragma omp teams num_teams(6)
179 if (omp_get_team_num () == 0)
180 num_teams
= omp_get_num_teams ();
184 /* For each device, including host fallback. */
185 for (int dev
= 0; dev
<= omp_get_num_devices (); dev
++)
188 #pragma omp target teams device(dev) map(from: num_teams) num_teams(dev+3)
189 if (omp_get_team_num () == 0)
190 num_teams
= omp_get_num_teams ();
192 /* This must match the set value, also with host fallback. */
193 if (num_teams
!= 3 + dev
)