231 Commits

Author SHA1 Message Date
Michael Kruse
27539c3f90 Revert "[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)"
The production buildbot master apparently has not yet been restarted
since https://github.com/llvm/llvm-zorg/pull/393 landed.

This reverts commit 96d1baedefc3581b53bc4389bb171760bec6f191.
2025-03-26 19:02:13 +01:00
Michael Kruse
96d1baedef
[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)
Remove the FLANG_INCLUDE_RUNTIME option which was replaced by
LLVM_ENABLE_RUNTIMES=flang-rt.

The FLANG_INCLUDE_RUNTIME option was added in #122336 which disables the
non-runtimes build instructions for the Flang runtime so they do not
conflict with the LLVM_ENABLE_RUNTIMES=flang-rt option added in #110217.
In order to not maintain multiple build instructions for the same thing,
this PR completely removes the old build instructions (effectively
forcing FLANG_INCLUDE_RUNTIME=OFF).

As per discussion in
https://discourse.llvm.org/t/buildbot-changes-with-llvm-enable-runtimes-flang-rt/83571/2
we now implicitly add LLVM_ENABLE_RUNTIMES=flang-rt whenever Flang is
compiled in a bootstrapping (non-standalone) build. Because it is
possible to build Flang-RT separately, this behavior can be disabled
using `-DFLANG_ENABLE_FLANG_RT=OFF`. Also see the discussion an
implicitly adding runtimes/projects in #123964.
2025-03-26 18:50:41 +01:00
Michael Kruse
54f37133b7
[Flang][NFC] Move runtime library files to flang-rt (#110298)
Mostly mechanical changes in preparation of extracting the Flang-RT
"subproject" in #110217. This PR intends to only move pre-existing files
to the new folder structure, with no behavioral change. Common files
(headers, testing, cmake) shared by Flang-RT and Flang remain in
`flang/`.

Some cosmetic changes and files paths were necessary:
* Relative paths to the new path for the source files and
`add_subdirectory`.
 * Add the new location's include directory to `include_directories`
* The unittest/Evaluate directory has unitests for flang-rt and Flang. A
new `CMakeLists.txt` was introduced for the flang-rt tests.
 * Change the `#include` paths relative to the include directive
 * clang-format on the `#include` directives
* Since the paths are part if the copyright header and include guards, a
script was used to canonicalize those
* `test/Runtime` and runtime tests in `test/Driver` are moved, but the
lit.cfg.py mechanism to execute the will only be added in #110217.
2025-02-16 13:25:31 +01:00
Slava Zakharin
660cdace55
[flang] Fixed write past allocated descriptor in PointerAssociateRemapping. (#127000)
The pointer descriptor might be smaller than the target descriptor,
so `operator=` would write beyound the pointer descriptor.
2025-02-13 09:39:36 -08:00
Michael Kruse
5c8c2b3db5
[Flang] Rename libFortranRuntime.a to libflang_rt.runtime.a (#122341)
Following the conclusion of the
[RFC](https://discourse.llvm.org/t/rfc-names-for-flang-rt-libraries/84321),
rename Flang's runtime libraries as follows:

 * libFortranRuntime.(a|so) to libflang_rt.runtime.(a|so)
 * libFortranFloat128Math.a to libflang_rt.quadmath.a
* libCufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so) to
libflang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so)

This follows the same naming scheme as Compiler-RT libraries
(`libclang_rt.${component}.(a|so)`). It provides some consistency
between Flang's runtime libraries for current and potential future
library components.
2025-02-08 18:02:54 +01:00
Michael Kruse
b815a3942a
[Flang] Move non-common headers to FortranSupport (#124416)
Move non-common files from FortranCommon to FortranSupport (analogous to
LLVMSupport) such that

* declarations and definitions that are only used by the Flang compiler,
but not by the runtime, are moved to FortranSupport

* declarations and definitions that are used by both ("common"), the
compiler and the runtime, remain in FortranCommon

* generic STL-like/ADT/utility classes and algorithms remain in
FortranCommon

This allows a for cleaner separation between compiler and runtime
components, which are compiled differently. For instance, runtime
sources must not use STL's `<optional>` which causes problems with CUDA
support. Instead, the surrogate header `flang/Common/optional.h` must be
used. This PR fixes this for `fast-int-sel.h`.

Declarations in include/Runtime are also used by both, but are
header-only. `ISO_Fortran_binding_wrapper.h`, a header used by compiler
and runtime, is also moved into FortranCommon.
2025-02-06 15:29:10 +01:00
macurtis-amd
c25bd6e351
[flang][runtime] Teach ApplyType to handle TypeCategory::Unsigned (#123058) 2025-01-16 05:08:49 -06:00
Peter Klausler
eb77f442b3
[flang] Accept L0 (#121998)
Accept a zero field width for formatted logical output (L0),
interpreting it as if it had been L1.
2025-01-08 13:15:51 -08:00
Matthias Springer
c870632ef6
[flang] Fix some memory leaks (#121050)
This commit fixes some but not all memory leaks in Flang. There are
still 91 tests that fail with ASAN.

- Use `mlir::OwningOpRef` instead of `std::unique_ptr`. The latter does
not free allocations of nested blocks.
- Pass `ModuleOp` as value instead of reference.
- Add few missing deallocations in test cases and other places.
2024-12-25 09:42:03 +01:00
Valentin Clement (バレンタイン クレメン)
4cb2a519db
Revert "Reland '[flang] Allow to pass an async id to allocate the descriptor (#118713)' and #118733" (#121029)
This still cause issue for device runtime build.
2024-12-23 21:27:34 -08:00
Valentin Clement (バレンタイン クレメン)
5b74fb75d9
Reland '[flang] Allow to pass an async id to allocate the descriptor (#118713)' and #118733 (#120997)
Device runtime build have been fixed. Attempt to re-land these patches
that have been approved before.

https://github.com/llvm/llvm-project/pull/118713
https://github.com/llvm/llvm-project/pull/118733
2024-12-23 12:13:56 -08:00
Valentin Clement (バレンタイン クレメン)
415cfaf339
[flang][cuda][NFC] Fix type in CUFFreeDescriptor (#120799) 2024-12-20 14:43:12 -08:00
Valentin Clement (バレンタイン クレメン)
e650ac1654
[flang][cuda][NFC] Fix typo in CUFAllocDescriptor (#120797)
Missing `r` in the function name.
2024-12-20 13:57:47 -08:00
Tom Eccles
32403f79f4
[flang][unittests] fix test broken when run as root (#119604)
It is convenient to run tests as root inside of a docker container.

The test (and the library function it is testing) are already
unsupported on Windows so it is safe to use UNIX-isms here.
2024-12-12 09:41:44 +00:00
Valentin Clement (バレンタイン クレメン)
16c2a1016e
Revert "[flang] Allow to pass an async id to allocate the descriptor (#118713)" (#119109)
This reverts commit 7d1c661381d36018fd105f4ad4c2d6dc45e7288b.

This commit breaks some device runtime builds. Need time to investigate.
2024-12-07 19:55:12 -08:00
Michael Kruse
c91ba04328
[Flang][NFC] Split runtime headers in preparation for cross-compilation. (#112188)
Split some headers into headers for public and private declarations in
preparation for #110217. Moving the runtime-private headers in
runtime-private include directory will occur in #110298.

* Do not use `sizeof(Descriptor)` in the compiler. The size of the
descriptor is target-dependent while `sizeof(Descriptor)` is the size of
the Descriptor for the host platform which might be too small when
cross-compiling to a different platform. Another problem is that the
emitted assembly ((cross-)compiling to the same target) is not identical
between Flang's running on different systems. Moving the declaration of
`class Descriptor` out of the included header will also reduce the
amount of #included sources.

* Do not use `sizeof(ArrayConstructorVector)` and
`alignof(ArrayConstructorVector)` in the compiler. Same reason as with
`Descriptor`.

* Compute the descriptor's extra flags without instantiating a
Descriptor. `Fortran::runtime::Descriptor` is defined in the runtime
source, but not the compiler source.

* Move `InquiryKeywordHashDecode` into runtime-private header. The
function is defined in the runtime sources and trying to call it in the
compiler would lead to a link-error.

* Move allocator-kind magic numbers into common header. They are the
only declarations out of `allocator-registry.h` in the compiler as well.
 
This does not make Flang cross-compile ready yet, the main goal is to
avoid transitive header dependencies from Flang to clang-rt. There are
more assumptions that host platform is the same as the target platform.
2024-12-06 15:29:00 +01:00
Valentin Clement (バレンタイン クレメン)
83ccaad473
[flang][cuda] Use async id for device stream allocation (#118733)
When stream is specified use cudaMallocAsync with the specified stream
2024-12-05 08:57:10 -08:00
Michael Kruse
0cda970ecc
[Flang][NFC] Split common headers to reduce dependencies. (#110244)
Fortran.h and target.h are defining symbols where some are used by both, the Fortran runtime (Flang-RT) and Fortran compiler (Flang), and others are used by Flang only. With the upcoming refactoring of the Fortran runtime into its own subproject (#110217), move the declarations that are used by both into new headers to minimize the amount of code that will need to be shared by Flang-RT and Flang.

Details:

 * `Fortran.h`: Flang-RT  only uses some enum definitions out of this file, but not `AsFortran` which is defined in `Fortran.cpp`. Moving the enums into `Fortran-consts.h` allows keeping `Fortran.cpp` within Flang.

 * `target.h`: Contains some floating-point definitions that is used by the non-GTest unittests in `fp-testing.h`. Flang-RT also uses some non-GTest as well. Moving those definitions avoids the dependence on the entire FortranEvaluate library.
2024-12-05 11:29:32 +01:00
Valentin Clement (バレンタイン クレメン)
7d1c661381
[flang] Allow to pass an async id to allocate the descriptor (#118713)
This is a patch in preparation for the support stream ordered memory
allocator in CUDA Fortran.

This patch adds an asynchronous id to the AllocatableAllocate runtime
function and to Descriptor::Allocate so it can be passed down to the
registered allocator. It is up to the allocator to use this value or
not.

A follow up patch will implement that asynchronous allocator for CUDA
Fortran.
2024-12-04 18:24:40 -08:00
Kelvin Li
af35e21cfe
[flang] Update CommandTest for AIX (NFC) (#118403)
With the change in commit e335563, the behavior for `ECLGeneralErrorCommandErrorSync` 
on AIX is the same as on Linux.
2024-12-03 10:27:14 -05:00
David Truby
e335563806
[NFC][flang] Fix execute_command_line test for odd environments (#117714)
One of the execute_command_line tests currently runs `cat` on an invalid
file and checks its return value, but since we don't control `cat` or
the user's path, the return value might not be reliably stable on a
per-platform basis. For example, if `git` is installed on Windows in
certain configurations it adds a directory to the path containing a
`cat` with a different set of error codes to the default Windows one.

This patch changes the test to use the `not` binary built by LLVM for
testing purposes, which should always return 1 on any platform
regardless of the user's environment.
2024-11-27 00:43:56 +00:00
Valentin Clement
308c00749d [flang][cuda][NFC] Fix format 2024-11-01 12:42:06 -07:00
Valentin Clement (バレンタイン クレメン)
32473864cb
[flang][cuda] Data transfer with descriptor (#114598)
Reopen PR #114302 as it was automatically closed. 

Review in #114302
2024-11-01 12:35:48 -07:00
Valentin Clement (バレンタイン クレメン)
fa627d98e8
[flang][cuda] Add entry point for alloc/free and simple copy (#109867)
These will be used to translate simple cuf.alloc/cuf.free and
cuf.data_transfer on scalar and constant size arrays.
2024-09-24 20:00:11 -07:00
Slava Zakharin
fc51c7f0cc
[flang][runtime] Disable LDBL_MANT_DIG == 113 for the offload builds. (#109339)
When compiling on aarch64 some `LDBL_MANT_DIG == 113` entries
end up trying to use `complex<long double>` for which there are
no certain specializations in `libcudacxx`. This change-set
includes a clean-up for `LDBL_MANT_DIG == 113` usage, which is replaced
with `HAS_LDBL128` that is set in `float128.h`.
2024-09-19 15:45:45 -07:00
Valentin Clement (バレンタイン クレメン)
cdf447baa5
[flang][cuda] Add function to allocate and deallocate device module variable (#109213)
This patch adds new runtime entry points that perform the simple
allocation/deallocation of module allocatable variable with cuda
attributes.
When the allocation is initiated on the host, the descriptor on the
device is synchronized. Both descriptors point to the same data on the
device.

This is the first PR of a stack.
2024-09-18 20:22:06 -07:00
Slava Zakharin
104f3c1806
Reland "[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build. (#109078)" (#109207)
`std::complex` operators do not work for the CUDA device compilation
of F18 runtime. This change makes use of `cuda::std::complex` from
`libcudacxx`.
`cuda::std::complex` does not have specializations for `long double`,
so the change is accompanied with a clean-up for `long double` usage.

Additional change on top of #109078 is to use `cuda::std::complex`
only for the device compilation, otherwise the host compilation
fails because `libcudacxx` may not support `long double` specialization
at all (depending on the compiler).
2024-09-18 17:41:33 -07:00
Slava Zakharin
36192fdfb9
Revert "[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build." (#109173)
Reverts llvm/llvm-project#109078
2024-09-18 11:22:31 -07:00
Slava Zakharin
be187a6812
[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build. (#109078)
`std::complex` operators do not work for the CUDA device compilation
of F18 runtime. This change makes use of `cuda::std::complex` from
`libcudacxx`.
`cuda::std::complex` does not have specializations for `long double`,
so the change is accompanied with a clean-up for `long double` usage.
2024-09-18 10:59:05 -07:00
Peter Klausler
7aad87312a
[flang][runtime] Accept some real input for integer NAMELIST (#108268)
A few other Fortran compilers silently accept real values for integer
variables in NAMELIST input. Handling an exponent would be difficult,
but it's easy to skip and ignore a fractional part when one is present.
2024-09-12 09:14:20 -07:00
Peter Klausler
500f6cc25c
[flang][runtime] Support SPACING for REAL(2 & 3) (#106575)
Add runtime APIs for the intrinsic function SPACING for REAL kinds 2 & 3
in two ways: Spacing2 (& 3) for build environments with std::float16_t,
and Spacing2By4 (& 3By4) variants (for any build environment) which
compute SPACING for those types but accept and return their values as
32-bit floats.

SPACING for REAL(2) is needed by HDF5.
2024-09-04 10:53:22 -07:00
Peter Klausler
9e53e77265
[flang] Fix warnings from more recent GCCs (#106567)
While experimenting with some more recent C++ features, I ran into
trouble with warnings from GCC 12.3.0 and 14.2.0. These warnings looked
legitimate, so I've tweaked the code to avoid them.
2024-09-04 10:52:51 -07:00
Kelvin Li
ba5e8fcece
[flang] Adjust execute_command_line intrinsic return values for AIX (NFC) (#106472) 2024-08-29 15:21:06 -04:00
Kelvin Li
66ab4b80a4
[flang] Re-enable date_and_time intrinsic test (NFC) (#104967) 2024-08-20 15:47:15 -04:00
Valentin Clement (バレンタイン クレメン)
5c3a3dc9eb
[flang][cuda] Add version in libCufRuntime name (#104506) 2024-08-15 20:45:33 -07:00
Valentin Clement
743e99dcf5
Reland "[flang][cuda] Use cuda runtime API #103488"
CUDA Fortran is meant to be an equivalent to the runtime API. Therefore, it
makes more sense to use the cuda rt API in the allocators for CUF.
2024-08-14 14:56:00 -07:00
Valentin Clement (バレンタイン クレメン)
f6e3dbc27d
Revert "[flang][cuda] Use cuda runtime API" (#104232)
Reverts llvm/llvm-project#103488
2024-08-14 13:44:49 -07:00
Valentin Clement (バレンタイン クレメン)
00ab8a6a4c
[flang][cuda] Use cuda runtime API (#103488)
CUDA Fortran is meant to be an equivalent to the runtime API. Therefore,
it makes more sense to use the cuda rt API in the allocators for CUF.

@bdudleback
2024-08-14 12:34:45 -07:00
Valentin Clement (バレンタイン クレメン)
4c1dbbe7aa
[flang][cuda] Make CUFRegisterAllocator callable from C/Fortran (#102543) 2024-08-08 17:09:53 -07:00
Valentin Clement (バレンタイン クレメン)
10d7805c4f
[flang][cuda][NFC] Disambiguate namespace with cuf dialect (#102194)
Rename namespace `Fortran::runtime::cuf` to `Fortran::runtime::cuda` to
avoid embiguity with the namespace `::cuf` that is defined in the CUF
dialect.
2024-08-06 14:04:45 -07:00
Valentin Clement (バレンタイン クレメン)
a3ccaed3b9
[flang][cuda] Allocate local descriptor in managed memory (#102060)
This patch adds entry point in the runtime to be able to allocate
descriptors in managed memory. These entry points currently only call
`CUFAllocManaged` and `CUFFreeManaged` but could be more complicated in
the future.

`cuf.alloc` and `cuf.free` related to local descriptors are converted
into runtime calls.
2024-08-06 11:17:11 -07:00
Valentin Clement (バレンタイン クレメン)
bbdb1e400f
[flang][cuda] Set the allocator on fir.embox operation (#101722)
This patch set the `allocator_idx` attribute for allocatable descriptor
that have specific CUDA attribute.
2024-08-02 14:00:26 -07:00
Peter Klausler
b1a1d4e08e
[flang][runtime] Don't emit excess digits for ES0.0E0 or EN0.0E0 (#101238)
Don't emit any digits after the decimal point.
2024-08-02 12:04:12 -07:00
Valentin Clement (バレンタイン クレメン)
1417633943
[flang][cuda] Add CUF allocator (#101216)
Add allocators for CUDA fortran allocation on the device. 3 allocators
are added for pinned, device and managed/unified memory allocation.
`CUFRegisterAllocator()` is called to register the allocators in the
allocator registry added in #100690.


Since this require CUDA, a cmake option `FLANG_CUF_RUNTIME` is added to
conditionally build these.
2024-08-02 10:02:34 -07:00
Slava Zakharin
8ce1aed55f
[flang] Lower MATMUL to type specific runtime calls. (#97547)
Lower MATMUL to the new runtime entries added in #97406.
2024-07-03 21:18:56 -07:00
Slava Zakharin
dd22085308
[flang][runtime] Split MATMUL[_TRANSPOSE] into separate entries. (#97406)
Device compilation is much faster for separate MATMUL[_TRANPOSE]
entries than for a single one that covers all data types.
The lowering changes and the removal of the generic entries will follow.
2024-07-02 21:30:37 -07:00
Yi Wu
dfd2711f8f
Revert "Revert "[flang] Fix execute_command_line cmdstat is not set when error occurs" (#96365)" (#96774)
The fix broke llvm-test-suite, so it was reverted previously. With test
fixes added in https://github.com/llvm/llvm-test-suite/pull/137, it
should now pass the tests

This reverts commit 435635652fd226fa292abcff6a10d3df9dbd74e3.
2024-06-27 10:53:56 +01:00
Kiran Chandramohan
435635652f
Revert "[flang] Fix execute_command_line cmdstat is not set when error occurs" (#96365)
Reverts llvm/llvm-project#93023

Reverting due to buildbot failure.
https://lab.llvm.org/buildbot/#/builders/41/builds/227
test-suite ::
Fortran/gfortran/regression/gfortran-regression-execute-regression__execute_command_line_3_f90
2024-06-21 23:47:13 +01:00
Yi Wu
4232dd586b
[flang] Fix execute_command_line cmdstat is not set when error occurs (#93023)
Fixes: https://github.com/llvm/llvm-project/issues/92929
Also added cmdstat for common linux return code 1, 126, 127
2024-06-21 14:42:07 +01:00
Peter Klausler
f8fc883da9
[flang][runtime] Distinguish VALUE from non-VALUE operations in REDUCE (#95297)
Accommodate operations with VALUE dummy arguments in the runtime support
for the REDUCE intrinsic function by splitting most entry points into
Reduce...Ref and Reduce...Value variants.

Further work will be needed in lowering to call the ...Value entry
points.
2024-06-13 11:10:32 -07:00