Skip to content

Commit

Permalink
[mlir][openacc][flang] Simplify gang, vector and worker representation (
Browse files Browse the repository at this point in the history
#77667)

The IR representation for gang, vector and worker has grown with the
support for device_type. This patch simplify the IR representation for
gang, vector and worker information on the acc.loop operation.

When the only the keyword is present without any values, the information
is printed at the same place than when there is values. The device_type
is omitted if there is no values and it is equal to None. Otherwise the
full information is displayed. First the keyword only device_type
information and then the values with their device_type.
  • Loading branch information
clementval committed Jan 11, 2024
1 parent 37c1a5e commit 40f5f90
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 102 deletions.
12 changes: 6 additions & 6 deletions flang/test/Lower/OpenACC/acc-kernels-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ subroutine acc_kernels_loop
END DO

! CHECK: acc.kernels {
! CHECK: acc.loop {
! CHECK: acc.loop gang {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {gang = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.terminator
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -550,10 +550,10 @@ subroutine acc_kernels_loop
a(i) = b(i)
END DO
! CHECK: acc.kernels {
! CHECK: acc.loop {
! CHECK: acc.loop vector {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {vector = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.terminator
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -591,10 +591,10 @@ subroutine acc_kernels_loop
END DO

! CHECK: acc.kernels {
! CHECK: acc.loop {
! CHECK: acc.loop worker {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {worker = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.terminator
! CHECK-NEXT: }{{$}}

Expand Down
18 changes: 12 additions & 6 deletions flang/test/Lower/OpenACC/acc-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop {
!CHECK: acc.loop gang {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: } attributes {gang = [#acc.device_type<none>]}{{$}}
!CHECK-NEXT: }{{$}}

!$acc loop gang(num: 8)
DO i = 1, n
Expand Down Expand Up @@ -109,10 +109,10 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop {
!CHECK: acc.loop vector {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: } attributes {vector = [#acc.device_type<none>]}{{$}}
!CHECK-NEXT: }{{$}}

!$acc loop vector(128)
DO i = 1, n
Expand Down Expand Up @@ -141,10 +141,10 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop {
!CHECK: acc.loop worker {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: } attributes {worker = [#acc.device_type<none>]}{{$}}
!CHECK-NEXT: }{{$}}

!$acc loop worker(128)
DO i = 1, n
Expand Down Expand Up @@ -320,4 +320,10 @@ program acc_loop
! CHECK: acc.loop
! CHECK: fir.do_loop

!$acc loop gang device_type(nvidia) gang(8)
DO i = 1, n
END DO

! CHECK: acc.loop gang([#acc.device_type<none>], {num=%c8{{.*}} : i32} [#acc.device_type<nvidia>])

end program
12 changes: 6 additions & 6 deletions flang/test/Lower/OpenACC/acc-parallel-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,10 @@ subroutine acc_parallel_loop
END DO

! CHECK: acc.parallel {
! CHECK: acc.loop {
! CHECK: acc.loop gang {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {gang = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -565,10 +565,10 @@ subroutine acc_parallel_loop
a(i) = b(i)
END DO
! CHECK: acc.parallel {
! CHECK: acc.loop {
! CHECK: acc.loop vector {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {vector = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -606,10 +606,10 @@ subroutine acc_parallel_loop
END DO

! CHECK: acc.parallel {
! CHECK: acc.loop {
! CHECK: acc.loop worker {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {worker = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down
12 changes: 6 additions & 6 deletions flang/test/Lower/OpenACC/acc-serial-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ subroutine acc_serial_loop
END DO

! CHECK: acc.serial {
! CHECK: acc.loop {
! CHECK: acc.loop gang {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {gang = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -500,10 +500,10 @@ subroutine acc_serial_loop
a(i) = b(i)
END DO
! CHECK: acc.serial {
! CHECK: acc.loop {
! CHECK: acc.loop vector {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {vector = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down Expand Up @@ -541,10 +541,10 @@ subroutine acc_serial_loop
END DO

! CHECK: acc.serial {
! CHECK: acc.loop {
! CHECK: acc.loop worker {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: } attributes {worker = [#acc.device_type<none>]}{{$}}
! CHECK-NEXT: }{{$}}
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down
20 changes: 9 additions & 11 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
Example:

```mlir
acc.loop {
acc.loop gang vector {
scf.for %arg3 = %c0 to %c10 step %c1 {
scf.for %arg4 = %c0 to %c10 step %c1 {
scf.for %arg5 = %c0 to %c10 step %c1 {
Expand All @@ -1492,10 +1492,7 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
}
}
acc.yield
} attributes {
collapse = [3], gang = [#acc.device_type<none>],
vector = [#acc.device_type<none>]
}
} attributes { collapse = [3] }
```
}];

Expand Down Expand Up @@ -1613,13 +1610,14 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
let hasCustomAssemblyFormat = 1;
let assemblyFormat = [{
oilist(
`gang` `` `(` custom<GangClause>($gangOperands, type($gangOperands),
`gang` `` custom<GangClause>($gangOperands, type($gangOperands),
$gangOperandsArgType, $gangOperandsDeviceType,
$gangOperandsSegments) `)`
| `worker` `` `(` custom<DeviceTypeOperands>($workerNumOperands,
type($workerNumOperands), $workerNumOperandsDeviceType) `)`
| `vector` `` `(` custom<DeviceTypeOperands>($vectorOperands,
type($vectorOperands), $vectorOperandsDeviceType) `)`
$gangOperandsSegments, $gang)
| `worker` `` custom<DeviceTypeOperandsWithKeywordOnly>(
$workerNumOperands, type($workerNumOperands),
$workerNumOperandsDeviceType, $worker)
| `vector` `` custom<DeviceTypeOperandsWithKeywordOnly>($vectorOperands,
type($vectorOperands), $vectorOperandsDeviceType, $vector)
| `private` `(` custom<SymOperandList>(
$privateOperands, type($privateOperands), $privatizations) `)`
| `tile` `(` custom<DeviceTypeOperandsWithSegment>($tileOperands,
Expand Down

0 comments on commit 40f5f90

Please sign in to comment.