166 Commits

Author SHA1 Message Date
Valentin Clement (バレンタイン クレメン)
3f4e4e0a12
[flang][cuda] Add on_device interface to cudadevice (#134747) 2025-04-07 18:21:07 -07:00
Valentin Clement (バレンタイン クレメン)
db21ae7803
[flang][cuda] Support any_sync and ballot_sync (#134135) 2025-04-02 14:26:09 -07:00
Valentin Clement (バレンタイン クレメン)
ae8dd63681
[flang][cuda] Add interface and lowering for all_sync (#134001) 2025-04-01 17:59:11 -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
Valentin Clement (バレンタイン クレメン)
5668c7bb90
[flang][cuda] Add more interfaces for __ldca, __ldcs, __ldlu and __ldcv (#130218) 2025-03-07 10:19:20 -08:00
Valentin Clement (バレンタイン クレメン)
eb84c1181e
[flang][cuda] Add more math intrinsic interfaces in cudadevice (#128931) 2025-02-26 13:32:54 -08:00
Valentin Clement (バレンタイン クレメン)
65cf534139
[flang][cuda] Add interfaces for __ldcg, __ldca, __ldcs, __ldlu, __ldcv, __stwb, __stcg, __stcs, __stwt (#128766) 2025-02-25 14:31:41 -08:00
Valentin Clement (バレンタイン クレメン)
6038fd44d4
[flang][cuda] Lower atomiccas, atomicxor and atomicexch (#128242)
Lower atomiccas, atomicxor and atomicexch to corresponding llvm atomic
operations.
2025-02-21 15:12:52 -08:00
Valentin Clement (バレンタイン クレメン)
84c8848f81
[flang][cuda] Lower match_any_sync functions to nvvm intrinsics (#127942) 2025-02-20 13:45:15 -08:00
Valentin Clement (バレンタイン クレメン)
726c4b9f77
[flang][cuda] Lower match_all_sync functions to nvvm intrinsics (#127940) 2025-02-20 09:10:25 -08:00
Valentin Clement (バレンタイン クレメン)
004afcbfb4
[flang][cuda] Set cudadevice interfaces as public by default (#127229)
Remove the PRIVATE statement from cudadevice as it hides any interfaces
from the used __cuda_device module.
2025-02-14 10:16:16 -08:00
Valentin Clement (バレンタイン クレメン)
910be4ff90
[flang][cuda] Lower clock64 to nvvm intrinsic (#127155) 2025-02-13 18:59:24 -08:00
Valentin Clement (バレンタイン クレメン)
070c888292
[flang][cuda] Lower syncwarp to NVVM intrinsic (#126164) 2025-02-06 19:43:21 -08:00
Valentin Clement (バレンタイン クレメン)
98752ef893
[flang][cuda] Add interface for sinpi, cospi and sincospi (#126123)
Add interface for `sinpi`, `cospi` and `sincospi` and also expose
`sincosf`
2025-02-06 13:12:41 -08:00
Valentin Clement (バレンタイン クレメン)
69ccb1357f
[flang][cuda] Make argument passed by value for sync functions (#125909)
`syncthreads_and`, `syncthreads_count`, `syncthreads_or`, `synwrap` must
take their argument by value. This patch updates the interfaces and
makes sure these functions can be called inside a cuff kernel as well.
2025-02-05 13:47:53 -08:00
Renaud Kauffmann
9ad153a696
[flang][cuda] Adding more bindings to libcudadevice (#125276) 2025-01-31 14:41:34 -08:00
Renaud Kauffmann
56a0a7f6d1
[flang][cuda] Adding support for more atomic calls (#124671)
The PR follows the earlier
https://github.com/llvm/llvm-project/pull/123840 PR for atomic operation
support in CUF
2025-01-28 08:36:43 -08:00
Renaud Kauffmann
652ff20140
[flang][cuda] Adding atomicadd as a cudadevice intrinsic and converting it LLVM dialect (#123840)
With these changes, CUF atomic operations are handled as cudadevice
intrinsics and are converted straight to the LLVM dialect with the
`llvm.atomicrw` operation.

I am only submitting changes for `atomicadd` to gather feedback. If we
are to proceed with these changes I will add support for all other
applicable atomic operations following this pattern.
2025-01-22 19:06:28 -08:00
Renaud Kauffmann
acba822a45
[CUF] Moving __fadd_rd and __fadd_ru to cudadevice.f90 as they are symbol already known upstream. (#123127)
They are defined under `__clang_cuda_device_functions.h`

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2025-01-16 11:53:18 -08:00
Renaud Kauffmann
2bb5ca537b
Preparing cudadevice.mod to be the same upstream and downstream. (#123099) 2025-01-15 14:04:15 -08:00
vdonaldson
ff862d6de9
[flang] Modifications to ieee floating point environment procedures (#121949)
Intrinsic module procedures ieee_get_modes, ieee_set_modes,
ieee_get_status, and ieee_set_status store and retrieve opaque data
values whose size varies by machine and OS environment. These data
values are usually, but not always small. Their sizes are not directly
known in a cross compilation environment. Address this issue by
implementing two mechanisms for processing these data values.
Environments that use typical small data sizes can access storage
defined at compile time. When this is not valid, data storage of any
size can be allocated at runtime.
2025-01-15 10:55:09 -05:00
Valentin Clement (バレンタイン クレメン)
c701c18bed
[flang][cuda] Move interface to __cuda_device (#122771) 2025-01-13 17:28:34 -08:00
Valentin Clement (バレンタイン クレメン)
df808df8f7
[flang][cuda] Add bind(c) interfaces for __fadd_rd and __fadd_ru (#122535)
Function like `__fadd_rd ` and `__fadd_ru ` need to be converted to the
cuda equivalent.
2025-01-10 19:15:02 -08:00
Peter Klausler
b53bdc6101
[flang] Add default component initialization to some built-in types (#121416)
The standard requires EVENT_TYPE, LOCK_TYPE, NOTIFY_TYPE, and TEAM_TYPE
to have full default initialization for their nonallocatable private
components.
2025-01-08 13:14:28 -08:00
Valentin Clement (バレンタイン クレメン)
878a57468b
[flang][cuda] Add c_devloc as intrinsic and inline it during lowering (#120648)
Add `c_devloc` as intrinsic and inline it during lowering. `c_devloc` is
used in CUDA Fortran to get the address of device variables.

For the moment, we borrow almost all semantic checks from `c_loc` except
for the pointer or target restriction. The specifications of `c_devloc`
are are pretty vague and we will relax/enforce the restrictions based on
library and apps usage comparing them to the reference compiler.
2025-01-08 11:23:05 -08:00
Renaud Kauffmann
cb0effc0e6
[flang][cuda] Using nvvm intrinsics for the syncthread and threadfence families of calls (#120020) 2024-12-18 11:44:30 -08:00
Peter Klausler
fc97d2e68b
[flang] Add UNSIGNED (#113504)
Implement the UNSIGNED extension type and operations under control of a
language feature flag (-funsigned).

This is nearly identical to the UNSIGNED feature that has been available
in Sun Fortran for years, and now implemented in GNU Fortran for
gfortran 15, and proposed for ISO standardization in J3/24-116.txt.

See the new documentation for details; but in short, this is C's
unsigned type, with guaranteed modular arithmetic for +, -, and *, and
the related transformational intrinsic functions SUM & al.
2024-12-18 07:02:37 -08:00
vdonaldson
92604cf378
[flang] IEEE_REM (#115936)
Implement the IEEE 60559:2020 remainder function.
2024-11-13 13:02:20 -05:00
Peter Klausler
751389218e
[flang] Make IEEE_INT and IEEE_REAL into builtin intrinsic functions (#109191)
For proper error detection of bad KIND= arguments, make IEEE_INT and
IEEE_REAL actual intrinsic functions. Lowering will have to check for
the new __builtin_ names.
2024-09-20 13:52:02 -07:00
Peter Klausler
fc1c481cf4
[flang][preprocessor] Change handling of macros in text from Fortran … (#108113)
…INCLUDE lines

The compiler current treats an INCLUDE line as essentially a synonym for
a preprocessing #include directive. The causes macros that have been
defined at the point where the INCLUDE line is processed to be replaced
within the text of the included file.

This behavior is surprising to users who expect an INCLUDE line to be
expanded into its contents *after* preprocessing has been applied to the
original source file, with no further macro expansion.

Change INCLUDE line processing to use a fresh instance of Preprocessor
containing no macro definitions except _CUDA in CUDA Fortran
compilations and, if the original file was being preprocessed, the
standard definitions of __FILE__, __LINE__, and so forth.
2024-09-12 09:08:00 -07:00
Philip Reames
050f785e2c Revert "[flang][runtime] Fix odd "invalid descriptor" runtime crash (#107785)"
This reverts commit 15106c26662a573df31e8dfdd9350c313b8bfd84.  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
Valentin Clement (バレンタイン クレメン)
92e75c095b
Reland [flang][cuda] Add c_devptr and bypass output semantic check (#107353)
Add a builtin type for c_devptr since it will need some special handling
for some function like c_f_pointer.
`c_ptr` is defined as a builtin type and was raising a semantic error if
you try to use it in a I/O statement. This patch add a check for c_ptr
and c_devptr to bypass the semantic check and allow the variables of
these types to be used in I/O.

This version of the patch keeps the semantic error when -pedantic is
enabled to align with gfortran.
2024-09-05 11:44:12 -07:00
Tom Eccles
3b19e480c0
[flang] Warn when F128 is unsupported (#102147) (#106957)
This generates `warning: REAL(KIND=16) is not an enabled type for this
target` if that type is used in a build not correctly configured to
support this type. Uses of `selected_real_kind(30)` return -1.

Relanding #102147 because the test errors turned out to be specific to a
downstream configuration.
2024-09-05 15:59:36 +01:00
Valentin Clement (バレンタイン クレメン)
abbcfff706
Revert "[flang][cuda] Add c_devptr and bypass output semantic check" (#107349)
Reverts llvm/llvm-project#107318

It breaks a test
https://lab.llvm.org/buildbot/#/builders/143/builds/1933
2024-09-04 21:16:00 -07:00
Valentin Clement (バレンタイン クレメン)
c2fc33204c
[flang][cuda] Add c_devptr and bypass output semantic check (#107318)
Add a builtin type for c_devptr since it will need some special handling
for some function like c_f_pointer.
`c_ptr` is defined as a builtin type and was raising a semantic error if
you try to use it in a I/O statement. This patch add a check for c_ptr
and c_devptr to bypass the semantic check and allow the variables of
these types to be used in I/O.
2024-09-04 20:41:31 -07:00
Tom Eccles
8ae877a089
Revert "[flang] Warn when F128 is unsupported" (#106561)
Reverts llvm/llvm-project#102147

It seems some systems which should support F128 are wrongly detected as
not supporting.

This might be due to checking `LDBL_MANT_DIG` instead of
`__LDBL_MANT_DIG__`. I will investigate.
2024-08-29 15:37:59 +01:00
Tom Eccles
114ff99e93
[flang] Warn when F128 is unsupported (#102147)
This generates `warning: REAL(KIND=16) is not an enabled type for this
target` if that type is used in a build not correctly configured to
support this type. Uses of `selected_real_kind(30)` return -1.
2024-08-28 16:33:39 +01:00
Peter Klausler
7c512cef61
[flang] Disallow references to some IEEE procedures in DO CONCURRENT (#102082)
There's a numbered constraint that prohibits calls to some IEEE
arithmetic and exception procedures within the body of a DO CONCURRENT
construct. Clean up the implementation to catch missing cases.
2024-08-08 11:07:19 -07:00
Michael Klemm
2f8b64d327
[flang][runtime] Build ISO_FORTRAN_ENV to export kind arrays as linkable symbols (#95388)
Moves definitions of the kind arrays into a Fortran MODULE to not only
emit the MOD file, but also compile that MODULE file into an object
file. This file is then linked into libFortranRuntime.so.

Eventually this workaround PR shoud be redone and a proper runtime build
should be setup that will then also compile Fortran MODULE files.

Fixes #89403

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
Co-authored-by: Michael Kruse <github@meinersbur.de>
2024-07-19 19:37:24 +02:00
Peter Klausler
3602efa78d
[flang] Silence errors on C_LOC/C_FUNLOC in specification expressions (#96108)
Transformational functions from the intrinsic module ISO_C_BINDING are
allowed in specification expressions, so tweak some general checks that
would otherwise trigger error messages about inadmissible targets, dummy
procedures in specification expressions, and pure procedures with impure
dummy procedures.
2024-06-24 09:06:32 -07:00
Peter Klausler
4b57fe65fd
[flang] Fold IEEE_SUPPORT_xxx() intrinsic functions (#95866)
All of the IEEE_SUPPORT_xxx() intrinsic functions must fold to constant
logical values when they have constant arguments; and since they fold to
.TRUE. for currently support architectures, always fold them. But also
put in the infrastructure whereby a driver can initialize Evaluate's
target information to set some of them to .FALSE. if that becomes
necessary.
2024-06-18 12:46:15 -07:00
Valentin Clement (バレンタイン クレメン)
00bd2fa198
[flang][cuda] Add bind c to cudadevice procedures (#92822)
This patch adds bind c names to functions and subroutines in cudadevice
so they can be lowered and not hit the intrinsic procedure TODOs.
2024-05-28 14:57:13 -07:00
Valentin Clement (バレンタイン クレメン)
6d50a79b72
[flang][cuda] Implicitly load cudadevice module in device/global subprogram (#92038)
This is a re-worked version of #91668. It adds the `cudadevice` module
and set the `device` attributes on its functions/subroutines so there is
no need for special case in semantic check.
`cudadevice` module is implicitly USE'd in `global`/`device` subprogram.
2024-05-17 13:58:49 -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
fde5e471df
[flang] C_LOC is PURE (#89437)
The standard defines C_LOC as being PURE (actually SIMPLE now in
F'2023); characterize it appropriately.

Fixes https://github.com/llvm/llvm-project/issues/88747.
2024-04-22 15:33:17 -07:00
Daniel Chen
8136ac1c42
[Flang] Define c_int_fast16_t and c_int_fast32_t for PowerPC. (#88292)
On Linux, PowerPC defines `int_fast16_t` and `int_fast32_t` as `long`.
Need to update the corresponding type, `c_int_fast16_t` and
`c_int_fast32_t` in `iso_c_binding` module so they are interoparable.
2024-04-10 19:22:38 -04:00
Peter Klausler
e1ad2735c3
[flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)
Address TODOs in the intrinsic module ISO_FORTRAN_ENV, and extend the
implementation of NUMERIC_STORAGE_SIZE so that the calculation of its
value is deferred until it is needed so that the effects of
-fdefault-integer-8 or -fdefault-real-8 are reflected. Emit a warning
when NUMERIC_STORAGE_SIZE is used from the module file and the default
integer and real sizes do not match.

Fixes https://github.com/llvm/llvm-project/issues/87476.
2024-04-08 11:57:01 -07:00
Michael Klemm
fb5fd2d82f
[flang][OpenMP] Compile proper omp_lib.mod from the openmp/src/include sources (#80874)
This PR changes the build system to use use the sources for the module
`omp_lib` and the `omp_lib.h` include file from the `openmp` runtime
project and not from a separate copy of these files. This will greatly
reduce potential for inconsistencies when adding features to the OpenMP
runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the
corresponding LIT tests with a "REQUIRES" directive at the beginning of
the OpenMP test files.

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2024-03-20 13:47:26 +01:00