[Flang][FlangRT][Runtime] Add RT_OFFLOAD_API_GROUP_BEGIN to missing symbols on AMDGPU (#147612)

After the recent move to work queues, in certain cases when linking in
the fortran runtime built for offload on AMDGPU as required in certain
cases, we'll get missing symbols when linking. This PR tries to address
this issue by encompassing more of the library in
RT_OFFLOAD_API_GROUP_BEGIN, which has the affect of compiling these
functions for AMDGPU, resolving the missing symbols.

This PR should address the following issue:
https://github.com/llvm/llvm-project/issues/145888
This commit is contained in:
agozillon 2025-07-10 13:19:58 +02:00 committed by GitHub
parent 59a99c6f2c
commit 75f81ded8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 41 additions and 0 deletions

View File

@ -25,6 +25,8 @@ class Descriptor;
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
class IoStatementState; class IoStatementState;
enum EditingFlags { enum EditingFlags {
@ -200,5 +202,8 @@ private:
// must be last, may be incomplete // must be last, may be incomplete
Iteration stack_[maxMaxHeight]; Iteration stack_[maxMaxHeight];
}; };
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_FORMAT_H_ #endif // FLANG_RT_RUNTIME_FORMAT_H_

View File

@ -18,6 +18,8 @@
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
class IoErrorHandler; class IoErrorHandler;
// Points to (but does not own) a CHARACTER scalar or array for internal I/O. // Points to (but does not own) a CHARACTER scalar or array for internal I/O.
@ -55,5 +57,8 @@ private:
extern template class InternalDescriptorUnit<Direction::Output>; extern template class InternalDescriptorUnit<Direction::Output>;
extern template class InternalDescriptorUnit<Direction::Input>; extern template class InternalDescriptorUnit<Direction::Input>;
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_INTERNAL_UNIT_H_ #endif // FLANG_RT_RUNTIME_INTERNAL_UNIT_H_

View File

@ -28,6 +28,8 @@
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
class ExternalFileUnit; class ExternalFileUnit;
class ChildIo; class ChildIo;
@ -880,5 +882,7 @@ private:
ExternalFileUnit *unit_{nullptr}; ExternalFileUnit *unit_{nullptr};
}; };
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_IO_STMT_H_ #endif // FLANG_RT_RUNTIME_IO_STMT_H_

View File

@ -32,6 +32,8 @@ class DerivedType;
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
struct NonTbpDefinedIo { struct NonTbpDefinedIo {
const typeInfo::DerivedType &derivedType; const typeInfo::DerivedType &derivedType;
void (*subroutine)(); // null means no non-TBP defined I/O here void (*subroutine)(); // null means no non-TBP defined I/O here
@ -52,5 +54,7 @@ struct NonTbpDefinedIoTable {
bool ignoreNonTbpEntries{false}; bool ignoreNonTbpEntries{false};
}; };
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_NON_TBP_DIO_H_ #endif // FLANG_RT_RUNTIME_NON_TBP_DIO_H_

View File

@ -74,6 +74,8 @@ namespace Fortran::runtime {
class Terminator; class Terminator;
class WorkQueue; class WorkQueue;
RT_OFFLOAD_API_GROUP_BEGIN
// Ticket worker base classes // Ticket worker base classes
template <typename TICKET> class ImmediateTicketRunner { template <typename TICKET> class ImmediateTicketRunner {
@ -361,6 +363,7 @@ public:
: ImmediateTicketRunner<DescriptorIoTicket>(*this), : ImmediateTicketRunner<DescriptorIoTicket>(*this),
Elementwise{descriptor}, io_{io}, table_{table}, Elementwise{descriptor}, io_{io}, table_{table},
anyIoTookPlace_{anyIoTookPlace} {} anyIoTookPlace_{anyIoTookPlace} {}
RT_API_ATTRS int Begin(WorkQueue &); RT_API_ATTRS int Begin(WorkQueue &);
RT_API_ATTRS int Continue(WorkQueue &); RT_API_ATTRS int Continue(WorkQueue &);
RT_API_ATTRS bool &anyIoTookPlace() { return anyIoTookPlace_; } RT_API_ATTRS bool &anyIoTookPlace() { return anyIoTookPlace_; }
@ -551,5 +554,7 @@ private:
TicketList *firstFree_{static_}; TicketList *firstFree_{static_};
}; };
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime } // namespace Fortran::runtime
#endif // FLANG_RT_RUNTIME_WORK_QUEUE_H_ #endif // FLANG_RT_RUNTIME_WORK_QUEUE_H_

View File

@ -15,6 +15,8 @@
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
RT_API_ATTRS bool EditIntegerInput( RT_API_ATTRS bool EditIntegerInput(
IoStatementState &, const DataEdit &, void *, int kind, bool isSigned); IoStatementState &, const DataEdit &, void *, int kind, bool isSigned);
@ -49,5 +51,7 @@ extern template RT_API_ATTRS bool EditCharacterInput(
extern template RT_API_ATTRS bool EditCharacterInput( extern template RT_API_ATTRS bool EditCharacterInput(
IoStatementState &, const DataEdit &, char32_t *, std::size_t); IoStatementState &, const DataEdit &, char32_t *, std::size_t);
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_EDIT_INPUT_H_ #endif // FLANG_RT_RUNTIME_EDIT_INPUT_H_

View File

@ -25,6 +25,8 @@
namespace Fortran::runtime::io { namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
// I, B, O, Z, and G output editing for INTEGER. // I, B, O, Z, and G output editing for INTEGER.
// The DataEdit reference is const here (and elsewhere in this header) so that // The DataEdit reference is const here (and elsewhere in this header) so that
// one edit descriptor with a repeat factor may safely serve to edit // one edit descriptor with a repeat factor may safely serve to edit
@ -137,5 +139,7 @@ extern template class RealOutputEditing<10>;
// TODO: double/double // TODO: double/double
extern template class RealOutputEditing<16>; extern template class RealOutputEditing<16>;
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_EDIT_OUTPUT_H_ #endif // FLANG_RT_RUNTIME_EDIT_OUTPUT_H_

View File

@ -46,6 +46,8 @@ extern RT_VAR_ATTRS ExternalFileUnit *defaultOutput; // unit 6
extern RT_VAR_ATTRS ExternalFileUnit *errorOutput; // unit 0 extension extern RT_VAR_ATTRS ExternalFileUnit *errorOutput; // unit 0 extension
RT_OFFLOAD_VAR_GROUP_END RT_OFFLOAD_VAR_GROUP_END
RT_OFFLOAD_API_GROUP_BEGIN
#if defined(RT_USE_PSEUDO_FILE_UNIT) #if defined(RT_USE_PSEUDO_FILE_UNIT)
// A flavor of OpenFile class that pretends to be a terminal, // A flavor of OpenFile class that pretends to be a terminal,
// and only provides basic buffering of the output // and only provides basic buffering of the output
@ -298,5 +300,7 @@ private:
Fortran::common::optional<IoStatementState> io_; Fortran::common::optional<IoStatementState> io_;
}; };
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::runtime::io } // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_UNIT_H_ #endif // FLANG_RT_RUNTIME_UNIT_H_

View File

@ -65,6 +65,9 @@ enum DecimalConversionFlags {
#define EXTRA_DECIMAL_CONVERSION_SPACE (1 + 1 + 2 * 16 - 1) #define EXTRA_DECIMAL_CONVERSION_SPACE (1 + 1 + 2 * 16 - 1)
#ifdef __cplusplus #ifdef __cplusplus
RT_OFFLOAD_API_GROUP_BEGIN
template <int PREC> template <int PREC>
RT_API_ATTRS ConversionToDecimalResult ConvertToDecimal(char *, size_t, RT_API_ATTRS ConversionToDecimalResult ConvertToDecimal(char *, size_t,
DecimalConversionFlags, int digits, enum FortranRounding rounding, DecimalConversionFlags, int digits, enum FortranRounding rounding,
@ -110,6 +113,9 @@ extern template RT_API_ATTRS ConversionToBinaryResult<64> ConvertToBinary<64>(
const char *&, enum FortranRounding, const char *end); const char *&, enum FortranRounding, const char *end);
extern template RT_API_ATTRS ConversionToBinaryResult<113> ConvertToBinary<113>( extern template RT_API_ATTRS ConversionToBinaryResult<113> ConvertToBinary<113>(
const char *&, enum FortranRounding, const char *end); const char *&, enum FortranRounding, const char *end);
RT_OFFLOAD_API_GROUP_END
} // namespace Fortran::decimal } // namespace Fortran::decimal
extern "C" { extern "C" {
#define NS(x) Fortran::decimal::x #define NS(x) Fortran::decimal::x