Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Added Assign runtime to CUDA build closure. #68171

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions flang/include/flang/ISO_Fortran_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ namespace cfi_internal {
template <typename T> struct FlexibleArray : T {
RT_API_ATTRS T &operator[](int index) { return *(this + index); }
const RT_API_ATTRS T &operator[](int index) const { return *(this + index); }
operator T *() { return this; }
operator const T *() const { return this; }
RT_API_ATTRS operator T *() { return this; }
RT_API_ATTRS operator const T *() const { return this; }
};
} // namespace cfi_internal
#endif
Expand Down Expand Up @@ -182,19 +182,20 @@ template <> struct CdescStorage<0> : public CFI_cdesc_t {};
#ifdef __cplusplus
extern "C" {
#endif
void *CFI_address(const CFI_cdesc_t *, const CFI_index_t subscripts[]);
int CFI_allocate(CFI_cdesc_t *, const CFI_index_t lower_bounds[],
RT_API_ATTRS void *CFI_address(
const CFI_cdesc_t *, const CFI_index_t subscripts[]);
RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *, const CFI_index_t lower_bounds[],
const CFI_index_t upper_bounds[], size_t elem_len);
RT_API_ATTRS int CFI_deallocate(CFI_cdesc_t *);
int CFI_establish(CFI_cdesc_t *, void *base_addr, CFI_attribute_t, CFI_type_t,
size_t elem_len, CFI_rank_t, const CFI_index_t extents[]);
int CFI_is_contiguous(const CFI_cdesc_t *);
RT_API_ATTRS int CFI_is_contiguous(const CFI_cdesc_t *);
RT_API_ATTRS int CFI_section(CFI_cdesc_t *, const CFI_cdesc_t *source,
const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],
const CFI_index_t strides[]);
int CFI_select_part(CFI_cdesc_t *, const CFI_cdesc_t *source,
RT_API_ATTRS int CFI_select_part(CFI_cdesc_t *, const CFI_cdesc_t *source,
size_t displacement, size_t elem_len);
int CFI_setpointer(
RT_API_ATTRS int CFI_setpointer(
CFI_cdesc_t *, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[]);
#ifdef __cplusplus
} // extern "C"
Expand Down
11 changes: 10 additions & 1 deletion flang/include/flang/Runtime/api-attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/*
* RT_OFFLOAD_API_GROUP_BEGIN/END pair is placed around definitions
* of functions that can be referenced in other modules of Flang
* runtime. For OpenMP offload these functions are made "declare target"
* runtime. For OpenMP offload, these functions are made "declare target"
* making sure they are compiled for the target even though direct
* references to them from other "declare target" functions may not
* be seen. Host-only functions should not be put in between these
Expand All @@ -54,6 +54,15 @@
#define RT_OFFLOAD_API_GROUP_BEGIN RT_EXT_API_GROUP_BEGIN
#define RT_OFFLOAD_API_GROUP_END RT_EXT_API_GROUP_END

/*
* RT_OFFLOAD_VAR_GROUP_BEGIN/END pair is placed around definitions
* of variables (e.g. globals or static class members) that can be
* referenced in functions marked with RT_OFFLOAD_API_GROUP_BEGIN/END.
* For OpenMP offload, these variables are made "declare target".
*/
#define RT_OFFLOAD_VAR_GROUP_BEGIN RT_EXT_API_GROUP_BEGIN
#define RT_OFFLOAD_VAR_GROUP_END RT_EXT_API_GROUP_END

/*
* RT_VAR_GROUP_BEGIN/END pair is placed around definitions
* of module scope variables referenced by Flang runtime (directly
Expand Down
10 changes: 5 additions & 5 deletions flang/include/flang/Runtime/assign.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ class Descriptor;

extern "C" {
// API for lowering assignment
void RTNAME(Assign)(Descriptor &to, const Descriptor &from,
void RTDECL(Assign)(Descriptor &to, const Descriptor &from,
const char *sourceFile = nullptr, int sourceLine = 0);
// This variant has no finalization, defined assignment, or allocatable
// reallocation.
void RTNAME(AssignTemporary)(Descriptor &to, const Descriptor &from,
void RTDECL(AssignTemporary)(Descriptor &to, const Descriptor &from,
const char *sourceFile = nullptr, int sourceLine = 0);
void RTNAME(CopyOutAssign)(Descriptor &to, const Descriptor &from,
void RTDECL(CopyOutAssign)(Descriptor &to, const Descriptor &from,
bool skipToInit, const char *sourceFile = nullptr, int sourceLine = 0);
// This variant is for assignments to explicit-length CHARACTER left-hand
// sides that might need to handle truncation or blank-fill, and
// must maintain the character length even if an allocatable array
// is reallocated.
void RTNAME(AssignExplicitLengthCharacter)(Descriptor &to,
void RTDECL(AssignExplicitLengthCharacter)(Descriptor &to,
const Descriptor &from, const char *sourceFile = nullptr,
int sourceLine = 0);
// This variant is assignments to whole polymorphic allocatables.
void RTNAME(AssignPolymorphic)(Descriptor &to, const Descriptor &from,
void RTDECL(AssignPolymorphic)(Descriptor &to, const Descriptor &from,
const char *sourceFile = nullptr, int sourceLine = 0);
} // extern "C"
} // namespace Fortran::runtime
Expand Down
2 changes: 2 additions & 0 deletions flang/include/flang/Runtime/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ static_assert(sizeof(Descriptor) == sizeof(ISO::CFI_cdesc_t));
template <int MAX_RANK = maxRank, bool ADDENDUM = false, int MAX_LEN_PARMS = 0>
class alignas(Descriptor) StaticDescriptor {
public:
RT_OFFLOAD_VAR_GROUP_BEGIN
static constexpr int maxRank{MAX_RANK};
static constexpr int maxLengthTypeParameters{MAX_LEN_PARMS};
static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0};
static constexpr std::size_t byteSize{
Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)};
RT_OFFLOAD_VAR_GROUP_END

RT_API_ATTRS Descriptor &descriptor() {
return *reinterpret_cast<Descriptor *>(storage_);
Expand Down
6 changes: 6 additions & 0 deletions flang/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,16 @@ option(FLANG_EXPERIMENTAL_CUDA_RUNTIME

# List of files that are buildable for all devices.
set(supported_files
ISO_Fortran_binding.cpp
assign.cpp
derived.cpp
descriptor.cpp
stat.cpp
terminator.cpp
tools.cpp
transformational.cpp
type-code.cpp
type-info.cpp
)

if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
Expand Down
23 changes: 14 additions & 9 deletions flang/runtime/ISO_Fortran_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
namespace Fortran::ISO {
extern "C" {

void *CFI_address(
RT_EXT_API_GROUP_BEGIN

RT_API_ATTRS void *CFI_address(
const CFI_cdesc_t *descriptor, const CFI_index_t subscripts[]) {
char *p{static_cast<char *>(descriptor->base_addr)};
const CFI_rank_t rank{descriptor->rank};
Expand All @@ -30,8 +32,9 @@ void *CFI_address(
return p;
}

int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
const CFI_index_t upper_bounds[], std::size_t elem_len) {
RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *descriptor,
const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],
std::size_t elem_len) {
if (!descriptor) {
return CFI_INVALID_DESCRIPTOR;
}
Expand Down Expand Up @@ -81,7 +84,7 @@ int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
return CFI_SUCCESS;
}

int CFI_deallocate(CFI_cdesc_t *descriptor) {
RT_API_ATTRS int CFI_deallocate(CFI_cdesc_t *descriptor) {
if (!descriptor) {
return CFI_INVALID_DESCRIPTOR;
}
Expand All @@ -101,7 +104,7 @@ int CFI_deallocate(CFI_cdesc_t *descriptor) {
return CFI_SUCCESS;
}

int CFI_establish(CFI_cdesc_t *descriptor, void *base_addr,
RT_API_ATTRS int CFI_establish(CFI_cdesc_t *descriptor, void *base_addr,
CFI_attribute_t attribute, CFI_type_t type, std::size_t elem_len,
CFI_rank_t rank, const CFI_index_t extents[]) {
int cfiStatus{VerifyEstablishParameters(descriptor, base_addr, attribute,
Expand All @@ -121,7 +124,7 @@ int CFI_establish(CFI_cdesc_t *descriptor, void *base_addr,
return CFI_SUCCESS;
}

int CFI_is_contiguous(const CFI_cdesc_t *descriptor) {
RT_API_ATTRS int CFI_is_contiguous(const CFI_cdesc_t *descriptor) {
CFI_index_t bytes = descriptor->elem_len;
for (int j{0}; j < descriptor->rank; ++j) {
if (bytes != descriptor->dim[j].sm) {
Expand All @@ -132,7 +135,7 @@ int CFI_is_contiguous(const CFI_cdesc_t *descriptor) {
return 1;
}

int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
RT_API_ATTRS int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],
const CFI_index_t strides[]) {
CFI_index_t extent[CFI_MAX_RANK];
Expand Down Expand Up @@ -208,7 +211,7 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
return CFI_SUCCESS;
}

int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
RT_API_ATTRS int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
std::size_t displacement, std::size_t elem_len) {
if (!result || !source) {
return CFI_INVALID_DESCRIPTOR;
Expand Down Expand Up @@ -243,7 +246,7 @@ int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
return CFI_SUCCESS;
}

int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
RT_API_ATTRS int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
const CFI_index_t lower_bounds[]) {
if (!result) {
return CFI_INVALID_DESCRIPTOR;
Expand Down Expand Up @@ -285,5 +288,7 @@ int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
}
return CFI_SUCCESS;
}

RT_EXT_API_GROUP_END
} // extern "C"
} // namespace Fortran::ISO
3 changes: 2 additions & 1 deletion flang/runtime/assign-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Terminator;
// Note that if allocate object and source expression have the same rank, the
// value of the allocate object becomes the value provided; otherwise the value
// of each element of allocate object becomes the value provided (9.7.1.2(7)).
void DoFromSourceAssign(Descriptor &, const Descriptor &, Terminator &);
RT_API_ATTRS void DoFromSourceAssign(
Descriptor &, const Descriptor &, Terminator &);

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_
Loading