1 ! This test checks lowering of OpenACC loop directive.
3 ! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
5 ! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
6 ! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>):
7 ! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10x10xf32>>
13 integer, parameter :: n
= 10
14 real, dimension(n
) :: a
, b
15 real, dimension(n
, n
) :: c
, d
16 integer :: gangNum
= 8
17 integer :: gangDim
= 1
18 integer :: gangStatic
= 8
19 integer :: vectorLength
= 128
20 integer, parameter :: tileSize
= 2
21 integer :: reduction_i
30 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
32 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}{{$}}
39 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
41 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>, seq = [#acc.device_type<none>]}
48 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
50 ! CHECK-NEXT: } attributes {auto_ = [#acc.device_type<none>], inclusiveUpperbound = array<i1: true>}
52 !$acc loop independent
57 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
59 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>, independent = [#acc.device_type<none>]}
66 ! CHECK: acc.loop gang private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
68 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
70 !$acc loop gang(num: 8)
75 ! CHECK: [[GANGNUM1:%.*]] = arith.constant 8 : i32
76 ! CHECK-NEXT: acc.loop gang({num=[[GANGNUM1]] : i32}) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
78 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
80 !$acc loop gang(num: gangNum)
85 ! CHECK: [[GANGNUM2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
86 ! CHECK-NEXT: acc.loop gang({num=[[GANGNUM2]] : i32}) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
88 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
90 !$acc loop gang(num: gangNum, static: gangStatic)
95 ! CHECK: acc.loop gang({num=%{{.*}} : i32, static=%{{.*}} : i32}) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
97 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
104 ! CHECK: acc.loop vector private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
106 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
108 !$acc loop vector(128)
113 ! CHECK: [[CONSTANT128:%.*]] = arith.constant 128 : i32
114 ! CHECK: acc.loop vector([[CONSTANT128]] : i32) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
118 !$acc loop vector(vectorLength)
123 ! CHECK: [[VECTORLENGTH:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
124 ! CHECK: acc.loop vector([[VECTORLENGTH]] : i32) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
126 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
133 ! CHECK: acc.loop worker private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
135 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
137 !$acc loop worker(128)
142 ! CHECK: [[WORKER128:%.*]] = arith.constant 128 : i32
143 ! CHECK: acc.loop worker([[WORKER128]] : i32) private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
145 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
147 !$acc loop private(c)
152 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
154 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
156 !$acc loop private(c, d)
161 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
163 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
165 !$acc loop private(c) private(d)
170 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
172 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
179 ! CHECK: [[TILESIZE:%.*]] = arith.constant 2 : i32
180 ! CHECK: acc.loop {{.*}} tile({[[TILESIZE]] : i32}) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
182 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
188 ! CHECK: [[TILESIZEM1:%.*]] = arith.constant -1 : i32
189 ! CHECK: acc.loop {{.*}} tile({[[TILESIZEM1]] : i32}) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
191 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
193 !$acc loop tile(2, 2)
200 ! CHECK: [[TILESIZE1:%.*]] = arith.constant 2 : i32
201 ! CHECK: [[TILESIZE2:%.*]] = arith.constant 2 : i32
202 ! CHECK: acc.loop {{.*}} tile({[[TILESIZE1]] : i32, [[TILESIZE2]] : i32}) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
204 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
206 !$acc loop tile(tileSize)
211 ! CHECK: acc.loop {{.*}} tile({%{{.*}} : i32}) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
213 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
215 !$acc loop tile(tileSize, tileSize)
222 ! CHECK: acc.loop {{.*}} tile({%{{.*}} : i32, %{{.*}} : i32}) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
224 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
226 !$acc loop collapse(2)
233 ! CHECK: acc.loop {{.*}} control(%arg0 : i32, %arg1 : i32) = (%{{.*}} : i32, i32) to (%{{.*}} : i32, i32) step (%{{.*}} : i32, i32) {
234 ! CHECK: fir.store %arg0 to %{{.*}} : !fir.ref<i32>
235 ! CHECK: fir.store %arg1 to %{{.*}} : !fir.ref<i32>
237 ! CHECK-NEXT: } attributes {collapse = [2], collapseDeviceType = [#acc.device_type<none>], inclusiveUpperbound = array<i1: true, true>}
247 ! CHECK: acc.loop {{.*}} control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
248 ! CHECK: acc.loop {{.*}} control(%arg1 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
250 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
252 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
254 !$acc loop reduction(+:reduction_r) reduction(*:reduction_i)
256 reduction_r
= reduction_r
+ a(i
)
260 ! CHECK: acc.loop private(@privatization_ref_i32 -> %{{.*}} : !fir.ref<i32>) reduction(@reduction_add_ref_f32 -> %{{.*}} : !fir.ref<f32>, @reduction_mul_ref_i32 -> %{{.*}} : !fir.ref<i32>) control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
262 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
264 !$acc loop gang(dim: gangDim, static: gangStatic)
269 ! CHECK: acc.loop gang({dim=%{{.*}}, static=%{{.*}} : i32}) {{.*}} control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
271 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
273 !$acc loop gang(dim: 1)
278 ! CHECK: acc.loop gang({dim={{.*}} : i32}) {{.*}} control(%arg0 : i32) = (%{{.*}} : i32) to (%{{.*}} : i32) step (%{{.*}} : i32) {
280 ! CHECK-NEXT: } attributes {inclusiveUpperbound = array<i1: true>}
288 ! CHECK: %[[CACHE:.*]] = acc.cache varPtr(%{{.*}} : !fir.ref<!fir.array<10xf32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<10xf32>> {name = "b"}
289 ! CHECK: acc.loop {{.*}} cache(%[[CACHE]] : !fir.ref<!fir.array<10xf32>>)
296 !$acc loop gang device_type(nvidia) gang(8)
300 ! CHECK: acc.loop gang([#acc.device_type<none>], {num=%c8{{.*}} : i32} [#acc.device_type<nvidia>])
302 !$acc loop device_type(nvidia, default) gang
306 ! CHECK: acc.loop gang([#acc.device_type<nvidia>, #acc.device_type<default>])
310 subroutine sub1(i
, j
, k
)
314 do concurrent (i
=1:10,j
=1:100,k
=1:200)
315 a(i
,j
,k
) = a(i
,j
,k
) + 1
319 ! CHECK: func.func @_QPsub1
320 ! CHECK: acc.parallel
321 ! CHECK: %[[DC_K:.*]] = fir.alloca i32 {bindc_name = "k"}
322 ! CHECK: %[[DC_J:.*]] = fir.alloca i32 {bindc_name = "j"}
323 ! CHECK: %[[DC_I:.*]] = fir.alloca i32 {bindc_name = "i"}
324 ! CHECK: %[[P_I:.*]] = acc.private varPtr(%[[DC_I]] : !fir.ref<i32>) -> !fir.ref<i32> {implicit = true, name = ""}
325 ! CHECK: %[[P_J:.*]] = acc.private varPtr(%[[DC_J]] : !fir.ref<i32>) -> !fir.ref<i32> {implicit = true, name = ""}
326 ! CHECK: %[[P_K:.*]] = acc.private varPtr(%[[DC_K]] : !fir.ref<i32>) -> !fir.ref<i32> {implicit = true, name = ""}
327 ! CHECK: acc.loop combined(parallel) private(@privatization_ref_i32 -> %[[P_I]] : !fir.ref<i32>, @privatization_ref_i32 -> %[[P_J]] : !fir.ref<i32>, @privatization_ref_i32 -> %[[P_K]] : !fir.ref<i32>) control(%{{.*}} : i32, %{{.*}} : i32, %{{.*}} : i32) = (%c1{{.*}}, %c1{{.*}}, %c1{{.*}} : i32, i32, i32) to (%c10{{.*}}, %c100{{.*}}, %c200{{.*}} : i32, i32, i32) step (%c1{{.*}}, %c1{{.*}}, %c1{{.*}} : i32, i32, i32)
328 ! CHECK: } attributes {inclusiveUpperbound = array<i1: true, true, true>}