[AOTI] Move c10/util ostream function implementations to their headers (#123847)

Summary: AOTInductor generated code for CPU models may have direct reference to these c10-implemented data types, see _inductor/codegen/cpp_prefix.h. To make sure the AOTI generated code is ABI backward compatible, we need to change those headers to a header-only implementation. The next PR in this stack will add tests to use those data types without linking against libtorch.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123847
Approved by: https://github.com/jansel
This commit is contained in:
Bin Bao
2024-04-11 08:18:42 -07:00
committed by PyTorch MergeBot
parent 9ed9b22ec0
commit cbefaf2a37
12 changed files with 34 additions and 41 deletions

View File

@ -7,8 +7,8 @@
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iosfwd>
#include <ostream>
#if defined(__CUDACC__) && !defined(USE_ROCM)
#include <cuda_bf16.h>
@ -114,7 +114,12 @@ struct alignas(2) BFloat16 {
#endif
};
C10_API std::ostream& operator<<(std::ostream& out, const BFloat16& value);
C10_API inline std::ostream& operator<<(
std::ostream& out,
const BFloat16& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/BFloat16.h>
#include <ostream>
#include <type_traits>
namespace c10 {
@ -8,8 +7,4 @@ static_assert(
std::is_standard_layout_v<BFloat16>,
"c10::BFloat16 must be standard layout.");
std::ostream& operator<<(std::ostream& out, const BFloat16& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/Float8_e4m3fn.h>
#include <ostream>
#include <type_traits>
namespace c10 {
@ -8,8 +7,4 @@ static_assert(
std::is_standard_layout_v<Float8_e4m3fn>,
"c10::Float8_e4m3fn must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Float8_e4m3fn& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -239,7 +239,12 @@ struct alignas(1) Float8_e4m3fn {
inline C10_HOST_DEVICE bool isnan() const;
};
C10_API std::ostream& operator<<(std::ostream& out, const Float8_e4m3fn& value);
C10_API inline std::ostream& operator<<(
std::ostream& out,
const Float8_e4m3fn& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/Float8_e4m3fnuz.h>
#include <ostream>
namespace c10 {
@ -7,9 +6,4 @@ static_assert(
std::is_standard_layout_v<Float8_e4m3fnuz>,
"c10::Float8_e4m3fnuz must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Float8_e4m3fnuz& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -127,9 +127,12 @@ struct alignas(1) Float8_e4m3fnuz {
inline C10_HOST_DEVICE bool isnan() const;
};
C10_API std::ostream& operator<<(
C10_API inline std::ostream& operator<<(
std::ostream& out,
const Float8_e4m3fnuz& value);
const Float8_e4m3fnuz& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/Float8_e5m2.h>
#include <ostream>
namespace c10 {
@ -7,8 +6,4 @@ static_assert(
std::is_standard_layout<Float8_e5m2>::value,
"c10::Float8_e5m2 must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Float8_e5m2& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -136,7 +136,12 @@ struct alignas(1) Float8_e5m2 {
inline C10_HOST_DEVICE bool isinf() const;
};
C10_API std::ostream& operator<<(std::ostream& out, const Float8_e5m2& value);
C10_API inline std::ostream& operator<<(
std::ostream& out,
const Float8_e5m2& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/Float8_e5m2fnuz.h>
#include <ostream>
namespace c10 {
@ -7,9 +6,4 @@ static_assert(
std::is_standard_layout_v<Float8_e5m2fnuz>,
"c10::Float8_e5m2 must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Float8_e5m2fnuz& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -126,9 +126,12 @@ struct alignas(1) Float8_e5m2fnuz {
inline C10_HOST_DEVICE bool isinf() const;
};
C10_API std::ostream& operator<<(
C10_API inline std::ostream& operator<<(
std::ostream& out,
const Float8_e5m2fnuz& value);
const Float8_e5m2fnuz& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -1,5 +1,4 @@
#include <c10/util/Half.h>
#include <ostream>
#include <type_traits>
namespace c10 {
@ -8,8 +7,4 @@ static_assert(
std::is_standard_layout_v<Half>,
"c10::Half must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Half& value) {
out << (float)value;
return out;
}
} // namespace c10

View File

@ -30,6 +30,7 @@
#include <cstring>
#include <iosfwd>
#include <limits>
#include <ostream>
#ifdef __CUDACC__
#include <cuda_fp16.h>
@ -531,7 +532,10 @@ std::enable_if_t<is_complex<From>::value, bool> overflows(
typename From::value_type>(f.imag());
}
C10_API std::ostream& operator<<(std::ostream& out, const Half& value);
C10_API inline std::ostream& operator<<(std::ostream& out, const Half& value) {
out << (float)value;
return out;
}
} // namespace c10