79 Commits

Author SHA1 Message Date
Valentin Clement
61807f5c29
[mlir][openacc] Add wait attribute and variadic operand
OpenACC 3.2 allowed the wait clause to the data construct. This patch
adds a unit attribute and a variadic operand to the data operation to model
the wait clause in a similar way it was added to other data operation.
The attribute models the presence of the clause without any argument. When
arguments are provided they are placed in the wait operand.

Depends on D154111

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D154131
2023-06-30 10:04:49 -07:00
Valentin Clement
ecc7adc46c
[mlir][openacc] Add async attribute and optional operand
OpenACC 3.2 allowed the async clause to the data construct. This patch
adds a unit attribute and an optional operand to the data operation to model
the data clause in a similar way it was added to other data operation.
The attribute models the presence of the clause without any argument. When
an argument is provided it is placed in the async operand.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D154111
2023-06-30 10:03:48 -07:00
Valentin Clement
c4a63b8ee1
[mlir][openacc] Switch numGangs to a variadic operand
In the latest spec, the `num_gangs` clause accepts up to three
arguments. Update the dialect to swicth `numGangs` operands from
optional single operand to a variadic operand. The verifier limits
the number of operands to three as specified in the spec.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153796
2023-06-27 11:08:44 -07:00
Valentin Clement
ff86ce65f6
[flang][openacc] Add lowering support for 1d array reduction for add/mul operator
Lower 1d array reduction for add and mul operator. Multi-dimensional arrays and
other operator will follow.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153448
2023-06-22 13:09:48 -07:00
Valentin Clement
8fb247e2de
[mlir][openacc] Add acc.firstprivate operation as data entry operation
acc.firstprivate operation will be used as data entry operation
for the firstprivate operands.

Depends on D152970

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D152972
2023-06-21 14:18:48 -07:00
Valentin Clement
cfba521dbd
[mlir][openacc] Add acc.private operation as data entry operation
acc.private operation will be used as data entry operation
for the private operands.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D152970
2023-06-21 14:17:32 -07:00
Valentin Clement
e6d8598e13
[mlir][flang][openacc] Use new firstprivate representation for compute construct
Use the new firstprivate representation on the comupte construct.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151975
2023-06-13 20:32:23 -07:00
Valentin Clement
7f3d2cc26b
[mlir][openacc] Add gang dim operand to acc.loop operation
OpenACC 3.3 introduces a dim argument on the gang clause. This patch
adds a new operand for it on the acc.loop and update the custom
gang clause parser/printer for it.

Depends on D151970

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151971
2023-06-13 13:39:29 -07:00
Valentin Clement
2e69944a61
[mlir][openacc][NFC] Fix current gang clause parser
The custom parser for the gang values was not implemented correctly.
This patch fixes the noted issue and allows the num/static values
to appear in any order.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151970
2023-06-13 11:16:58 -07:00
Valentin Clement
6763f5918c
[mlir][openacc] Use new reduction design in acc.loop
Use the new reduction design in acc.loop operation.

Depends on D151146

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151164
2023-05-24 10:51:39 -07:00
Valentin Clement
74f15d9c0b
[mlir][openacc] Add check for the private list in acc.serial
Add the missing check on private list information. The
check is the same than the one done for acc.parallel.

Depends on D151146

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151149
2023-05-24 10:43:29 -07:00
Valentin Clement
eaf29b3261
[mlir][openacc] Add check for the private list in acc.serial
Add the missing check on private list information. The
check is the same than the one done for acc.parallel.

Depends on D151146

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151149
2023-05-24 10:39:34 -07:00
Valentin Clement
f4f53f8b90
[mlir][openacc] Use new reduction design in acc.parallel
After D150818 the reduction clause is represented
with a acc.reduction.recipe operation and an operand.
This patch updates the acc.parallel op for the new design.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151146
2023-05-24 10:38:25 -07:00
Valentin Clement
6a3312f326
[mlir][openacc] destroy region on firstprivate.recipe is optional
The destroy region is optional but the verifier was enforcing it.
Update the verifier and make it clear in the definition.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D151239
2023-05-24 07:58:06 -07:00
Valentin Clement
f7d92d45a8
[mlir][openacc] Use new private representation in acc.serial
Update acc.serial private operands list to use the new design
introduced in D150622.

Test in flang/test/Lower/OpenACC/acc-parallel.f90 and
flang/test/Lower/OpenACC/acc-parallel-loop.f90 are temporarly
disabled and will be enabled with updated lowering in the next
patch.

Depends on D150971

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D150972
2023-05-22 09:50:34 -07:00
Valentin Clement
c067c6e55d
[mlir][openacc] Use new private representation in acc.parallel
Update acc.parallel private operands list to use the new design
introduced in D150622.

Test in flang/test/Lower/OpenACC/acc-parallel.f90 and
flang/test/Lower/OpenACC/acc-parallel-loop.f90 are temporarly
disabled and will be enabled with updated lowering in the follow-up
patch.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D150971
2023-05-22 09:49:31 -07:00
Valentin Clement
12f3ae6fe6
[mlir][openacc] Add reduction representation
Similarly to D150622 for private clause, the reduction is currently not
modeled in a good way. This patch is inspired by the reduction representation
in the omp dialect (D105358) and make a new representation for the reduction in
the OpenACC dialect.

A new operation is introduced to model the sequences of operation needed to
initialize a local reduction value and how to combine two values during the
reduction. The operation requires two mandatory regions.

  1. The init region specifies how to initialize the local reduction
     value. The region has an argument that contains the value of the
     reduction accumulator at the start of the reduction. It is expected to
     `acc.yield` the new value.
  2. The reduction region contains a sequences of operations to combine two
     values of the reduction type into one. It has two arguments and it is
     expected to `acc.yield` the combined value.

Example:

```mlir
acc.reduction.recipe @reduction_add_i64 : i64 init reduction_operator<add> {
^bb0(%0: i64):
  // init region contains a sequence of operations to initialize the local
  // reduction value as specified in 2.5.15
  %c0 = arith.constant 0 : i64
  acc.yield %c0 : i64
} reduction {
^bb0(%0: i64, %1: i64)
  // reduction region contains a sequence of operations to combine
  // two values into one.
  %2 = arith.addi %0, %1 : i64
  acc.yield %2 : i64
}

// The reduction symbol is then used in the corresponding operation.
acc.parallel reduction(@reduction_add_i64 -> %a : i64) {
}

Reviewed By: razvanlupusoru, vzakhari

Differential Revision: https://reviews.llvm.org/D150818
2023-05-18 16:21:18 -07:00
Valentin Clement
8497dfdf5f
[mlir][openacc] Add firstprivate representation
Add a representation for firstprivate clause modeled on the
private representation added in D150622.
The firstprivate recipe operation has an additional mandatory
region representing a sequences of operations needed to copy
the initial value to the created private copy.

Depends on D150622

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D150729
2023-05-17 11:18:30 -07:00
Valentin Clement
9c3299b859
[mlir][openacc] Add private representation
Currently privatization is not well represented in the OpenACC dialect. This
patch is a prototype to model privatization with a dedicated operation that
declares how the private value is created and destroyed.

The newly introduced operation is `acc.private.recipe` and it declares
an OpenACC privatization. The operation requires one mandatory and
one optional region.

  1. The initializer region specifies how to create and initialize a new
     private value. For example in Fortran, a derived-type might have a
     default initialization. The region has an argument that contains the
     value that need to be privatized. This is useful if the type is not
     a known at compile time and the private value is needed to create its
     copy.
  2. The destroy region specifies how to destruct the value when it reaches
     its end of life. It takes the privatized value as argument.

A same privatization can be used for multiple operand if they have the same
type and do not require a specific default initialization.

Example:

```mlir
acc.private.recipe @privatization_f32 : f32 init {
^bb0(%0: f32):
  // init region contains a sequence of operations to create and initialize the
  // copy if needed.
} destroy {
^bb0(%0: f32):
  // destroy region contains a sequences of operations to destruct the created
  // copy.
}

// The privatization symbol is then used in the corresponding operation.
acc.parallel private(@privatization_f32 -> %a : f32) {
}
```

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D150622
2023-05-17 11:08:24 -07:00
Valentin Clement
c3c73e5d40
[mlir][openacc] Add canonicalization pattern for acc.host_data
Add if condition removal pattern for acc.host_data in a same way as
acc.enter_data, acc.exit_data and acc.update.

The condition is removed from the op if it is a true constant. If
it is a false constant then the region is inlined before the op
and the op is removed.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D150480
2023-05-12 16:57:58 -07:00
Valentin Clement
5cbe3381a6
[mlir][openacc] Add host_data operation
The acc.host_data operation models the OpenACC
host_data construct (2.8). The host_data construct
defines a region where the address of data in device memory
available on the host. The operation is modeled in a similar way
than acc.data operation.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D150289
2023-05-11 14:55:25 -07:00
Valentin Clement
1e463942f4
[mlir][openacc] Cleanup acc.kernels from old data clause operands
Remove old clause operands from acc.kernels operation since
the new dataOperands is now in place.
private and firstprivate will receive some redesign but are
not part of the new dataOperands.

Depends on D150224

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D150225
2023-05-10 08:38:03 -07:00
Valentin Clement
3484745a5f
[mlir][openacc] Cleanup acc.serial from old data clause operands
Remove old clause operands from acc.serial operation since
the new dataOperands is now in place.
private and firstprivate will receive some redesign but are
not part of the new dataOperands.

Depends on D150207

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D150224
2023-05-10 08:34:25 -07:00
Valentin Clement
647db57cdd
[mlir][openacc][NFC] Add missing check lines for acc.update tests
D149909 was missing the check lines in the ops.mlir lit test.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D150232
2023-05-10 08:24:28 -07:00
Valentin Clement
5e983942d5
[mlir][openacc] Cleanup acc.parallel from old data clause operands
Remove old clause operands from acc.parallel operation since
the new dataOperands is now in place.
private, firstprivate and reductions will receive some redesign but are
not part of the new dataOperands.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D150207
2023-05-09 14:57:50 -07:00
Valentin Clement
46e1b095c9
[mlir][openacc] Cleanup acc.data from old data clause operands
Since the new data operand operations have been added in D148389 and
adopted on acc.data in D149673, the old clause operands are no longer
needed.

The LegalizeDataOpForLLVMTranslation will become obsolete when all
operations will be cleaned. For the time being only the appropriate
part are being removed.

processOperands will also receive some updates once all the operands
will be coming from an acc data operand operation.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D150155
2023-05-09 13:21:37 -07:00
Valentin Clement
15a480c05e
[mlir][openacc] Cleanup acc.exit_data from old data clause operands
Since the new data operand operations have been added in D148389 and
adopted on acc.exit_data in D149601, the old clause operands are no longer
needed.

The LegalizeDataOpForLLVMTranslation will become obsolete when all
operations will be cleaned. For the time being only the appropriate
part are being removed.

processOperands will also receive some updates once all the operands
will be coming from an acc data operand operation.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D150145
2023-05-09 11:36:48 -07:00
Valentin Clement
9dec07f44a
[mlir][openacc] Cleanup acc.enter_data from old data clause operands
Since the new data operand operations have been added in D148389 and
adopted on acc.enter_data in D148721, the old clause operands are no longer
needed.

The LegalizeDataOpForLLVMTranslation will become obsolete when all
operations will be cleaned. For the time being only the appropriate
part are being removed.

processOperands will also receive some updates once all the operands
will be coming from an acc data operand operation.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D150132
2023-05-09 09:01:30 -07:00
Valentin Clement
689afa88ae
[mlir][openacc] Cleanup acc.update from old data clause operands
Since the new data operand operations have been added in D148389 and
adopted on acc.update in D149909, the old clause operands are no longer
needed. This is a first patch to start cleaning the OpenACC operations
with data clause operands.

The `LegalizeDataOpForLLVMTranslation` will become obsolete when all
operations will be cleaned. For the time being only the appropriate
part are being removed.

`processOperands` will also receive some updates once all the operands
will be coming from an acc data operand operation.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D150053
2023-05-08 10:03:28 -07:00
Valentin Clement
aad53e3b26
[mlir][openacc] Add verifier for dataOperands on compute operations
Data operands associated with acc.parallel, acc.serial and
acc.kernels should comes from acc data entry/exit operations
or acc.getdeviceptr.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D149994
2023-05-08 09:36:57 -07:00
Valentin Clement
78a09cbd3e
[mlir][opeancc] Update acc.update verifier for dataOperands
Data operands associated with acc.update should comes
from acc data entry/exit operations or acc.getdeviceptr.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D149990
2023-05-08 09:29:29 -07:00
Valentin Clement
7cb9629920
[mlir][openacc] Update acc.enter_data verifier for dataOperands
Data operands associated with acc.enter_data should comes
from acc data entry operations.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D149991
2023-05-08 09:28:31 -07:00
Valentin Clement
a7b50effcf
[mlir][openacc] Update acc.data verifier for dataOperands
Data operands associated with acc.data should comes
from acc data entry/exit operations or acc.getdeviceptr.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D149992
2023-05-08 09:27:46 -07:00
Valentin Clement
437bc5640f
[mlir][openacc] Switch host/device clauses to data operand operations
Introduce acc.update_host and acc.update_device as data
operands operation to be used by the acc.update op.

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D149909
2023-05-05 12:01:27 -07:00
Valentin Clement
ed35b584da
[mlir][openacc] Restrict types for acc.bounds operands to index or integer type
Values in bounds are expected to have integer or index types. Enforce
this expectation by restricting the type to be IntOrIndex.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148839
2023-04-20 14:44:19 -07:00
Razvan Lupusoru
70bd2b8b35 [mlir][openacc] Refine data operation data clause attribute
The data operations added in D148389 hold two data clause fields:
"dataClause" and "decomposedFrom". However, in most cases, dataClause
field holds a default value (except for acc_copyin_readonly,
acc_create_zero, and acc_copyout_zero).

The decomposedFrom field holds the original clause specified by user.
As work began on lowering to these new operations [1], it seems that
having both fields adds a bit of ambiguity. There is only one scenario
where we actually intended to use both:
acc data copyout(zero:)

The original intent was that this clause would be decomposed to
the following operations:
acc.create {dataClause = acc_create_zero, decomposedFrom =
acc_copyout_zero}
...
acc.copyout {dataClause = acc_copyout_zero}

However, we can encode the zero semantics like so without need of both:
acc.create {dataClause = acc_copyout_zero}
...
acc.copyout {dataClause = acc_copyout_zero}

Thus get rid of the decomposedFrom field and update verifier checks
to check for all data clauses that can be decomposed to the particular
operation.

So now the dataClause holds the original user's clause which simplifies
understanding of the operation.

[1] https://reviews.llvm.org/D148721

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D148731
2023-04-19 15:06:21 -07:00
Razvan Lupusoru
c184dcb458 [mlir][openacc] Add separate acc data operations for OpenACC data clauses
As outlined in [1], data clauses are now implemented as separate operations
from the constructs that they belong to. Some of the highlighted benefits:
- Correctly represent dataflow of data operations
- Easier to track debugging information
- Friendlier to add attributes and to optimize operations

For now, all of the other operand lists are being kept until all references
to them in LLVM can be removed (such as those in flang lowering)

[1] https://discourse.llvm.org/t/rfc-openacc-dialect-data-operation-improvements/69825

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D148389
2023-04-18 15:36:38 -07:00
Valentin Clement
b6c1930d56
[mlir][openacc][NFC] Use assembly format for acc.loop
Use the assembly format with custom parser/printer
for specific clauses instead of a full custom parser/printer.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D148391
2023-04-17 12:45:04 -07:00
Valentin Clement
e1d1da71cb
Revert "[mlir][openacc][NFC] Use assembly format for acc.loop"
This reverts commit 7960993e4638c6243c4b37f05bb61b080fe13d43.
2023-04-17 08:05:51 -07:00
Valentin Clement
7960993e46
[mlir][openacc][NFC] Use assembly format for acc.loop
Use the assembly format with custom parser/printer
for specific clauses instead of a full custom parser/printer.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D148391
2023-04-17 07:53:19 -07:00
Valentin Clement
d56b74eac0
[mlir][openacc] Add acc.kernels operation
The acc.kernels operation models the OpenACC kernels construct.
The kernels construct defines a region of a program that is
compiled into a sequence of kernels to be executed on the current device.
The operation is modelled on the acc.parallel operation and will
receive similar updates when the data operands operations will
be implemented.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D148277
2023-04-14 08:30:23 -07:00
Valentin Clement
8a21dfe1bd
[mlir][openacc] Accept acc.serial has parent of acc.yield op
acc.serial op is modeled on the acc.parallel op.
acc.yield operation must then accept acc.serial has a parent
operation.

Reviewed By: PeteSteinfeld, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148258
2023-04-13 14:35:22 -07:00
Valentin Clement
f8330c1482
[mlir][openacc] Add acc.serial operation
The acc.serial operation models the OpenACC serial construct.
The serial construct defines a region of a program that is to be
executed sequentially on the current device.
The operation is modelled on the acc.parallel operation and will
receive similar updates when the data operands operations will
be implemented.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D148250
2023-04-13 10:35:56 -07:00
Valentin Clement
3d683cb9f1
[mlir][openacc][NFC] Use assembly format for acc.parallel
Remove the custoom parser and printer for the acc.parallel
operation and use the assembly format directly.

Reviewed By: PeteSteinfeld, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148183
2023-04-13 10:15:08 -07:00
Valentin Clement
2326480f37
[mlir][openacc][NFC] Use oilist in assembly format
Use the oilist syntax in assembly format where appropriate.
This makes the dialect format more flexible as an order
is not imposed for the clauses.

Reviewed By: PeteSteinfeld, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148154
2023-04-12 16:13:49 -07:00
Valentin Clement
7951ab12b9
[mlir][openacc] Relax the single block constraint on acc.loop
The acc.loop operation was constrained by the SingleBlockImplicitTerminator.
This patch relax this constraint to allow multiple block in the loop.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148025
2023-04-11 10:43:09 -07:00
Matthias Springer
e7790fbed3 [mlir] Add test-convergence option to Canonicalizer tests
This new option is set to `false` by default. It should  be set only in Canonicalizer tests to detect faulty canonicalization patterns. I.e., patterns that prevent the canonicalizer from converging. The canonicalizer should always convergence on such small unit tests that we have in `canonicalize.mlir`.

Two faulty canonicalization patterns were detected and fixed with this change.

Differential Revision: https://reviews.llvm.org/D140873
2023-01-04 12:02:21 +01:00
River Riddle
ab9cdf09f4 [mlir:Parser] Don't use strings for the "ugly" form of Attribute/Type syntax
This commit refactors the syntax of "ugly" attribute/type formats to not use
strings for wrapping. This means that moving forward attirbutes and type formats
will always need to be in some recognizable form, i.e. if they use incompatible
characters they will need to manually wrap those in a string, the framework will
no longer do it automatically.

This has the benefit of greatly simplifying how parsing attributes/types work, given
that we currently rely on some extremely complicated nested parser logic which is
quite problematic for a myriad of reasons; unecessary complexity(we create a nested
source manager/lexer/etc.), diagnostic locations can be off/wrong given string escaping,
etc.

Differential Revision: https://reviews.llvm.org/D118505
2022-07-05 16:20:30 -07:00
River Riddle
0254b0bcf0 [mlir][NFC] Update textual references of func to func.func in LLVM/Math/MemRef/NVGPU/OpenACC/OpenMP/Quant/SCF/Shape tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:28 -07:00
River Riddle
ef72cf4413 [mlir][NFC] Update OpenACC/OpenMP operations to use hasVerifier instead of verifier
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118825
2022-02-02 13:34:30 -08:00