Skip to content

Commit b4b23ff

Browse files
authored
[flang][runtime] Enable more APIs in the offload build. (#75996)
This patch enables more numeric (mod, sum, matmul, etc.) APIs, and some others. I added new macros to disable warnings about using C++ STD methods like operators of std::complex, which do not have __device__ attribute. This may probably result in unresolved references, if the header files implementation relies on libstdc++. I will need to follow up on this.
1 parent 8928622 commit b4b23ff

19 files changed

+712
-604
lines changed

flang/include/flang/ISO_Fortran_binding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ RT_API_ATTRS void *CFI_address(
189189
RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *, const CFI_index_t lower_bounds[],
190190
const CFI_index_t upper_bounds[], size_t elem_len);
191191
RT_API_ATTRS int CFI_deallocate(CFI_cdesc_t *);
192-
int CFI_establish(CFI_cdesc_t *, void *base_addr, CFI_attribute_t, CFI_type_t,
193-
size_t elem_len, CFI_rank_t, const CFI_index_t extents[]);
192+
RT_API_ATTRS int CFI_establish(CFI_cdesc_t *, void *base_addr, CFI_attribute_t,
193+
CFI_type_t, size_t elem_len, CFI_rank_t, const CFI_index_t extents[]);
194194
RT_API_ATTRS int CFI_is_contiguous(const CFI_cdesc_t *);
195195
RT_API_ATTRS int CFI_section(CFI_cdesc_t *, const CFI_cdesc_t *source,
196196
const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],

flang/include/flang/Runtime/allocatable.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ extern "C" {
2626
// A descriptor must be initialized before being used for any purpose,
2727
// but needs reinitialization in a deallocated state only when there is
2828
// a change of type, rank, or corank.
29-
void RTNAME(AllocatableInitIntrinsic)(
29+
void RTDECL(AllocatableInitIntrinsic)(
3030
Descriptor &, TypeCategory, int kind, int rank = 0, int corank = 0);
31-
void RTNAME(AllocatableInitCharacter)(Descriptor &, SubscriptValue length = 0,
31+
void RTDECL(AllocatableInitCharacter)(Descriptor &, SubscriptValue length = 0,
3232
int kind = 1, int rank = 0, int corank = 0);
33-
void RTNAME(AllocatableInitDerived)(
33+
void RTDECL(AllocatableInitDerived)(
3434
Descriptor &, const typeInfo::DerivedType &, int rank = 0, int corank = 0);
3535

3636
// Initializes the descriptor for an allocatable of intrinsic or derived type.
3737
// These functions are meant to be used in the allocate statement lowering. If
3838
// the descriptor is allocated, the initialization is skiped so the error
3939
// handling can be done by AllocatableAllocate.
40-
void RTNAME(AllocatableInitIntrinsicForAllocate)(
40+
void RTDECL(AllocatableInitIntrinsicForAllocate)(
4141
Descriptor &, TypeCategory, int kind, int rank = 0, int corank = 0);
42-
void RTNAME(AllocatableInitCharacterForAllocate)(Descriptor &,
42+
void RTDECL(AllocatableInitCharacterForAllocate)(Descriptor &,
4343
SubscriptValue length = 0, int kind = 1, int rank = 0, int corank = 0);
44-
void RTNAME(AllocatableInitDerivedForAllocate)(
44+
void RTDECL(AllocatableInitDerivedForAllocate)(
4545
Descriptor &, const typeInfo::DerivedType &, int rank = 0, int corank = 0);
4646

4747
// Checks that an allocatable is not already allocated in statements
@@ -50,37 +50,37 @@ void RTNAME(AllocatableInitDerivedForAllocate)(
5050
// (If there's no STAT=, the error will be caught later anyway, but
5151
// this API allows the error to be caught before descriptor is modified.)
5252
// Return 0 on success (deallocated state), else the STAT= value.
53-
int RTNAME(AllocatableCheckAllocated)(Descriptor &,
53+
int RTDECL(AllocatableCheckAllocated)(Descriptor &,
5454
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
5555
int sourceLine = 0);
5656

5757
// For MOLD= allocation; sets bounds, cobounds, and length type
5858
// parameters from another descriptor. The destination descriptor must
5959
// be initialized and deallocated.
60-
void RTNAME(AllocatableApplyMold)(
60+
void RTDECL(AllocatableApplyMold)(
6161
Descriptor &, const Descriptor &mold, int rank = 0);
6262

6363
// Explicitly sets the bounds and length type parameters of an initialized
6464
// deallocated allocatable.
65-
void RTNAME(AllocatableSetBounds)(
65+
void RTDECL(AllocatableSetBounds)(
6666
Descriptor &, int zeroBasedDim, SubscriptValue lower, SubscriptValue upper);
6767

6868
// The upper cobound is ignored for the last codimension.
69-
void RTNAME(AllocatableSetCoBounds)(Descriptor &, int zeroBasedCoDim,
69+
void RTDECL(AllocatableSetCoBounds)(Descriptor &, int zeroBasedCoDim,
7070
SubscriptValue lower, SubscriptValue upper = 0);
7171

7272
// Length type parameters are indexed in declaration order; i.e., 0 is the
7373
// first length type parameter in the deepest base type. (Not for use
7474
// with CHARACTER; see above.)
75-
void RTNAME(AllocatableSetDerivedLength)(
75+
void RTDECL(AllocatableSetDerivedLength)(
7676
Descriptor &, int which, SubscriptValue);
7777

7878
// When an explicit type-spec appears in an ALLOCATE statement for an
7979
// allocatable with an explicit (non-deferred) length type paramater for
8080
// a derived type or CHARACTER value, the explicit value has to match
8181
// the length type parameter's value. This API checks that requirement.
8282
// Returns 0 for success, or the STAT= value on failure with hasStat==true.
83-
int RTNAME(AllocatableCheckLengthParameter)(Descriptor &,
83+
int RTDECL(AllocatableCheckLengthParameter)(Descriptor &,
8484
int which /* 0 for CHARACTER length */, SubscriptValue other,
8585
bool hasStat = false, const Descriptor *errMsg = nullptr,
8686
const char *sourceFile = nullptr, int sourceLine = 0);
@@ -94,38 +94,38 @@ int RTNAME(AllocatableCheckLengthParameter)(Descriptor &,
9494
// Successfully allocated memory is initialized if the allocatable has a
9595
// derived type, and is always initialized by AllocatableAllocateSource().
9696
// Performs all necessary coarray synchronization and validation actions.
97-
int RTNAME(AllocatableAllocate)(Descriptor &, bool hasStat = false,
97+
int RTDECL(AllocatableAllocate)(Descriptor &, bool hasStat = false,
9898
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
9999
int sourceLine = 0);
100-
int RTNAME(AllocatableAllocateSource)(Descriptor &, const Descriptor &source,
100+
int RTDECL(AllocatableAllocateSource)(Descriptor &, const Descriptor &source,
101101
bool hasStat = false, const Descriptor *errMsg = nullptr,
102102
const char *sourceFile = nullptr, int sourceLine = 0);
103103

104104
// Implements the intrinsic subroutine MOVE_ALLOC (16.9.137 in F'2018,
105105
// but note the order of first two arguments is reversed for consistency
106106
// with the other APIs for allocatables.) The destination descriptor
107107
// must be initialized.
108-
std::int32_t RTNAME(MoveAlloc)(Descriptor &to, Descriptor &from,
108+
std::int32_t RTDECL(MoveAlloc)(Descriptor &to, Descriptor &from,
109109
const typeInfo::DerivedType *, bool hasStat = false,
110110
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
111111
int sourceLine = 0);
112112

113113
// Deallocates an allocatable. Finalizes elements &/or components as needed.
114114
// The allocatable is left in an initialized state suitable for reallocation
115115
// with the same bounds, cobounds, and length type parameters.
116-
int RTNAME(AllocatableDeallocate)(Descriptor &, bool hasStat = false,
116+
int RTDECL(AllocatableDeallocate)(Descriptor &, bool hasStat = false,
117117
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
118118
int sourceLine = 0);
119119

120120
// Same as AllocatableDeallocate but also set the dynamic type as the declared
121121
// type as mentioned in 7.3.2.3 note 7.
122-
int RTNAME(AllocatableDeallocatePolymorphic)(Descriptor &,
122+
int RTDECL(AllocatableDeallocatePolymorphic)(Descriptor &,
123123
const typeInfo::DerivedType *, bool hasStat = false,
124124
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
125125
int sourceLine = 0);
126126

127127
// Variant of above that does not finalize; for intermediate results
128-
void RTNAME(AllocatableDeallocateNoFinal)(
128+
void RTDECL(AllocatableDeallocateNoFinal)(
129129
Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
130130
} // extern "C"
131131
} // namespace Fortran::runtime

flang/include/flang/Runtime/api-attrs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@
121121
#undef RT_DEVICE_COMPILATION
122122
#endif
123123

124+
#if defined(__CUDACC__)
125+
#define RT_DIAG_PUSH _Pragma("nv_diagnostic push")
126+
#define RT_DIAG_POP _Pragma("nv_diagnostic pop")
127+
#define RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN \
128+
_Pragma("nv_diag_suppress 20011") _Pragma("nv_diag_suppress 20014")
129+
#else /* !defined(__CUDACC__) */
130+
#define RT_DIAG_PUSH
131+
#define RT_DIAG_POP
132+
#define RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN
133+
#endif /* !defined(__CUDACC__) */
134+
124135
#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */

flang/include/flang/Runtime/derived-api.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ extern "C" {
2929
// Initializes and allocates an object's components, if it has a derived type
3030
// with any default component initialization or automatic components.
3131
// The descriptor must be initialized and non-null.
32-
void RTNAME(Initialize)(
32+
void RTDECL(Initialize)(
3333
const Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
3434

3535
// Finalizes an object and its components. Deallocates any
3636
// allocatable/automatic components. Does not deallocate the descriptor's
3737
// storage.
38-
void RTNAME(Destroy)(const Descriptor &);
38+
void RTDECL(Destroy)(const Descriptor &);
3939

4040
// Finalizes the object and its components.
41-
void RTNAME(Finalize)(
41+
void RTDECL(Finalize)(
4242
const Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
4343

4444
/// Deallocates any allocatable/automatic components.
4545
/// Does not deallocate the descriptor's storage.
4646
/// Does not perform any finalization.
47-
void RTNAME(DestroyWithoutFinalization)(const Descriptor &);
47+
void RTDECL(DestroyWithoutFinalization)(const Descriptor &);
4848

4949
// Intrinsic or defined assignment, with scalar expansion but not type
5050
// conversion.
51-
void RTNAME(Assign)(const Descriptor &, const Descriptor &,
51+
void RTDECL(Assign)(const Descriptor &, const Descriptor &,
5252
const char *sourceFile = nullptr, int sourceLine = 0);
5353

5454
// Perform the test of the CLASS IS type guard statement of the SELECT TYPE
5555
// construct.
56-
bool RTNAME(ClassIs)(const Descriptor &, const typeInfo::DerivedType &);
56+
bool RTDECL(ClassIs)(const Descriptor &, const typeInfo::DerivedType &);
5757

5858
// Perform the test of the SAME_TYPE_AS intrinsic.
59-
bool RTNAME(SameTypeAs)(const Descriptor &, const Descriptor &);
59+
bool RTDECL(SameTypeAs)(const Descriptor &, const Descriptor &);
6060

6161
// Perform the test of the EXTENDS_TYPE_OF intrinsic.
62-
bool RTNAME(ExtendsTypeOf)(const Descriptor &, const Descriptor &);
62+
bool RTDECL(ExtendsTypeOf)(const Descriptor &, const Descriptor &);
6363

6464
} // extern "C"
6565
} // namespace Fortran::runtime

flang/include/flang/Runtime/matmul-transpose.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ extern "C" {
1818
// The most general MATMUL(TRANSPOSE()). All type and shape information is
1919
// taken from the arguments' descriptors, and the result is dynamically
2020
// allocated.
21-
void RTNAME(MatmulTranspose)(Descriptor &, const Descriptor &,
21+
void RTDECL(MatmulTranspose)(Descriptor &, const Descriptor &,
2222
const Descriptor &, const char *sourceFile = nullptr, int line = 0);
2323

2424
// A non-allocating variant; the result's descriptor must be established
2525
// and have a valid base address.
26-
void RTNAME(MatmulTransposeDirect)(const Descriptor &, const Descriptor &,
26+
void RTDECL(MatmulTransposeDirect)(const Descriptor &, const Descriptor &,
2727
const Descriptor &, const char *sourceFile = nullptr, int line = 0);
2828
} // extern "C"
2929
} // namespace Fortran::runtime

flang/include/flang/Runtime/matmul.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ extern "C" {
1717

1818
// The most general MATMUL. All type and shape information is taken from the
1919
// arguments' descriptors, and the result is dynamically allocated.
20-
void RTNAME(Matmul)(Descriptor &, const Descriptor &, const Descriptor &,
20+
void RTDECL(Matmul)(Descriptor &, const Descriptor &, const Descriptor &,
2121
const char *sourceFile = nullptr, int line = 0);
2222

2323
// A non-allocating variant; the result's descriptor must be established
2424
// and have a valid base address.
25-
void RTNAME(MatmulDirect)(const Descriptor &, const Descriptor &,
25+
void RTDECL(MatmulDirect)(const Descriptor &, const Descriptor &,
2626
const Descriptor &, const char *sourceFile = nullptr, int line = 0);
2727
} // extern "C"
2828
} // namespace Fortran::runtime

0 commit comments

Comments
 (0)