256 Commits

Author SHA1 Message Date
Razvan Lupusoru
14e17ea1f6
[flang][acc] Add support for lowering combined constructs (#86696)
PR#80319 added support to record combined construct semantics via an
attribute. Add lowering support for this.
2024-03-26 12:52:13 -07:00
Krzysztof Parzyszek
84115494d6
[flang][Lower] Convert OMP Map and related functions to evaluate::Expr (#81626)
The related functions are `gatherDataOperandAddrAndBounds` and
`genBoundsOps`. The former is used in OpenACC as well, and it was
updated to pass evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions of index
expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns
optional Expr. Making it accept an optional Expr as input would reduce
the number of necessary checks when handling frequent optional values in
evaluator.

[Clause representation 4/6]
2024-03-20 15:00:29 -05:00
Tom Eccles
3b0a426b3f
[flang][NFC] move extractSequenceType helper out of OpenACC to share code (#84957)
Moving extractSequenceType to FIRType.h so that this can also be used
from OpenMP.

OpenMP array reductions 5/6
Previous PR: https://github.com/llvm/llvm-project/pull/84955
Next PR: https://github.com/llvm/llvm-project/pull/84958
2024-03-20 10:09:50 +00:00
Tom Eccles
860a40057d
[flang][NFC] move loadIfRef to FIRBuilder (#84306)
This will be useful for OpenMP too.

I changed the definition slightly to use `fir::isa_ref_type` (which also
includes llvm pointers) because I think it reads better using the common
type helpers. There shouldn't be any llvm pointers in lowering so this
isn't a functional change.
2024-03-08 10:33:43 +00:00
Peter Klausler
5a20a20803
[flang] Resolve "possible performance problem" issue spam (#79769)
Four "issues" on GitHub report possible performance problems, likely
detected by static analysis. None of them would ever make a measureable
difference in compilation time, but I'm resolving them to clean up the
open issues list.

Fixes https://github.com/llvm/llvm-project/issues/79703, .../79705,
.../79706, & .../79707.
2024-02-20 14:08:37 -08:00
Valentin Clement (バレンタイン クレメン)
135529aab0
[flang][openacc] Use the same iv privatized value in the loop region (#81821)
IV variable are privatized during acc loop lowering. An hlfir.declare
operation is added when mapping the symbol to the new private value. In
order to avoid using multiple value in the acc.loop region, we map the
symbol to the result of the hlfir.declare operation inserted.
2024-02-20 07:39:54 -08:00
Valentin Clement (バレンタイン クレメン)
58e8147d16
[flang][openacc] Use original input for base address with optional (#80931)
In #80317 the data op generation was updated to use correctly the #0
result from the hlfir.delcare op. In case of optional that are not
descriptor, it is preferable to use the original input for the varPtr
value of the OpenACC data op.
This patch also make sure that the descriptor value of optional is only
accessed when present.
2024-02-08 08:49:11 -08:00
Valentin Clement (バレンタイン クレメン)
3c8a5800f5
[flang][openacc] Place post allocate/deallocate attribute correctly (#79883)
The `acc.declate_action` attribute was sometime misplaced as reported in
#79770.
This patch updates the lowering code to place the
postAllocate/postDeallocate actions at the correct place.
2024-01-29 14:56:26 -08:00
Valentin Clement
4eeeeb305b
[flang][openacc] Remove waitDevnum unused variable 2024-01-28 21:31:33 -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 (バレンタイン クレメン)
e99c8aef5d
[flang][openacc] Lower DO CONCURRENT with acc loop (#79223)
Lower basic DO CONCURRENT with acc loop construct. The DO CONCURRENT is
lowered to an acc.loop operation.

This does not currently cover the DO CONCURRENT with locality specs.
2024-01-24 08:55:15 -08:00
Kazu Hirata
bcfdab8705 [flang] Fix a warning
This patch fixes:

  flang/lib/Lower/OpenACC.cpp:1964:15: error: unused variable
  'loopDirective' [-Werror,-Wunused-variable]
2024-01-22 11:24:55 -08:00
Valentin Clement (バレンタイン クレメン)
5062a178bf
[flang][openacc] Lower loop directive to the new acc.loop op design (#65417)
acc.loop was redesigned in https://reviews.llvm.org/D159229. This patch
updates the lowering to match the new op.

DO CONCURRENT construct will be added in a follow up patch.

Note that the pre-commit ci will fail until D159229 is merged. 

Depends on #67355
2024-01-22 10:31:37 -08:00
Valentin Clement (バレンタイン クレメン)
b8967e003e
[flang][openacc] Support multiple device_type when lowering (#78634)
routine, data, parallel, serial, kernels and loop construct all support
the device_type clause. This clause takes a list of device_type.
Previously the lowering code was assuming that the list s a single item.
This PR updates the lowering to handle any number of device_types.
2024-01-18 21:20:28 -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
c8ad802443
[flang][openacc] Carry device dependent info for routine in the module file 2024-01-11 13:57:23 -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 8b885eb90ff14862b579b191c3f469a5a4fed1bc.
2023-12-20 16:08:10 -08:00
Valentin Clement
e98082d90a
Revert "[flang][openacc] Remove unused waitdevnum"
This reverts commit 8fdc3b98b894bbbe301b13cf8fc89663e1cbac1a.
2023-12-20 16:07:57 -08:00
Valentin Clement
8fdc3b98b8
[flang][openacc] Remove unused waitdevnum 2023-12-20 14:01:51 -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
Razvan Lupusoru
a711b042fd
[acc] Initial implementation of MemoryEffects on acc operations (#75970)
The `acc` dialect operations now implement MemoryEffects interfaces in
the following ways:
- Data entry operations which may read host memory via `varPtr` are now
marked as so. The majority of them do NOT actually read the host memory.
For example, `acc.present` works on the basis of presence of pointer and
not necessarily what the data points to - so they are not marked as
reading the host memory. They still use `varPtr` though but this
dependency is reflected through ssa.
- Data clause operations which may mutate the data pointed to by
`accPtr` are marked as doing so.
- Data clause operations which update required structured or dynamic
runtime counters are marked as reading and writing the newly defined
`RuntimeCounters` resource. Some operations, like `acc.getdeviceptr` do
not actually use the runtime counters - but are marked as reading them
since the address obtained depends on the mapping operations which do
update the runtime counters. Namely, `acc.getdeviceptr` cannot be moved
across other mapping operations.
- Constructs are marked as writing to the `ConstructResource`. This may
be too strict but is needed for the following reasons: 1) Structured
constructs may not use `accPtr` and instead use `varPtr` - when this is
the case, data actions may be removed even when used. 2) Unstructured
constructs are currently used to aggregate multiple data actions. We do
not want such constructs removed or moved for now.
- Terminators are marked as `Pure` as in other dialects.

The current approach has the following limitations which may require
further improvements:
- Subsequent `acc.copyin` operations on same data do not actually read
host memory pointed to by `varPtr` but are still marked as so.
- Two `acc.delete` operations on same data may not mutate `accPtr` until
the runtime counters are zero (but are still marked as mutating).
- The `varPtrPtr` argument, when present, points to the address of
location of `varPtr`. When mapping to target device, an `accPtrPtr`
needs computed and this memory is mutated. This effect is not captured
since the current operations do not produce `accPtrPtr`.
- Runtime counter effects are imprecise since two operations with
differing `varPtr` increment/decrement different counters. Additionally,
operations with `varPtrPtr` mutate attachment counters.
- The `ConstructResource` is too strict and likely can be relaxed with
better modeling.
2023-12-20 07:11:19 -08:00
Valentin Clement (バレンタイン クレメン)
22426d9ecd
[flang][openacc/mp] Do not read bounds on absent box (#75252)
Make sure we only load box and read its bounds when it is present.
- Add `AddrAndBoundInfo` struct to be able to carry around the `addr`
and `isPresent` values. This is likely to grow so we can make all the
access in a single `fir.if` operation.
2023-12-15 13:02:40 -08:00
Valentin Clement (バレンタイン クレメン)
711809f37a
[flang][openacc/mp][NFC] Fix order of template arguments (#75538)
Some template parameters for the bounds ops generation have been
inverted. It should be consistent to be `BoundsOp, BoundsType`.
2023-12-14 21:13:38 -08:00
Valentin Clement (バレンタイン クレメン)
a9a5af8270
[flang][openacc] Support early return in acc.loop (#73841)
Early return is accepted in OpenACC loop not directly nested in a
compute construct. Since acc.loop operation has a region, the
`func.return` operation cannot be directly used inside the region.
An early return is materialized by an `acc.yield` operation returning a
`true` value. The standard end of the `acc.loop` region yield a `false`
value in this case.
A conditional branch operation on the `acc.loop` result will branch to
the `finalBlock` or just to the continue block whether an early exit was
produce in the acc.loop.
2023-11-30 14:25:03 -08:00
Valentin Clement (バレンタイン クレメン)
9365ed1e10
[flang][openacc] Add ability to link acc.declare_enter with acc.declare_exit ops (#72476) 2023-11-16 16:41:50 -08:00
Valentin Clement (バレンタイン クレメン)
a3700cc29d
[flang][openacc] Make implicit declare region unstructured (#71591)
Using an op with a region cause some issue with unstructured code. This
patch make use of acc.declare_enter and acc.declare_exit to represent
the implicit declare region.
2023-11-14 14:42:11 -08:00
Valentin Clement (バレンタイン クレメン)
90da688bac
[flang][openacc] Avoid creation of duplicate global ctor (#71846)
PR #70698 relax the duplication rule in acc declare clauses. This lead
to potential duplicate creation of the global constructor/destructor.
This patch make sure to not generate a duplicate ctor/dtor.
2023-11-09 12:57:30 -08:00
Valentin Clement (バレンタイン クレメン)
edfaae8726
[flang][openacc] Correctly lower acc routine in interface block (#71451)
When the acc routine directive was in an interface block in a
subroutine, the routine information was attached to the wrong
subroutine. This patch fixes this be retrieving the subroutine name in
the interface.
2023-11-06 17:48:45 -08:00
Valentin Clement (バレンタイン クレメン)
3c356eef31
[flang][openacc] Support variable from equivalence in data clauses (#71434)
The value for a var in an equivalence is represented by a `fir.ptr`.
Support this type in the recipe creation.
2023-11-06 15:49:40 -08:00
Slava Zakharin
ecb1fbaa13
[flang][openacc] Generate data bounds for array addressing. (#71254)
In cases like `copy(array(N))` it is still useful to represent
the data operand uniformly with `copy(array(N:N))`.
This change generates data bounds even if it is not an array
section with the triplets. The lower and the upper bounds
are the same and the extent is one in this case.
2023-11-06 14:45:46 -08:00
Valentin Clement
ad584a27f2
[flang][openacc][NFC] Remove unused variable 2023-11-06 14:43:36 -08:00
Valentin Clement (バレンタイン クレメン)
fdf3823c0e
[flang][openacc] Support variable in equivalence in declare directive (#71242)
A variable in equivalence share the storage units with one or more
objects. When lowered to FIR, the global created for the equivalence has
the name of one of the object. The variable also has an offset in the
storage unit.
This patch takes all of this into account for variable part of
equivalence used in a declare directive.
2023-11-06 14:36:24 -08:00
Valentin Clement (バレンタイン クレメン)
32d91449ef
[flang][openacc] Only issue a warning when acc routine func is not found (#70964)
Do not issue a hard error when the function in acc routine directive is
not present in the current translation unit. Only issue a warning.
2023-11-01 12:59:59 -07:00
Razvan Lupusoru
f5a5142571
[openacc] Update acc.loop to expose data operands (#70954)
The compute and data constructs implement getNumDataOperands and
getDataOperand. The acc.loop operation similarly has multiple data
operands - thus it makes sense to expose them the same way.

For loop, only private and reduction operands are exposed this way.
Technically, acc.loop also holds cache operands - but these are hints
not a data attribute.
2023-11-01 11:52:31 -07:00
Valentin Clement (バレンタイン クレメン)
0f8615f4dc
[flang][openacc][openmp] Set correct location on atomic operations (#70680)
The location set on atomic operations in both OpenMP and OpenACC was
completly off. The real location needs to be created from the source
CharBlock of the parse tree node of the respective atomic statement.
This patch updates locations in lowering for atomic operations.
2023-10-30 10:35:43 -07: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
Razvan Lupusoru
62ae549f57
[flang][openacc] Add implicit copy for reduction in combined construct (#70148)
After PR#69417, lowering for combined constructs was updated to adhere
to OpenACC 3.3, section 2.11: `A private or reduction clause on a
combined construct is treated as if it appeared on the loop construct.`

However, the second part of that paragraph notes `In addition, a
reduction clause on a combined construct implies a copy clause`. Since
the acc dialect decomposes combined constructs, it is important to
distinguish between the case where an explicit data clause is required
(as noted in section 2.6.2) and the case where an implicit data action
must be generated by compiler.
2023-10-25 07:27:57 -07:00
Valentin Clement (バレンタイン クレメン)
828674395b
[flang][openacc] Allow acc routine at the top level (#69936)
Some compilers allow the `$acc routine(<name>)` to be placed at the
program unit level. To be compatible, this patch enables the use of acc
routine at this level. These acc routine directives must have a name.
2023-10-24 09:17:48 -07:00
Razvan Lupusoru
54e46ba447
[flang][openacc] Fix post_alloc declare function ordering (#69980)
The declare actions were introduced to capture semantics dealing with
allocation of descriptor-based variable. However, the post_alloc action
has an ordering error. It needs to update descriptor first before the
mapping action of the data. The reason for this is that implicit attach
must occur during mapping action - but updating the descriptor
synchronizes it with the host copy (which would hold a host pointer).
2023-10-23 18:25:17 -07:00
Valentin Clement (バレンタイン クレメン)
d2e7a15dfb
[flang][openacc] Warn about misplaced end loop directive and ignore it (#69512)
Instead of raising an error for a misplaced `end loop directive`, just
warn about it and ignore it. This directive is an extension and is
optional.
2023-10-19 08:49:01 -07:00
Slava Zakharin
d0e8f3321e
[flang][openacc] Fixed private/reduction for combined constructs. (#69417)
According to OpenACC 3.2 2.11, private or reduction clause
on the combined construct is treated as if it appeared
on the loop construct.
2023-10-18 08:10:50 -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 (バレンタイン クレメン)
f74b85c678
[flang][openacc] Support array with dynamic extents in reduction recipe (#68829)
Add support for array with dynamic extents in lowering of the reduction
recipe.
2023-10-16 12:50:39 -07:00
Valentin Clement (バレンタイン クレメン)
468d3b1b78
[flang][openacc][NFC] Simplify lowering of recipe (#68836)
Refactor some of the lowering in the reduction and firstprivate recipe
to avoid duplicated code.
2023-10-16 09:35:50 -07:00
Valentin Clement
acbb260a48
[flang][openacc][NFC] Fix TODO messages 2023-10-10 10:10:15 -07:00
Valentin Clement (バレンタイン クレメン)
e2f493bed3
[flang][openacc] Support assumed shape array in firstprivate recipe (#68640)
Add support for assumed shape arrays in lowering of the copy region of
the firstprivate recipe. Information is passed in block arguments as it
is done for the reduction recipe.
2023-10-10 09:55:55 -07:00