Commit Graph

846 Commits

Author SHA1 Message Date
Valentin Clement (バレンタイン クレメン)
0b700f2333 [flang][cuda] Add entry point to launch global function with cluster_dims (#113958) 2024-10-29 10:01:49 -07:00
Renaud Kauffmann
70d61f6de7 [flang][cuda] Adding runtime call to CUFRegisterVariable (#113952) 2024-10-28 13:34:37 -07:00
Valentin Clement (バレンタイン クレメン)
4e40b71c51 [flang][cuda] Add specialized gpu.launch_func conversion (#113493) 2024-10-23 15:28:51 -07:00
Valentin Clement (バレンタイン クレメン)
e2766b2bce [flang][cuda] Add entry point to launch cuda fortran kernel (#113490) 2024-10-23 13:44:02 -07:00
Valentin Clement (バレンタイン クレメン)
60105ac6ba [flang][cuda] Fix kernel registration (#113372)
The registration needs the fct pointer and the name. This patch updates
the entry point with an extra arg and the translation as well.
2024-10-23 11:25:58 -07:00
Valentin Clement (バレンタイン クレメン)
cc4926a069 [flang][cuda] Fix module registration (#113358) 2024-10-22 12:26:10 -07:00
Valentin Clement (バレンタイン クレメン)
d37bc32a65 [flang][cuda] Translate cuf.register_kernel and cuf.register_module (#112972)
Add LLVM IR Translation for `cuf.register_module` and
`cuf.register_kernel`. These are lowered to function call to the CUF
runtime entries.
2024-10-18 21:31:47 -07:00
David Truby
91b5bef358 [flang] Tighten requirements on some glibc float128 functions (#110651)
j0l, j1l, jnl, y0l, y1l and ynl are glibc extensions rather than
standard POSIX functions, and so are not available in every Linux libc.
This patch checks if `__GLIBC__` and `_GNU_SOURCE` are defined before
using
these functions.

This patch allows the float128 runtime to build with musl libc on Linux.
2024-10-16 14:49:30 +01:00
Peter Klausler
38b9dd7a7f [flang] Fold ERFC_SCALED (#112287)
Move the ErfcScaled template function from the runtime into a new header
file in flang/include/Common, then use it in constant folding to
implement folding for the erfc_scaled() intrinsic function.
2024-10-15 14:23:15 -07:00
Peter Klausler
c893e3d02d [flang][runtime] Fix runtime crash after bad recoverable OPEN (#111454)
When an OPEN statement with a unit number fails in a recoverable manner,
the runtime needs to delete the ExternalFileUnit instance that was
created in the unit map. And we do this too soon -- that instance still
holds some of the I/O statement state that will be used by a later call
into the runtime for EndIoStatement.

Move the code that deletes the unit after a failed but recoverable OPEN
into ExternalIoStatementBase::EndIoStatement, and don't do things
afterwards that would need the I/O statement state that has been
destroyed.

Fixes https://github.com/llvm/llvm-project/issues/111404.
2024-10-10 10:24:59 -07:00
Brad Richardson
06eb10dadf [flang][driver] rename flang-new to flang (#110023)
This does a global rename from `flang-new` to `flang`. I also
removed/changed any TODOs that I found related to making this change.

---------

Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2024-10-10 09:26:04 +01:00
David Truby
856c38d542 [flang] Implement GETUID and GETGID intrinsics (#110679)
GETUID and GETGID are non-standard intrinsics supported by a number of
other Fortran compilers. On supported platforms these intrinsics simply
call the POSIX getuid() and getgid() functions and return the result.
The only platform we support that does not have these is Windows.

Windows does not have the same concept of UIDs and GIDs, so on Windows
we issue a warning indicating this and return 1 from both functions.

Co-authored-by: Yi Wu <yi.wu2@arm.com>
2024-10-02 13:26:40 +01:00
vdonaldson
936142e0e7 [flang] IEEE_RINT, IEEE_INT (#110509)
IEEE_RINT rounds a real value to an integer-valued real.

IEEE_INT rounds a real value to an integer value.
The primary IEEE_INT result is generated with a call to IEEE_RINT.
2024-10-01 09:15:16 -04:00
David Truby
78ccffc053 [flang] Add MALLOC and FREE intrinsics for Cray pointers (#110018)
MALLOC and FREE are extensions provided by gfortran, Intel Fortran and
classic flang to allocate memory for Cray pointers. These are used in
some legacy codes such as libexodus.

All the above compilers accept using MALLOC and FREE with integers as
well, despite that this will often signify a bug in user code. We should
accept the same as the other compilers for compatibility.
2024-09-30 22:40:16 +01:00
David Truby
7a0a7947ee Revert "[flang] Implement GETUID and GETGID intrinsics" (#110531)
Reverts llvm/llvm-project#108017
2024-09-30 17:35:27 +01:00
David Truby
054eadcb11 [flang] Implement GETUID and GETGID intrinsics (#108017)
GETUID and GETGID are non-standard intrinsics supported by a number of
other Fortran compilers. On supported platforms these intrinsics simply
call the POSIX getuid() and getgid() functions and return the result.
The only platform we support that does not have these is Windows.

Windows does not have the same concept of UIDs and GIDs, so on Windows
we issue a warning indicating this and return 1 from both functions.

Co-authored-by: Yi Wu <yi.wu2@arm.com>

---------

Co-authored-by: Yi Wu <yi.wu2@arm.com>
2024-09-30 14:36:39 +01: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 (バレンタイン クレメン)
434c9c50f9 [flang][cuf][NFC] Clean up unused header and library (#109326)
These were part of a previous attempt and are not needed anymore.
2024-09-19 12:56:26 -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
Peter Klausler
5f11d38d01 [flang] Fix code that deletes unit from bad OPEN (#108994)
When an OPEN statement fails, a unit that was created for the OPEN needs
to be removed from the unit map. The code that tried to do this was
incorrect -- it needs to re-acquire the unit via LookUpForClose as a
CLOSE statement does. (The failure to do this completely was leaving a
zombie unit active that could break a later OPEN on the same unit
number.)
2024-09-18 12:19:18 -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
50d15e688f [flang] Subnormal arguments to and results from SPACING (#108861)
The standards aren't clear about how IEEE-754 subnormal values interact
with the intrinsic function SPACING. Four compilers interpret the
standard such that SPACING(x) will return a value never less than
TINY(x); one compiler returns TINY(x) for ABS(x) <= TINY(x) but can
return SPACING(x) < TINY(x) for some ABS(x) > TINY(x); one other
compiler works similarly, but also oddly returns SPACING(x) < TINY(x)
for ABS(x) >= TINY(x)/2.

Follow the most common precedent.
2024-09-16 13:46:12 -07:00
Valentin Clement (バレンタイン クレメン)
bc54e5636f [flang][cuda] Add new entry points function for data transfer (#108244)
Add new entry points for more complex data transfer involving
descriptors. These functions will be called when converting
`cuf.data_transfer` operations.
2024-09-16 09:45:44 -07:00
Slava Zakharin
b9198a1731 [flang][runtime] Fixed include directories for Float128Math files. (#108466)
When building FortranRuntime out of tree on aarch64, the list of include
directories for the files comming from FortranFloat128MathILib
has to contain flang/runtime. I did this via
INTERFACE_INCLUDE_DIRECTORIES property.
2024-09-16 08:18:33 -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
Philip Reames
050f785e2c Revert "[flang][runtime] Fix odd "invalid descriptor" runtime crash (#107785)"
This reverts commit 15106c2666.  Commit does
not pass check-flang on x86 host.
2024-09-11 07:40:22 -07:00
Peter Klausler
15106c2666 [flang][runtime] Fix odd "invalid descriptor" runtime crash (#107785)
A defined assignment generic interface for a given LHS/RHS type & rank
combination may have a specific procedure with LHS dummy argument that
is neither allocatable nor pointer, or specific procedure(s) whose LHS
dummy arguments are allocatable or pointer. It is possible to have two
specific procedures if one's LHS dummy argument is allocatable and the
other's is pointer.

However, the runtime doesn't work with LHS dummy arguments that are
allocatable, and will crash with a mysterious "invalid descriptor" error
message.

Extend the list of special bindings to include
ScalarAllocatableAssignment and ScalarPointerAssignment, use them when
appropriate in the runtime type information tables, and handle them in
Assign() in the runtime support library.
2024-09-10 14:14:08 -07:00
Peter Klausler
ea858e39bf [flang][runtime] Accept '\n' as space in internal list-directed input (#107716)
When scanning ahead for the first character in the next input item in
list-directed internal input, allow a newline character to appear and
treat it as a space, matching the behavior of nearly all other Fortran
compilers.
2024-09-10 14:13:47 -07:00
Peter Klausler
cd92c42555 [flang][runtime] Don't emit runtime error for "AA" editing (#107714)
Commas are optional between edit descriptors in a format, so treat "AA"
as if it were "A,A".
2024-09-10 14:13:28 -07:00
Peter Klausler
fe58527305 [flang] Relax ETIME(VALUES=) runtime checking (#107647)
Don't require the "VALUES=" argument to the extension intrinsic
procedure ETIME to have exactly two elements. Other compilers that
support ETIME do not, and it's easy to adapt the behavior to whatever
the dynamic size turns out to be.
2024-09-10 14:11:37 -07:00
Leandro Lupori
797f01198e [flang][OpenMP] Make lastprivate work with reallocated variables (#106559)
Fixes https://github.com/llvm/llvm-project/issues/100951
2024-09-05 14:55:01 -03: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
6facf69814 [flang][runtime] Correct RANDOM_INIT seed generation (#106250)
The initial seed was generated from a bitwise AND ("&") of two
clock-generated values, instead of an XOR or (best) a truncated integer
multiplication. Maybe I mistyped a shift-7 instead of a shift-6 or
shift-8 when I wrote that line, but it was most likely just stupidity.

Fixes https://github.com/llvm/llvm-project/issues/106221.
2024-09-04 10:52:20 -07:00
Kelvin Li
8b198ee3a0 [flang] Update the date_and_time intrinsic for AIX (#104849)
Currently, strftime is called to get the timezone for the ZONE argument.
On AIX, this routine requires an environment variable set in order to 
return the required format. This patch is to add the time difference 
computation from UTC for the platform.
2024-08-28 09:43:37 -04:00
Peter Klausler
f428f5fc68 [flang][runtime] Add alternate SELECTED_(INT|REAL)_KIND APIs (#105887)
Add extended versions of SELECTED_INT_KIND and SELECTED_REAL_KIND
runtime APIs that permit lowering to pass along a bit mask of acceptable
kinds. The existing APIs call the new ones with a full bit mask. If
lowering transitions to always use the new APIs the old ones can then be
deleted.
2024-08-26 10:54:29 -07:00
Peter Klausler
2326a02357 [flang] Support read-only access to an anonymous unit (#105859)
Don't require the "fort.123" file implicitly opened by READ(123, ... to
be writable.
2024-08-26 10:52:19 -07:00
Peter Klausler
57b89fdd8a [flang][runtime] Add FLANG_RUNTIME_NO_REAL_3 flag to build (#105856)
Allow a runtime build to disable SELECTED_REAL_KIND from returning kind
3 (16-bit truncated form of 32-bit IEEE-754 floating point, a/k/a "brain
float" or bfloat16).
2024-08-23 11:27:25 -07:00
serge-sans-paille
410f751144 [Flang][Runtime] Fix type used to store result of typeInfo::Value::Ge… (#105589)
…tValue

Current choice was only working out of accident on 64 bit machine, it
led to an implicit cast to smaller type on 32 bit machine. Use the exact
type instead.
2024-08-22 06:11:34 +00:00
Peter Klausler
c557d85204 [flang][runtime] Add build-time flags to runtime to adjust SELECTED_x_KIND() (#105575)
Add FLANG_RUNTIME_NO_INTEGER_16 and FLANG_RUNTIME_NO_REAL_{2,10,16} to
allow one to disable those kinds from being returned from
SELECTED_INT_KIND and SELECTED_REAL_KIND even if they are actually
available in the C++ build compiler.
2024-08-21 16:08:06 -07:00
serge-sans-paille
b6686e764c [Flang][Runtime] Handle missing definitions in <cfenv> (#101242)
According to the C99 standard, <fenv.h> may not define FE_INVALID and
the likes. Even if C++11 mandate them, musl and emscripten don't provide
them, so handle that case.
2024-08-21 07:42:18 +00: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 (バレンタイン クレメン)
5c016bf40e [flang][cuda] Force default allocator in device code (#102238) 2024-08-09 09:18:34 -07:00
Valentin Clement (バレンタイン クレメン)
4c1dbbe7aa [flang][cuda] Make CUFRegisterAllocator callable from C/Fortran (#102543) 2024-08-08 17:09:53 -07:00
Kelvin Li
59531cf01e [flang] Set the offset based on the significant bytes in the boz input in big endian (#102334)
The offset to the input data should be counted from most significant bit
instead of zero in the big endian environment.
2024-08-08 09:45:51 -04:00