Skip to content

Commit a669ae8

Browse files
committed
Bump PyTorch pin to nightly dev20260726
1 parent 3aeaa80 commit a669ae8

9 files changed

Lines changed: 106 additions & 82 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
release/2.13
1+
34fbe9e6e29430e1820fc960e50530a3e1d75821

runtime/core/portable_type/c10/c10/util/complex.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,11 @@ C10_HOST_DEVICE T abs(const c10::complex<T>& z) {
3131
#endif
3232
}
3333

34-
#if defined(USE_ROCM)
35-
#define ROCm_Bug(x)
36-
#else
37-
#define ROCm_Bug(x) x
38-
#endif
39-
4034
template <typename T>
4135
C10_HOST_DEVICE T arg(const c10::complex<T>& z) {
42-
return ROCm_Bug(std)::atan2(std::imag(z), std::real(z));
36+
return std::atan2(std::imag(z), std::real(z));
4337
}
4438

45-
#undef ROCm_Bug
46-
4739
template <typename T>
4840
constexpr T norm(const c10::complex<T>& z) {
4941
return z.real() * z.real() + z.imag() * z.imag();

runtime/core/portable_type/c10/c10/util/llvmMathExtras.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ constexpr inline bool isShiftedUInt(uint64_t x) {
400400
N + S <= 64, "isShiftedUInt<N, S> with N + S > 64 is too wide.");
401401
// Per the two static_asserts above, S must be strictly less than 64. So
402402
// 1 << S is not undefined behavior.
403+
// NOLINTNEXTLINE(bugprone-chained-comparison)
403404
return isUInt<N + S>(x) && (x % (UINT64_C(1) << S) == 0);
404405
}
405406

runtime/core/portable_type/c10/c10/util/overflows.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,28 @@ template <typename To, typename From>
6161
std::enable_if_t<std::is_floating_point_v<From>, bool> overflows(
6262
From f,
6363
bool strict_unsigned [[maybe_unused]] = false) {
64-
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
64+
using ToScalar = typename scalar_value_type<To>::type;
65+
using limit = std::numeric_limits<ToScalar>;
6566
if (limit::has_infinity && std::isinf(static_cast<double>(f))) {
6667
return false;
6768
}
6869
if (!limit::has_quiet_NaN && (f != f)) {
6970
return true;
7071
}
72+
if constexpr (std::is_integral_v<ToScalar>) {
73+
// limit::max() for wide integer types is NOT exactly representable in
74+
// floating point (e.g. int64 max = 2^63-1 rounds up to 2^63), so `f >
75+
// limit::max()` lets a just-out-of-range value like 2^63 slip through and
76+
// then become INT64_MIN via static_cast. Compare against the
77+
// exactly-representable upper bound max()+1 == 2^digits instead. lowest()
78+
// is 0 or a negated power of two, so it stays exact. (digits-1 keeps the
79+
// shift < 64 for the uint64 case; the *2 recovers 2^digits without a 1<<64
80+
// overflow.)
81+
constexpr int digits = limit::digits;
82+
constexpr From upper =
83+
static_cast<From>(uint64_t{1} << (digits - 1)) * From{2};
84+
return f < static_cast<From>(limit::lowest()) || f >= upper;
85+
}
7186
return f < limit::lowest() || f > limit::max();
7287
}
7388

runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@
123123
#define C10_HAS_CPP_ATTRIBUTE(x) (0)
124124
#endif
125125

126+
/// Bind a returned reference/pointer's lifetime to a parameter (or *this) so
127+
/// Clang can warn when it would dangle. Expands to nothing on compilers that
128+
/// lack the attribute (e.g. non-clang, older nvcc).
129+
#if C10_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
130+
#define C10_LIFETIMEBOUND [[clang::lifetimebound]]
131+
#else
132+
#define C10_LIFETIMEBOUND
133+
#endif
134+
126135
#ifndef FBCODE_CAFFE2
127136
/// DEPRECATED: Warn if a type or return value is discarded.
128137
#define C10_NODISCARD [[nodiscard]]

runtime/core/portable_type/c10/torch/headeronly/util/Half.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ C10_HOST_DEVICE inline float fp16_ieee_to_fp32_value(uint16_t h) {
213213
* Now, remember that denormalized half-precision numbers are represented as:
214214
* FP16 = mantissa * 2**(-24).
215215
* The trick is to construct a normalized single-precision number with the
216-
* same mantissa and thehalf-precision input and with an exponent which would
216+
* same mantissa and the half-precision input and with an exponent which would
217217
* scale the corresponding mantissa bits to 2**(-24). A normalized
218218
* single-precision floating-point number is represented as: FP32 = (1 +
219219
* mantissa * 2**(-23)) * 2**(exponent - 127) Therefore, when the biased

runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,19 @@ C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion")
1414

1515
namespace c10 {
1616

17-
/// Returns false since we cannot have x < 0 if x is unsigned.
18-
template <typename T>
19-
inline constexpr bool is_negative(
20-
const T& /*x*/,
21-
std::true_type /*is_unsigned*/) {
22-
return false;
23-
}
24-
25-
/// Returns true if a signed variable x < 0
26-
template <typename T>
27-
inline constexpr bool is_negative(const T& x, std::false_type /*is_unsigned*/) {
28-
return x < T(0);
29-
}
30-
3117
/// Returns true if x < 0
3218
/// NOTE: Will fail on an unsigned custom type
3319
/// For the most part it's possible to fix this if
3420
/// the custom type has a constexpr constructor.
3521
/// However, notably, c10::Half does not :-(
3622
template <typename T>
3723
inline constexpr bool is_negative(const T& x) {
38-
return is_negative(x, std::is_unsigned<T>());
39-
}
40-
41-
/// Returns the sign of an unsigned variable x as 0, 1
42-
template <typename T>
43-
inline constexpr int signum(const T& x, std::true_type /*is_unsigned*/) {
44-
return T(0) < x;
45-
}
46-
47-
/// Returns the sign of a signed variable x as -1, 0, 1
48-
template <typename T>
49-
inline constexpr int signum(const T& x, std::false_type /*is_unsigned*/) {
50-
return (T(0) < x) - (x < T(0));
24+
if constexpr (std::is_unsigned_v<T>) {
25+
// An unsigned value can never be less than zero.
26+
return false;
27+
} else {
28+
return x < T(0);
29+
}
5130
}
5231

5332
/// Returns the sign of x as -1, 0, 1
@@ -57,7 +36,11 @@ inline constexpr int signum(const T& x, std::false_type /*is_unsigned*/) {
5736
/// However, notably, c10::Half does not :-(
5837
template <typename T>
5938
inline constexpr int signum(const T& x) {
60-
return signum(x, std::is_unsigned<T>());
39+
if constexpr (std::is_unsigned_v<T>) {
40+
return T(0) < x;
41+
} else {
42+
return (T(0) < x) - (x < T(0));
43+
}
6144
}
6245

6346
/// Returns true if a and b are not both negative
@@ -86,53 +69,22 @@ inline constexpr bool greater_than_max(const T& x) {
8669
#pragma GCC diagnostic pop
8770
#endif
8871

89-
/// Returns true if x < lowest(Limit). Standard comparison
90-
template <typename Limit, typename T>
91-
inline constexpr bool less_than_lowest(
92-
const T& x,
93-
std::false_type /*limit_is_unsigned*/,
94-
std::false_type /*x_is_unsigned*/) {
95-
return x < std::numeric_limits<Limit>::lowest();
96-
}
97-
98-
/// Returns false since all the limit is signed and therefore includes
99-
/// negative values but x cannot be negative because it is unsigned
100-
template <typename Limit, typename T>
101-
inline constexpr bool less_than_lowest(
102-
const T& /*x*/,
103-
std::false_type /*limit_is_unsigned*/,
104-
std::true_type /*x_is_unsigned*/) {
105-
return false;
106-
}
107-
108-
/// Returns true if x < 0, where 0 is constructed from T.
109-
/// Limit is not signed, so its lower value is zero
110-
template <typename Limit, typename T>
111-
inline constexpr bool less_than_lowest(
112-
const T& x,
113-
std::true_type /*limit_is_unsigned*/,
114-
std::false_type /*x_is_unsigned*/) {
115-
return x < T(0);
116-
}
117-
118-
/// Returns false sign both types are unsigned
119-
template <typename Limit, typename T>
120-
inline constexpr bool less_than_lowest(
121-
const T& /*x*/,
122-
std::true_type /*limit_is_unsigned*/,
123-
std::true_type /*x_is_unsigned*/) {
124-
return false;
125-
}
126-
127-
/// Returns true if x is less than the lowest value of type T
72+
/// Returns true if x is less than the lowest value of type Limit
12873
/// NOTE: Will fail on an unsigned custom type
12974
/// For the most part it's possible to fix this if
13075
/// the custom type has a constexpr constructor.
13176
/// However, notably, c10::Half does not :
13277
template <typename Limit, typename T>
13378
inline constexpr bool less_than_lowest(const T& x) {
134-
return less_than_lowest<Limit>(
135-
x, std::is_unsigned<Limit>(), std::is_unsigned<T>());
79+
if constexpr (std::is_unsigned_v<T>) {
80+
// x is unsigned, so it can never be below the lowest value of any type.
81+
return false;
82+
} else if constexpr (std::is_unsigned_v<Limit>) {
83+
// Limit is unsigned, so its lowest value is zero.
84+
return x < T(0);
85+
} else {
86+
return x < std::numeric_limits<Limit>::lowest();
87+
}
13688
}
13789

13890
} // namespace c10

runtime/core/portable_type/c10/torch/headeronly/util/complex.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <complex>
44

55
#include <torch/headeronly/macros/Macros.h>
6+
#include <torch/headeronly/util/BFloat16.h>
67
#include <torch/headeronly/util/Half.h>
78

89
#if defined(__CUDACC__) || defined(__HIPCC__)
@@ -588,6 +589,60 @@ struct alignas(4) complex<Half> {
588589
}
589590
};
590591

592+
template <>
593+
struct alignas(4) complex<BFloat16> {
594+
BFloat16 real_;
595+
BFloat16 imag_;
596+
597+
// Constructors
598+
complex() = default;
599+
// BFloat16 constructor is not constexpr so the following constructor can't
600+
// be constexpr
601+
C10_HOST_DEVICE explicit inline complex(
602+
const BFloat16& real,
603+
const BFloat16& imag)
604+
: real_(real), imag_(imag) {}
605+
C10_HOST_DEVICE inline complex(const c10::complex<float>& value)
606+
: real_(value.real()), imag_(value.imag()) {}
607+
608+
// Conversion operator
609+
inline C10_HOST_DEVICE operator c10::complex<float>() const {
610+
return {real_, imag_};
611+
}
612+
613+
constexpr C10_HOST_DEVICE BFloat16 real() const {
614+
return real_;
615+
}
616+
constexpr C10_HOST_DEVICE BFloat16 imag() const {
617+
return imag_;
618+
}
619+
620+
C10_HOST_DEVICE complex<BFloat16>& operator+=(
621+
const complex<BFloat16>& other) {
622+
real_ = static_cast<float>(real_) + static_cast<float>(other.real_);
623+
imag_ = static_cast<float>(imag_) + static_cast<float>(other.imag_);
624+
return *this;
625+
}
626+
627+
C10_HOST_DEVICE complex<BFloat16>& operator-=(
628+
const complex<BFloat16>& other) {
629+
real_ = static_cast<float>(real_) - static_cast<float>(other.real_);
630+
imag_ = static_cast<float>(imag_) - static_cast<float>(other.imag_);
631+
return *this;
632+
}
633+
634+
C10_HOST_DEVICE complex<BFloat16>& operator*=(
635+
const complex<BFloat16>& other) {
636+
auto a = static_cast<float>(real_);
637+
auto b = static_cast<float>(imag_);
638+
auto c = static_cast<float>(other.real());
639+
auto d = static_cast<float>(other.imag());
640+
real_ = a * c - b * d;
641+
imag_ = a * d + b * c;
642+
return *this;
643+
}
644+
};
645+
591646
} // namespace c10
592647

593648
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)

torch_pin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
TORCH_VERSION = "2.13.0"
2-
# NIGHTLY_VERSION = "dev20260318" Temporarily pinning to stable release candidate. Revert https://github.com/pytorch/executorch/pull/18287
2+
NIGHTLY_VERSION = "dev20260726"

0 commit comments

Comments
 (0)