Move Half to headeronly (#159172)

Essence of this copypasta:
- combine Half-inl.h and Half.h in c10/util -> torch/headeronly/util/Half.h
- Add NOLINTNEXTLINE's to the portions of Half-inl.h that were previously in the ignore list of clangtidy
- Re-expose all APIs in namespaces and through includes of the original files. Ideally, we would have the APIs in torch::headeronly and reexpose them in c10, but that runs into BC issues (see D78997465) so for now we are keeping the APIs in c10 but reexposing them in torch::headeronly.
- Change test cases in test_aoti_abi_check to test torch::headeronly::Half vs c10::Half (they're the same thing but we eventually want all the tests for headeronly APIs to only import from headeronly).

Pull Request resolved: https://github.com/pytorch/pytorch/pull/159172
Approved by: https://github.com/albanD, https://github.com/desertfire
This commit is contained in:
Jane Xu
2025-07-30 08:11:59 -07:00
committed by PyTorch MergeBot
parent ee343ce60c
commit 259e79e3ff
4 changed files with 568 additions and 593 deletions

View File

@@ -6,10 +6,10 @@
#include <c10/util/Float8_e4m3fnuz.h>
#include <c10/util/Float8_e5m2.h>
#include <c10/util/Float8_e5m2fnuz.h>
#include <c10/util/Half.h>
#include <c10/util/complex.h>
#include <torch/headeronly/util/Float4_e2m1fn_x2.h>
#include <torch/headeronly/util/Half.h>
#include <torch/headeronly/util/bits.h>
#include <torch/headeronly/util/qint32.h>
#include <torch/headeronly/util/qint8.h>
@@ -93,17 +93,28 @@ TEST(TestDtype, TestFloat4) {
}
TEST(TestDtype, TestHalf) {
c10::Half a = 1.0f;
c10::Half b = 2.0f;
c10::Half add = 3.0f;
c10::Half sub = -1.0f;
c10::Half mul = 2.0f;
c10::Half div = 0.5f;
torch::headeronly::Half a = 1.0f;
torch::headeronly::Half b = 2.0f;
torch::headeronly::Half add = 3.0f;
torch::headeronly::Half sub = -1.0f;
torch::headeronly::Half mul = 2.0f;
torch::headeronly::Half div = 0.5f;
EXPECT_EQ(a + b, add);
EXPECT_EQ(a - b, sub);
EXPECT_EQ(a * b, mul);
EXPECT_EQ(a / b, div);
EXPECT_EQ(a += b, add);
EXPECT_EQ(a -= b, add - b);
EXPECT_EQ(a *= b, b);
EXPECT_EQ(a /= b, mul * div);
#if defined(__aarch64__) && !defined(__CUDACC__)
EXPECT_EQ(
torch::headeronly::detail::fp16_to_bits(
torch::headeronly::detail::fp16_from_bits(32)),
32);
#endif
}
TEST(TestDtype, TestComplexFloat) {