Commit Graph

117 Commits

Author SHA1 Message Date
Razvan Lupusoru
a435e1f63b [acc] Add attribute for combined constructs (#80319)
Combined constructs are decomposed into separate operations. However,
this does not adhere to `acc` dialect's goal to be able to regenerate
semantically equivalent clauses as user's intent. Thus, add an attribute
to keep track of the combined constructs.
2024-03-07 10:06:47 -08:00
Valentin Clement (バレンタイン クレメン)
4c9717c3be [mlir][openacc] Add private/reduction in legalize data pass (#80882)
This is a follow up to #80351 and adds private and reduction operands
from acc.loop, acc.parallel and acc.serial operations.
2024-02-06 13:21:13 -08:00
Valentin Clement (バレンタイン クレメン)
6b42625b1f [mlir][openacc] Simplify IR with acc.loop control (#80387)
When the new `acc.loop` design was introduced some of the loop
information like `gang`/`vector`/`worker` were also updated to support
`device_type`.
With a conflict in parsing/printing, the keyword only value for
`async`/`gang`/`vector`/`worker` were printed/parsed with an empty set
of parenthesis `()`. To make the IR clearer to read and similar across
the operations, the loop control part of is now prefixed by `control`
and this allow to remove the need of the empty `()`.
2024-02-05 14:22:36 -08:00
Valentin Clement
0d091206dd [mlir][openacc] Add legalize data pass for compute operation (#80351)
This patch adds a simple pass to replace the uses inside compute operation. It
replaces the `varPtr` values with their corresponding `accPtr` values gathered
through the dataClauseOperands.

private and reductions variables are not included in this pass since they will
normally be replace when they are materialized.

Reland with fix for dependencies
2024-02-05 13:40:41 -08:00
Valentin Clement
4b6062619a Revert "[mlir][openacc] Add legalize data pass for compute operation (#80351)"
This reverts commit fa7d0d3e35.
2024-02-05 12:57:54 -08:00
Valentin Clement
fa7d0d3e35 [mlir][openacc] Add legalize data pass for compute operation (#80351)
This patch adds a simple pass to replace the uses inside compute operation. It
replaces the `varPtr` values with their corresponding `accPtr` values gathered
through the dataClauseOperands.

private and reductions variables are not included in this pass since they will
normally be replace when they are materialized.
2024-02-05 12:34:38 -08:00
Valentin Clement (バレンタイン クレメン)
e2bb91b25c Revert "[mlir][openacc] Add legalize data pass for compute operation" (#80710)
Reverts llvm/llvm-project#80351

Breaks some buildbot
2024-02-05 08:47:23 -08:00
Valentin Clement (バレンタイン クレメン)
29d47513b3 [mlir][openacc] Add legalize data pass for compute operation (#80351)
This patch adds a simple pass to replace the uses inside compute
operation. It replaces the `varPtr` values with their corresponding
`accPtr` values gathered through the dataClauseOperands.

private and reductions variables are not included in this pass since
they will normally be replace when they are materialized.

---------

Co-authored-by: Slava Zakharin <szakharin@nvidia.com>
2024-02-05 08:38:13 -08:00
Valentin Clement (バレンタイン クレメン)
c09dc2d985 [mlir][openacc][flang] Support wait devnum and clean async/wait IR (#79525)
- Support wait(devnum: ) with device_type support on all operations that
require it
- devnum value is stored as the first value of waitOperands in its
device_type sub-segment. The hasWaitDevnum attribute inform which
sub-segment has a wait(devnum) value.
- Make async/wait information homogenous on compute ops, data and update
op.
- Unify operands/attributes names across operations and use the same
custom parser/printer
2024-01-28 21:17:36 -08:00
Valentin Clement (バレンタイン クレメン)
78ef032862 [mlir][flang][openacc] Add device_type support for update op (#78764)
Add support for device_type information on the acc.update operation and
update lowering from Flang.
2024-01-25 13:58:58 -08:00
Valentin Clement (バレンタイン クレメン)
3eb4178b9c [mlir][openacc] Update acc.loop to be a proper loop like operation (#67355)
The initial design of the `acc.loop` was to be an operation that
encapsulates a loop like operation. This was an early design and we now
want to change it so the `acc.loop` operation becomes a real loop-like
operation by implementing the LoopLikeInterface.

Differential Revision: https://reviews.llvm.org/D159229

This patch is just moved from Phabricator to github
2024-01-22 10:31:29 -08:00
Valentin Clement (バレンタイン クレメン)
b5df6a90f5 [mlir][openacc] Fix num_gang parser (#78792)
Nb of operand per segment is not correctly computed.
2024-01-22 08:40:33 -08:00
Valentin Clement (バレンタイン クレメン)
b06bc7c6a0 [mlir][flang][openacc] Device type support on acc routine op (#78375)
This patch add support for device_type on the acc.routine operation.
device_type can be specified on seq, worker, vector, gang and bind
information.

The support is following the same design than the one for compute
operations, data operation and the loop operation.
2024-01-18 09:04:11 -08:00
Valentin Clement (バレンタイン クレメン)
40f5f90507 [mlir][openacc][flang] Simplify gang, vector and worker representation (#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.
2024-01-11 13:02:06 -08:00
Valentin Clement (バレンタイン クレメン)
e456689fb3 [mlir][flang][openacc] Support device_type on loop construct (#76892)
This is adding support for `device_type` clause representation in the
OpenACC MLIR dialect on the acc.loop operation and adjust flang to lower
correctly to the new representation.

Each "value" that can be impacted by a `device_type` clause is now
associated with an array attribute that carry this information. This
includes:
- `worker` clause information
- `gang` clause information
- `vector` clause information
- `collapse` clause information
- `tile` clause information

The representation of the `gang` clause information has been updated and
all values are now carried in a single operand segment. This segment is
then subdivided by `device_type`. Each value in a segment is also
associated with a `GangArgType` so it can be differentiated
(num/dim/static). This simplify the handling of gang values an limit the
number of new attributes needed.

When the clause can be associated with the operation without any value
(`gang`, `vector`, `worker`). These are represented by a dedicated
attributes with device_type information.

Extra getter functions are provided to make it easier to retrieve a
value based on a device_type.
2024-01-04 16:33:33 -08:00
Valentin Clement (バレンタイン クレメン)
71ec30132b [mlir][openacc] Add device_type support for data operation (#76126)
Following #75864, this patch adds device_type support to the data
operation on the async and wait operands and attributes.
2024-01-04 16:33:20 -08:00
Valentin Clement
a25da1a921 [mlir][openacc] Add device_type support for compute operations (#75864)
Re-land PR after being reverted because of buildbot failures.

This patch adds representation for `device_type` clause information on
compute construct (parallel, kernels, serial).

The `device_type` clause on compute construct impacts clauses that
appear after it. The values impacted by `device_type` are now tied with
an attribute array that represent the device_type associated with them.
`DeviceType::None` is used to represent the value produced by a clause
before any `device_type`. The operands and the attribute information are
parser/printed together.

This is an example with `vector_length` clause. The first value (64) is
not impacted by `device_type` so it will be represented with
DeviceType::None. None is not printed. The second value (128) is tied
with the `device_type(multicore)` clause.
```
!$acc parallel vector_length(64) device_type(multicore) vector_length(256)
```
```
acc.parallel vector_length(%c64 : i32, %c128 : i32 [#acc.device_type<multicore>]) {
}
```

When multiple values can be produced for a single clause like
`num_gangs` and `wait`, an extra attribute describe the number of values
belonging to each `device_type`. Values and attributes are
parsed/printed together.

```
acc.parallel num_gangs({%c2 : i32, %c4 : i32}, {%c4 : i32} [#acc.device_type<nvidia>])
```

While preparing this patch I noticed that the wait devnum is not part of
the operations and is not lowered. It will be added in a follow up
patch.
2023-12-20 20:36:09 -08:00
Valentin Clement
553748356c Revert "[mlir][openacc] Add device_type support for compute operations (#75864)"
This reverts commit 8b885eb90f.
2023-12-20 16:08:10 -08:00
Valentin Clement (バレンタイン クレメン)
8b885eb90f [mlir][openacc] Add device_type support for compute operations (#75864)
This patch adds representation for `device_type` clause information on
compute construct (parallel, kernels, serial).

The `device_type` clause on compute construct impacts clauses that
appear after it. The values impacted by `device_type` are now tied with
an attribute array that represent the device_type associated with them.
`DeviceType::None` is used to represent the value produced by a clause
before any `device_type`. The operands and the attribute information are
parser/printed together.

This is an example with `vector_length` clause. The first value (64) is
not impacted by `device_type` so it will be represented with
DeviceType::None. None is not printed. The second value (128) is tied
with the `device_type(multicore)` clause.
```
!$acc parallel vector_length(64) device_type(multicore) vector_length(256)
```
```
acc.parallel vector_length(%c64 : i32, %c128 : i32 [#acc.device_type<multicore>]) {
}
```

When multiple values can be produced for a single clause like
`num_gangs` and `wait`, an extra attribute describe the number of values
belonging to each `device_type`. Values and attributes are
parsed/printed together.

```
acc.parallel num_gangs({%c2 : i32, %c4 : i32}, {%c4 : i32} [#acc.device_type<nvidia>])
```

While preparing this patch I noticed that the wait devnum is not part of
the operations and is not lowered. It will be added in a follow up
patch.
2023-12-20 13:45:47 -08:00
Valentin Clement (バレンタイン クレメン)
ab212fc94c [mlir][openacc] Switch * to star which is more MLIR friendly (#74662)
`*` is not friendly to the MLIR attribute parser and will fail to be
parsed. Switch the `*` enum representation to `star`.
2023-12-06 14:53:23 -08:00
Christian Ulmann
7ed96b1c0d [MLIR][LLVM] Remove last typed pointer remnants from tests (#71232)
This commit removes all LLVM dialect typed pointers from the lit tests.
Typed pointers have been deprecated for a while now and it's planned to
soon remove them from the LLVM dialect.

Related PSA:
https://discourse.llvm.org/t/psa-removal-of-typed-pointers-from-the-llvm-dialect/74502
2023-11-04 14:13:31 +01:00
Valentin Clement (バレンタイン クレメン)
f706837e2b [flang][mlir][openacc] Switch device_type representation to an enum (#70250)
Switch the representation from scalar integer to a enumeration. The
parser transform the string in the input to the correct enumeration.
2023-10-30 09:51:42 -07:00
Valentin Clement (バレンタイン クレメン)
d9568bd4aa [flang][openacc] Support array with dynamic extents in firstprivate recipe (#69026)
Add lowering support for array with dynamic extents in the firstprivate
recipe. Generalize the lowering so static shaped arrays and array with
dynamic extents use the same path.

Some cleaning code is taken from #68836 that is not landed yet.
2023-10-16 12:51:01 -07:00
Valentin Clement
470b65270b [flang][openacc] Support allocatable and pointer array in private recipe
Add support for pointer and allocatable arrays in private clause.
2023-10-09 10:20:58 -07:00
Valentin Clement (バレンタイン クレメン)
996171a412 [mlir][openacc] Model acc cache directive as data entry operands on acc.loop (#65521)
The `cache` directive may appear at the top of (inside of) a loop. It
specifies array elements or subarrays that should be fetched into the
highest level of the cache for the body of the loop.

The `cache` directive is modeled as a data entry operands attached to
the acc.loop operation.
2023-09-11 13:38:03 -07:00
Razvan Lupusoru
61278ec348 [openacc][openmp] Add dialect representation for acc atomic operations (#65493)
The OpenACC standard specifies an `atomic` construct in section 2.12 (of
3.3 spec), used to ensure that a specific location is accessed or
updated atomically. Four different clauses are allowed: `read`, `write`,
`update`, or `capture`. If no clause appears, it is as if `update` is
used.

The OpenMP specification defines the same clauses for `omp atomic`. The
types of expression and the clauses in the OpenACC spec match the OpenMP
spec exactly. The main difference is that the OpenMP specification is a
superset - it includes clauses for `hint` and `memory order`. It also
allows conditional expression statements. But otherwise, the expression
definition matches.

Thus, for OpenACC, we refactor and reuse the OpenMP implementation as
follows:
* The atomic operations are duplicated in OpenACC dialect. This is
preferable so that each language's semantics are precisely represented
even if specs have divergence.
* However, since semantics overlap, a common interface between the
atomic operations is being added. The semantics for the interfaces are
not generic enough to be used outside of OpenACC and OpenMP, and thus
new folders were added to hold common pieces of the two dialects.
* The atomic interfaces define common accessors (such as getting `x` or
`v`) which match the OpenMP and OpenACC specs. It also adds common
verifiers intended to be called by each dialect's operation verifier.
* The OpenMP write operation was updated to use `x` and `expr` to be
consistent with its other operations (that use naming based on spec).

The frontend lowering necessary to generate the dialect can also be
reused. This will be done in a follow up change.
2023-09-06 13:54:39 -07:00
Razvan Lupusoru
4bdc9057e9 [openacc] Add implicit flag to declare attribute
The declare attribute has been updated to allow implicit flag. This is
useful for variables that can be declare'd implicitly - like global
constants. The verifier has been updated to ensure that an implicit
declare'd variable has an implicit data action. The builder doesn't
require for this flag to be set so any code creating this attribute
will continue to work as-is.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D159124
2023-08-29 13:13:53 -07:00
Valentin Clement
b32839641c [mlir][openacc][NFC] Remove duplicated test 2023-08-23 14:20:50 -07:00
Valentin Clement
b90d6b237f [mlir][openacc] Switch deviceType to optional single operand
The standard suggests that the value for the `device_type` clause on the
`set` directive is a list but this does not makes sense. Restrict the number
of value to one so it matches the runtime function.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158644
2023-08-23 11:31:24 -07:00
Valentin Clement
4bac6ed492 [mlir][openacc] Add set operation
Introduce the acc.set operation that models the
acc set directive. Based on acc.init and acc.shutdown

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158554
2023-08-23 09:33:17 -07:00
Valentin Clement
804b9979c5 [mlir][openacc] Introduce acc.declare operation
The acc.declare operation represent the implicit
region of variable in the declare directive in the function
(and subroutine in fortran).

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158314
2023-08-21 08:30:07 -07:00
Valentin Clement
550b6f1167 [mlir][openacc] Add acc.declare_action attribute
iAdd the acc.declare_action attribute to attach pre/post
allocation/deallocation functions to operations.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157743
2023-08-14 10:41:13 -07:00
Razvan Lupusoru
52a0b6a662 [openacc] Add acc routine support to acc dialect
Adds representation for `acc routine` under new operation named
`acc.routine`. This operation is associated with a function symbol.
It also gets its own compiler generated synthetic symbol name so
that it can be referenced from the associated function. The clauses
associated with the `acc routine` directive are captured in the
`acc.routine` op.

The linking between the `func.func` and its `acc.routine` declaration
is done through the `acc.routine_info` attribute. In practice, a
single `acc routine` is associated with a function. But the spec does
not specifically restrict this - thus the 1:N relationship between
`func.func` and `acc.routine` allowed in the dialect. Additionally, it
makes sense that multiple acc routines could be used for a single
function depending on loop context - to allow flexible parallelization.

Most acc routine clauses are supported including `gang`, `gang(dim:)`,
`vector`, `worker`, `seq`, `nohost`, and `bind`. The only one not
supported is `device_type`. This is because most other clauses also
miss this and the effort to add support for it needs to be coordinated
and consistent.

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D156281
2023-07-26 15:06:39 -07:00
Valentin Clement
6674e578b9 [mlir][openacc] Fix acc.declare attribute on operation
The attribute on operations in ops.mlir were not DeclareAttr but
DataClauseAttr with the acc.declare attribute name. Update the test
and the verifier to work correctly with the expected DeclareAttr.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156262
2023-07-25 15:02:20 -07:00
Valentin Clement
1d49834280 [mlir][openacc] Relax verifier for the acc.reduction.recipe
Allow the init and combiner regions to have more
arguments to pass information.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D155656
2023-07-19 10:31:37 -07:00
Razvan Lupusoru
132c376a33 [openacc] Add attribute to hold declare data clause information
For variables in declare clauses, their producing operation should be
marked with the data clause for ease of lookup and consistency
verification. Thus add an attribute that can be used for this purpose
plus verification that declare data operation matches the declare
data clause on variable.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D155640
2023-07-19 07:54:57 -07:00
Razvan Lupusoru
b232054fac [openacc] Update data clause attribute definition
Instead of using the I64EnumAttr for the DataClause, now use
EnumAttr instead. This makes tests more readable since now
one can use the format #acc<data_clause acc_copyin> instead of
just the number.

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D155605
2023-07-18 11:39:33 -07:00
Razvan Lupusoru
7496177d98 [openacc] Add dialect definition for acc declare
A declare directive is used to specify the creation of a visible device
copy of a variable for the duration of the implicit data region as it
relates to the scope in which the variable is declared.

In order to support this, the following new operations were added:
1) `acc.global_ctor` and `acc.global_dtor`. These are used whenever the
declare directive applies to a global.
2) `acc.declare_enter` and `acc.declare_exit`. These operations are
modeled similarly to `acc.enter_data` and `acc.exit_data`. The reason
they are not modeled like `acc.data` is so that these operations can be
used both for globals and regions like functions.
3) `acc.declare_device_resident` and `acc.declare_link`. These
operations are modeled in a manner consistent with previously defined
data entry operation model.

The `acc.getdeviceptr` was generalized so that it can be used with
acc.declare_exit.

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D155322
2023-07-18 08:11:06 -07:00
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