Skip to content

Commit

Permalink
[flang][runtime] Enable I/O APIs in F18 runtime offload builds. (#87543)
Browse files Browse the repository at this point in the history
  • Loading branch information
vzakhari authored Apr 3, 2024
1 parent d53b829 commit 718638d
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 213 deletions.
164 changes: 82 additions & 82 deletions flang/include/flang/Runtime/io-api.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions flang/runtime/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static void SetEnvironmentDefaults(const EnvironmentDefaultList *envDefaults) {
}
}

RT_OFFLOAD_API_GROUP_BEGIN
Fortran::common::optional<Convert> GetConvertFromString(
const char *x, std::size_t n) {
static const char *keywords[]{
Expand All @@ -68,6 +69,7 @@ Fortran::common::optional<Convert> GetConvertFromString(
return Fortran::common::nullopt;
}
}
RT_OFFLOAD_API_GROUP_END

void ExecutionEnvironment::Configure(int ac, const char *av[],
const char *env[], const EnvironmentDefaultList *envDefaults) {
Expand Down
2 changes: 1 addition & 1 deletion flang/runtime/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RT_OFFLOAD_VAR_GROUP_END
// External unformatted I/O data conversions
enum class Convert { Unknown, Native, LittleEndian, BigEndian, Swap };

Fortran::common::optional<Convert> GetConvertFromString(
RT_API_ATTRS Fortran::common::optional<Convert> GetConvertFromString(
const char *, std::size_t);

struct ExecutionEnvironment {
Expand Down
19 changes: 19 additions & 0 deletions flang/runtime/freestanding-tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#define STD_STRCPY_UNSUPPORTED 1
#endif

#if !defined(STD_STRCMP_UNSUPPORTED) && \
(defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)
#define STD_STRCMP_UNSUPPORTED 1
#endif

namespace Fortran::runtime {

#if STD_FILL_N_UNSUPPORTED
Expand Down Expand Up @@ -176,5 +181,19 @@ static inline RT_API_ATTRS char *strcpy(char *dest, const char *src) {
using std::strcpy;
#endif // !STD_STRCPY_UNSUPPORTED

#if STD_STRCMP_UNSUPPORTED
// Provides alternative implementation for std::strcmp(), if
// it is not supported.
static inline RT_API_ATTRS int strcmp(const char *lhs, const char *rhs) {
while (*lhs != '\0' && *lhs == *rhs) {
++lhs;
++rhs;
}
return static_cast<unsigned char>(*lhs) - static_cast<unsigned char>(*rhs);
}
#else // !STD_STRCMP_UNSUPPORTED
using std::strcmp;
#endif // !STD_STRCMP_UNSUPPORTED

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

0 comments on commit 718638d

Please sign in to comment.