31 Commits

Author SHA1 Message Date
Peter Klausler
b01ab5318e
[flang][CUDA] Apply intrinsic operator overrides (#151018)
Fortran's intrinsic numeric and relational operators can be overridden
with explicit interfaces so long as one or more of the dummy arguments
have the DEVICE attribute. Semantics already allows this without
complaint, but fails to replace the operations with the defined specific
procedure calls when analyzing expressions.
2025-07-30 11:41:40 -07:00
Valentin Clement (バレンタイン クレメン)
46caad52ac
[flang][cuda] Do not produce data transfer in offloaded do concurrent (#147435)
If a `do concurrent` loop is offloaded then there should be no CUDA data
transfer in it. Update the semantic and lowering to take that into
account.

`AssignmentChecker` has to be put into a separate pass because the
checkers in `SemanticsVisitor` cannot have the same `Enter/Leave`
functions. The `DoForallChecker` already has `Eneter/Leave` functions
for the `DoConstruct`.
2025-07-08 10:52:15 -07:00
Valentin Clement (バレンタイン クレメン)
a3201ce9e1
[flang][cuda] Add option to disable warp function in semantic (#143640)
These functions are not available in some lower compute capabilities.
Add option in the language feature to enforce the semantic check on
these.
2025-06-10 22:10:26 -07:00
Valentin Clement (バレンタイン クレメン)
ef11bdc7fe
[flang][cuda] Allow compiler directive in cuda code (#141991) 2025-05-29 10:46:44 -07:00
Valentin Clement (バレンタイン クレメン)
fed0f58547
[flang][cuda] Avoid triggering host array error in host device proc (#134909)
we cannot enforce the detection of host arrays in device code when the
procedure is host, device. Relax the check for those.
2025-04-08 12:55:12 -07:00
Valentin Clement (バレンタイン クレメン)
20feca47c1
[flang][cuda] Allow ieee_arithmetic on the device (#131930)
- Allow ieee_arithmetic on the device
- Add ignore_tkr(d) to ieee_is_finite
2025-03-19 07:20:06 -07:00
Zhen Wang
a67566b185
Allow do concurrent inside cuf kernel directive (#127693)
Allow do concurrent inside cuf kernel directive to avoid the following
Lowering error:
```
void {anonymous}::FirConverter::genFIR(const Fortran::parser::CUFKernelDoConstruct&): Assertion `bounds && "Expected bounds on the loop construct"' failed.
```

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2025-02-20 14:05:44 -08:00
Valentin Clement (バレンタイン クレメン)
3d59e30cbc
[flang][cuda] Allow DO CONCURRENT in cuf kernel (#124190) 2025-01-23 15:09:39 -08:00
Valentin Clement (バレンタイン クレメン)
4065d985ab
[flang][cuda] Allow complex type in cuf kernel reduce (#124185) 2025-01-23 15:09:24 -08:00
Valentin Clement (バレンタイン クレメン)
e3dafa88a8
[flang][cuda] Allow GOTO, EXIT, CYCLE and SELECT CASE in device procedures (#121612) 2025-01-03 17:35:41 -08:00
Valentin Clement (バレンタイン クレメン)
7009b06993
[flang][cuda] Allow STOP in device context (#120625)
STOP statement is allowed in device procedure
2024-12-19 12:41:09 -08:00
Valentin Clement (バレンタイン クレメン)
81333cfc52
[flang][cuda] Relax host array check for cuda constant (#120333)
Array with CONSTANT attribute declared in module spec part are device
arrays and should not trigger the host array check.
2024-12-17 17:04:32 -08:00
Valentin Clement (バレンタイン クレメン)
15c61a208f
[flang][cuda] Do not consider SHARED array as host array (#120306)
Update the current `FindHostArray` to not return shared array as host
array.
2024-12-17 13:42:14 -08:00
Valentin Clement (バレンタイン クレメン)
97b7bace67
[flang][cuda] Allow host array with PARAMETER attribute in device context (#120298)
Host arrays are normally not allowed in device context unless they have
a `PARAMETER` attribute. This patch update the check so no error is
emitted.
2024-12-17 13:41:24 -08:00
Valentin Clement (バレンタイン クレメン)
67ae944bfa
[flang][cuda] Check for use of host array in device context (#119756)
Now that variables have implicit attribute, we can check for illegal use
of module host variable in device context.
2024-12-16 13:34:22 -08:00
Peter Klausler
73216cd712
[flang] Rework CUDA kernel DO host array check (#116301)
Don't worry about derived type components unless they are pointers or
allocatables.
2024-11-19 16:19:32 -08:00
Peter Klausler
0f973ac783
[flang] Tag warnings with LanguageFeature or UsageWarning (#110304)
(This is a big patch, but it's nearly an NFC. No test results have
changed and all Fortran tests in the LLVM test suites work as expected.)

Allow a parser::Message for a warning to be marked with the
common::LanguageFeature or common::UsageWarning that controls it. This
will allow a later patch to add hooks whereby a driver will be able to
decorate warning messages with the names of its options that enable each
particular warning, and to add hooks whereby a driver can map those
enumerators by name to command-line options that enable/disable the
language feature and enable/disable the messages.

The default settings in the constructor for LanguageFeatureControl were
moved from its header file into its C++ source file.

Hooks for a driver to use to map the name of a feature or warning to its
enumerator were also added.

To simplify the tagging of warnings with their corresponding language
feature or usage warning, to ensure that they are properly controlled by
ShouldWarn(), and to ensure that warnings never issue at code sites in
module files, two new Warn() member function templates were added to
SemanticsContext and other contextual frameworks. Warn() can't be used
before source locations can be mapped to scopes, but the bulk of
existing code blocks testing ShouldWarn() and FindModuleFile() before
calling Say() were convertible into calls to Warn(). The ones that were
not convertible were extended with explicit calls to
Message::set_languageFeature() and set_usageWarning().
2024-10-02 08:54:49 -07:00
Valentin Clement (バレンタイン クレメン)
cfc095118c
[flang][cuda] Do not check assignment semantic in cuf kernel (#107512) 2024-09-06 09:17:31 -07:00
Valentin Clement (バレンタイン クレメン)
16975ad27c
[flang][cuda] Emit error when host array is used in CUF kernel (#100693)
Restriction from the standard 2.11.2.

Arrays used or assigned in the loop must have the device, managed or
unifed attribute.
2024-07-26 09:49:43 -07:00
Valentin Clement (バレンタイン クレメン)
8e8dccdecd
[flang][cuda] Do not consider PINNED as device attribute (#95988)
PINNED is a CUDA data attribute meant for the host variables. Do not
consider it when computing the number of device variables in assignment
for the cuda data transfer.
2024-06-19 13:35:02 -07:00
khaki3
3af717d661
[flang] Add parsing of DO CONCURRENT REDUCE clause (#92518)
Derived from #92480. This PR supports parsing of the DO CONCURRENT
REDUCE clause in Fortran 2023. Following the style of the OpenMP parser
in MLIR, the front end accepts both arbitrary operations and procedures
for the REDUCE clause. But later Semantics can notify type errors and
resolve procedure names.
2024-05-30 11:34:19 -07:00
Peter Klausler
5bbb63bd6d
[flang] Parse REDUCE clauses in !$CUF KERNEL DO (#92154)
A !$CUF KERNEL DO directive is allowed to have advisory REDUCE clauses
similar to those in OpenACC and DO CONCURRENT. Parse and represent them.
Semantic validation will follow.
2024-05-15 16:28:58 -07:00
Valentin Clement (バレンタイン クレメン)
38b2755983
Revert "[flang][cuda] Implicitly load cudadevice module in device/global subprogram" (#91827)
Reverts llvm/llvm-project#91668
2024-05-10 17:51:30 -07:00
Valentin Clement (バレンタイン クレメン)
f32f6d199a
[flang][cuda] Implicitly load cudadevice module in device/global subprogram (#91668)
Some functions and subroutines are available in device context
(device/global). These functions have interfaces declared in the
`cudadevice` module.

This patch adds interfaces as `__cuda_device_builtins_<fctname>` in a
builtin module and they are USE'd rename in the `cudadevice` module. The
module is implicitly used in device/global subprograms.

The builtin module only contains procedures from section 3.6.4 for now.
2024-05-10 13:41:53 -07:00
Peter Klausler
505f6da196
[flang] Ensure all warning/portability messages are guarded by Should… (#90518)
…Warn()

Many warning messages were being emitted unconditionally. Ensure that
all warnings are conditional on a true result from a call to
common::LanguageFeatureControl::ShouldWarn() so that it is easy for a
driver to disable them all, or, in the future, to provide per-warning
control over them.
2024-05-01 14:33:14 -07:00
Valentin Clement (バレンタイン クレメン)
a309c07ad3
[flang][cuda] Allow if stmt in device subroutine (#89347) 2024-04-19 07:30:26 -07:00
Valentin Clement (バレンタイン クレメン)
26101e8c50
[flang][cuda] Avoid crash by exiting the check if assignment is not usable (#89149)
In the presence of other semantic error, `GetAssignment` would return a
nullptr and therefore would make the rest of the check crash when trying
to collect symbols.

Exiting early when we have a nullptr so the compiler doesn't crash and
user can get the meaningful semantic error.
2024-04-17 15:42:09 -07:00
Valentin Clement (バレンタイン クレメン)
7b6b023121
[flang][cuda] Fix crash in semantic (#88577)
Fix for #88451

Do not perform semantic check about data transfer on assignment
statement in device context.
2024-04-12 14:28:05 -07:00
Valentin Clement (バレンタイン クレメン)
896b5e5571
[flang][cuda] Allow list-directed PRINT and WRITE stmt in device code (#87415)
The specification allow list-directed PRINT and WRITE statements to
appear in device code. This patch relax the semantic check to allow
them.

3.6.11.
List-directed PRINT and WRITE statements to the default unit may be used
when compiling for compute capability 2.0 and higher; all other uses of
PRINT and WRITE are disallowed.
2024-04-08 09:59:12 -07:00
Valentin Clement (バレンタイン クレメン)
0aa982fb32
[flang][cuda] Add restriction on implicit data transfer (#87720)
In section 3.4.2, some example of illegal data transfer using expression
are given. One of it is when multiple device objects are part of an
expression in the rhs. Current implementation allow a single device
object in such case. This patch adds a similar restriction.
2024-04-05 13:40:38 -07:00
Peter Klausler
f674ddc19f
[flang] CUDA Fortran - part 5/5: statement semantics
Canonicalize !$CUF KERNEL DO loop nests, similar to OpenACC/OpenMP
canonicalization.  Check statements and expressions in device contexts
for usage that isn't supported.  Add more tests, and include some
tweaks to standard modules needed to build CUDA Fortran modules.

Depends on https://reviews.llvm.org/D150159,
https://reviews.llvm.org/D150161, https://reviews.llvm.org/D150162, &
https://reviews.llvm.org/D150163.

Differential Revision: https://reviews.llvm.org/D150164
2023-06-01 13:31:35 -07:00