1 ! This test checks lowering of OpenACC parallel loop combined directive.
3 ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
5 subroutine acc_parallel_loop
11 integer :: numGangs
= 1
12 integer :: numWorkers
= 10
13 integer :: vectorLength
= 128
14 logical :: ifCondition
= .TRUE
.
15 integer, parameter :: n
= 10
16 real, dimension(n
) :: a
, b
, c
17 real, dimension(n
, n
) :: d
, e
20 integer :: gangNum
= 8
21 integer :: gangStatic
= 8
22 integer :: vectorNum
= 128
23 integer, parameter :: tileSize
= 2
25 !CHECK: [[A:%.*]] = fir.alloca !fir.array<10xf32> {{{.*}}uniq_name = "{{.*}}Ea"}
26 !CHECK: [[B:%.*]] = fir.alloca !fir.array<10xf32> {{{.*}}uniq_name = "{{.*}}Eb"}
27 !CHECK: [[C:%.*]] = fir.alloca !fir.array<10xf32> {{{.*}}uniq_name = "{{.*}}Ec"}
28 !CHECK: [[F:%.*]] = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "f", uniq_name = "{{.*}}Ef"}
29 !CHECK: [[G:%.*]] = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = "g", uniq_name = "{{.*}}Eg"}
30 !CHECK: [[IFCONDITION:%.*]] = fir.address_of(@{{.*}}ifcondition) : !fir.ref<!fir.logical<4>>
37 !CHECK: acc.parallel {
45 !$acc parallel loop async
49 !$acc end parallel loop
51 !CHECK: acc.parallel {
57 !CHECK-NEXT: } attributes {asyncAttr}
59 !$acc parallel loop async(1)
64 !CHECK: [[ASYNC1:%.*]] = arith.constant 1 : i32
65 !CHECK: acc.parallel async([[ASYNC1]]: i32) {
73 !$acc parallel loop async(async)
78 !CHECK: [[ASYNC2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
79 !CHECK: acc.parallel async([[ASYNC2]]: i32) {
87 !$acc parallel loop wait
92 !CHECK: acc.parallel {
98 !CHECK-NEXT: } attributes {waitAttr}
100 !$acc parallel loop wait(1)
105 !CHECK: [[WAIT1:%.*]] = arith.constant 1 : i32
106 !CHECK: acc.parallel wait([[WAIT1]]: i32) {
114 !$acc parallel loop wait(1, 2)
119 !CHECK: [[WAIT2:%.*]] = arith.constant 1 : i32
120 !CHECK: [[WAIT3:%.*]] = arith.constant 2 : i32
121 !CHECK: acc.parallel wait([[WAIT2]]: i32, [[WAIT3]]: i32) {
129 !$acc parallel loop wait(wait1, wait2)
134 !CHECK: [[WAIT4:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
135 !CHECK: [[WAIT5:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
136 !CHECK: acc.parallel wait([[WAIT4]]: i32, [[WAIT5]]: i32) {
144 !$acc parallel loop num_gangs(1)
149 !CHECK: [[NUMGANGS1:%.*]] = arith.constant 1 : i32
150 !CHECK: acc.parallel num_gangs([[NUMGANGS1]]: i32) {
158 !$acc parallel loop num_gangs(numGangs)
163 !CHECK: [[NUMGANGS2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
164 !CHECK: acc.parallel num_gangs([[NUMGANGS2]]: i32) {
172 !$acc parallel loop num_workers(10)
177 !CHECK: [[NUMWORKERS1:%.*]] = arith.constant 10 : i32
178 !CHECK: acc.parallel num_workers([[NUMWORKERS1]]: i32) {
186 !$acc parallel loop num_workers(numWorkers)
191 !CHECK: [[NUMWORKERS2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
192 !CHECK: acc.parallel num_workers([[NUMWORKERS2]]: i32) {
200 !$acc parallel loop vector_length(128)
205 !CHECK: [[VECTORLENGTH1:%.*]] = arith.constant 128 : i32
206 !CHECK: acc.parallel vector_length([[VECTORLENGTH1]]: i32) {
214 !$acc parallel loop vector_length(vectorLength)
219 !CHECK: [[VECTORLENGTH2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
220 !CHECK: acc.parallel vector_length([[VECTORLENGTH2]]: i32) {
228 !$acc parallel loop if(.TRUE.)
233 !CHECK: [[IF1:%.*]] = arith.constant true
234 !CHECK: acc.parallel if([[IF1]]) {
242 !$acc parallel loop if(ifCondition)
247 !CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref<!fir.logical<4>>
248 !CHECK: [[IF2:%.*]] = fir.convert [[IFCOND]] : (!fir.logical<4>) -> i1
249 !CHECK: acc.parallel if([[IF2]]) {
257 !$acc parallel loop self(.TRUE.)
262 !CHECK: [[SELF1:%.*]] = arith.constant true
263 !CHECK: acc.parallel self([[SELF1]]) {
271 !$acc parallel loop self
276 !CHECK: acc.parallel {
282 !CHECK-NEXT: } attributes {selfAttr}
284 !$acc parallel loop self(ifCondition)
289 !CHECK: [[SELF2:%.*]] = fir.convert [[IFCONDITION]] : (!fir.ref<!fir.logical<4>>) -> i1
290 !CHECK: acc.parallel self([[SELF2]]) {
298 !$acc parallel loop copy(a, b)
303 !CHECK: acc.parallel copy([[A]]: !fir.ref<!fir.array<10xf32>>, [[B]]: !fir.ref<!fir.array<10xf32>>) {
311 !$acc parallel loop copy(a) copy(b)
316 !CHECK: acc.parallel copy([[A]]: !fir.ref<!fir.array<10xf32>>, [[B]]: !fir.ref<!fir.array<10xf32>>) {
324 !$acc parallel loop copyin(a) copyin(readonly: b)
329 !CHECK: acc.parallel copyin([[A]]: !fir.ref<!fir.array<10xf32>>) copyin_readonly([[B]]: !fir.ref<!fir.array<10xf32>>) {
337 !$acc parallel loop copyout(a) copyout(zero: b)
342 !CHECK: acc.parallel copyout([[A]]: !fir.ref<!fir.array<10xf32>>) copyout_zero([[B]]: !fir.ref<!fir.array<10xf32>>) {
350 !$acc parallel loop create(b) create(zero: a)
355 !CHECK: acc.parallel create([[B]]: !fir.ref<!fir.array<10xf32>>) create_zero([[A]]: !fir.ref<!fir.array<10xf32>>) {
363 !$acc parallel loop no_create(a, b)
368 !CHECK: acc.parallel no_create([[A]]: !fir.ref<!fir.array<10xf32>>, [[B]]: !fir.ref<!fir.array<10xf32>>) {
376 !$acc parallel loop present(a, b)
381 !CHECK: acc.parallel present([[A]]: !fir.ref<!fir.array<10xf32>>, [[B]]: !fir.ref<!fir.array<10xf32>>) {
389 !$acc parallel loop deviceptr(a) deviceptr(b)
394 !CHECK: acc.parallel deviceptr([[A]]: !fir.ref<!fir.array<10xf32>>, [[B]]: !fir.ref<!fir.array<10xf32>>) {
402 !$acc parallel loop attach(f, g)
407 !CHECK: acc.parallel attach([[F]]: !fir.ref<!fir.box<!fir.ptr<f32>>>, [[G]]: !fir.ref<!fir.box<!fir.ptr<f32>>>) {
415 !$acc parallel loop private(a) firstprivate(b)
420 !CHECK: acc.parallel private([[A]]: !fir.ref<!fir.array<10xf32>>) firstprivate([[B]]: !fir.ref<!fir.array<10xf32>>) {
421 !CHECK: acc.loop private([[A]]: !fir.ref<!fir.array<10xf32>>) {
428 !$acc parallel loop seq
433 !CHECK: acc.parallel {
437 !CHECK-NEXT: } attributes {seq}
441 !$acc parallel loop auto
446 !CHECK: acc.parallel {
450 !CHECK-NEXT: } attributes {auto}
454 !$acc parallel loop independent
459 !CHECK: acc.parallel {
463 !CHECK-NEXT: } attributes {independent}
467 !$acc parallel loop gang
472 !CHECK: acc.parallel {
473 !CHECK: acc.loop gang {
480 !$acc parallel loop gang(num: 8)
485 !CHECK: acc.parallel {
486 !CHECK: [[GANGNUM1:%.*]] = arith.constant 8 : i32
487 !CHECK-NEXT: acc.loop gang(num=[[GANGNUM1]]: i32) {
494 !$acc parallel loop gang(num: gangNum)
499 !CHECK: acc.parallel {
500 !CHECK: [[GANGNUM2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
501 !CHECK-NEXT: acc.loop gang(num=[[GANGNUM2]]: i32) {
508 !$acc parallel loop gang(num: gangNum, static: gangStatic)
513 !CHECK: acc.parallel {
514 !CHECK: acc.loop gang(num=%{{.*}}: i32, static=%{{.*}}: i32) {
521 !$acc parallel loop vector
525 !CHECK: acc.parallel {
526 !CHECK: acc.loop vector {
533 !$acc parallel loop vector(128)
538 !CHECK: acc.parallel {
539 !CHECK: [[CONSTANT128:%.*]] = arith.constant 128 : i32
540 !CHECK: acc.loop vector([[CONSTANT128]]: i32) {
547 !$acc parallel loop vector(vectorLength)
552 !CHECK: acc.parallel {
553 !CHECK: [[VECTORLENGTH:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
554 !CHECK: acc.loop vector([[VECTORLENGTH]]: i32) {
561 !$acc parallel loop worker
566 !CHECK: acc.parallel {
567 !CHECK: acc.loop worker {
574 !$acc parallel loop worker(128)
579 !CHECK: acc.parallel {
580 !CHECK: [[WORKER128:%.*]] = arith.constant 128 : i32
581 !CHECK: acc.loop worker([[WORKER128]]: i32) {
588 !$acc parallel loop collapse(2)
595 !CHECK: acc.parallel {
600 !CHECK-NEXT: } attributes {collapse = 2 : i64}
612 !CHECK: acc.parallel {
624 !$acc parallel loop tile(2)
629 !CHECK: acc.parallel {
630 !CHECK: [[TILESIZE:%.*]] = arith.constant 2 : i32
631 !CHECK: acc.loop tile([[TILESIZE]]: i32) {
638 !$acc parallel loop tile(*)
643 !CHECK: acc.parallel {
644 !CHECK: [[TILESIZEM1:%.*]] = arith.constant -1 : i32
645 !CHECK: acc.loop tile([[TILESIZEM1]]: i32) {
652 !$acc parallel loop tile(2, 2)
659 !CHECK: acc.parallel {
660 !CHECK: [[TILESIZE1:%.*]] = arith.constant 2 : i32
661 !CHECK: [[TILESIZE2:%.*]] = arith.constant 2 : i32
662 !CHECK: acc.loop tile([[TILESIZE1]]: i32, [[TILESIZE2]]: i32) {
669 !$acc parallel loop tile(tileSize)
674 !CHECK: acc.parallel {
675 !CHECK: acc.loop tile(%{{.*}}: i32) {
682 !$acc parallel loop tile(tileSize, tileSize)
689 !CHECK: acc.parallel {
690 !CHECK: acc.loop tile(%{{.*}}: i32, %{{.*}}: i32) {
697 end subroutine acc_parallel_loop