Skip to content

Commit 8127162

Browse files
authored
1 parent 14f3cdc commit 8127162

File tree

24 files changed

+384
-1
lines changed

24 files changed

+384
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ X86 Support
661661

662662
- Supported intrinsics for ``MOVRS AND AVX10.2``.
663663
* Supported intrinsics of ``_mm(256|512)_(mask(z))_loadrs_epi(8|16|32|64)``.
664+
- Support ISA of ``AMX-FP8``.
664665

665666
Arm and AArch64 Support
666667
^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/BuiltinsX86_64.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiv*SLLiSLLiIi", "n", "cmpccxadd")
155155
// AMX_FP16 FP16
156156
TARGET_BUILTIN(__builtin_ia32_tdpfp16ps, "vIUcIUcIUc", "n", "amx-fp16")
157157

158+
// AMX FP8
159+
TARGET_BUILTIN(__builtin_ia32_tdpbf8ps, "vIUcUIcUIc", "n", "amx-fp8")
160+
TARGET_BUILTIN(__builtin_ia32_tdpbhf8ps, "vIUcUIcUIc", "n", "amx-fp8")
161+
TARGET_BUILTIN(__builtin_ia32_tdphbf8ps, "vIUcUIcUIc", "n", "amx-fp8")
162+
TARGET_BUILTIN(__builtin_ia32_tdphf8ps, "vIUcUIcUIc", "n", "amx-fp8")
163+
158164
// RAO-INT
159165
TARGET_BUILTIN(__builtin_ia32_aadd64, "vv*SOi", "n", "raoint")
160166
TARGET_BUILTIN(__builtin_ia32_aand64, "vv*SOi", "n", "raoint")

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6300,6 +6300,8 @@ def mamx_fp16 : Flag<["-"], "mamx-fp16">, Group<m_x86_Features_Group>;
63006300
def mno_amx_fp16 : Flag<["-"], "mno-amx-fp16">, Group<m_x86_Features_Group>;
63016301
def mamx_int8 : Flag<["-"], "mamx-int8">, Group<m_x86_Features_Group>;
63026302
def mno_amx_int8 : Flag<["-"], "mno-amx-int8">, Group<m_x86_Features_Group>;
6303+
def mamx_fp8 : Flag<["-"], "mamx-fp8">, Group<m_x86_Features_Group>;
6304+
def mno_amx_fp8 : Flag<["-"], "mno-amx-fp8">, Group<m_x86_Features_Group>;
63036305
def mamx_tile : Flag<["-"], "mamx-tile">, Group<m_x86_Features_Group>;
63046306
def mno_amx_tile : Flag<["-"], "mno-amx-tile">, Group<m_x86_Features_Group>;
63056307
def mcmpccxadd : Flag<["-"], "mcmpccxadd">, Group<m_x86_Features_Group>;

clang/lib/Basic/Targets/X86.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
428428
HasAMXTILE = true;
429429
} else if (Feature == "+amx-complex") {
430430
HasAMXCOMPLEX = true;
431+
} else if (Feature == "+amx-fp8") {
432+
HasAMXFP8 = true;
431433
} else if (Feature == "+cmpccxadd") {
432434
HasCMPCCXADD = true;
433435
} else if (Feature == "+raoint") {
@@ -947,6 +949,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
947949
Builder.defineMacro("__AMX_FP16__");
948950
if (HasAMXCOMPLEX)
949951
Builder.defineMacro("__AMX_COMPLEX__");
952+
if (HasAMXFP8)
953+
Builder.defineMacro("__AMX_FP8__");
950954
if (HasCMPCCXADD)
951955
Builder.defineMacro("__CMPCCXADD__");
952956
if (HasRAOINT)
@@ -1077,6 +1081,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
10771081
.Case("amx-fp16", true)
10781082
.Case("amx-int8", true)
10791083
.Case("amx-tile", true)
1084+
.Case("amx-fp8", true)
10801085
.Case("avx", true)
10811086
.Case("avx10.1-256", true)
10821087
.Case("avx10.1-512", true)
@@ -1195,6 +1200,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
11951200
.Case("amx-fp16", HasAMXFP16)
11961201
.Case("amx-int8", HasAMXINT8)
11971202
.Case("amx-tile", HasAMXTILE)
1203+
.Case("amx-fp8", HasAMXFP8)
11981204
.Case("avx", SSELevel >= AVX)
11991205
.Case("avx10.1-256", HasAVX10_1)
12001206
.Case("avx10.1-512", HasAVX10_1_512)

clang/lib/Basic/Targets/X86.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
157157
bool HasAMXINT8 = false;
158158
bool HasAMXBF16 = false;
159159
bool HasAMXCOMPLEX = false;
160+
bool HasAMXFP8 = false;
160161
bool HasSERIALIZE = false;
161162
bool HasTSXLDTRK = false;
162163
bool HasUSERMSR = false;

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ set(x86_files
149149
amxcomplexintrin.h
150150
amxfp16intrin.h
151151
amxintrin.h
152+
amxfp8intrin.h
152153
avx10_2_512bf16intrin.h
153154
avx10_2_512convertintrin.h
154155
avx10_2_512minmaxintrin.h

clang/lib/Headers/amxfp8intrin.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*===------------- amxfp8intrin.h - AMX intrinsics -*- C++ -*----------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===------------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __IMMINTRIN_H
11+
#error "Never use <amxfp8intrin.h> directly; include <immintrin.h> instead."
12+
#endif /* __IMMINTRIN_H */
13+
14+
#ifndef __AMXFP8INTRIN_H
15+
#define __AMXFP8INTRIN_H
16+
#ifdef __x86_64__
17+
18+
/// Peform the dot product of a BF8 value \a a by a BF8 value \a b accumulating
19+
/// into a Single Precision (FP32) source/dest \a dst.
20+
///
21+
/// \headerfile <immintrin.h>
22+
///
23+
/// \code
24+
/// void _tile_dpbf8ps (__tile dst, __tile a, __tile b)
25+
/// \endcode
26+
///
27+
/// This intrinsic corresponds to the \c TDPBF8PS instruction.
28+
///
29+
/// \param dst
30+
/// The destination tile. Max size is 1024 Bytes.
31+
/// \param a
32+
/// The 1st source tile. Max size is 1024 Bytes.
33+
/// \param b
34+
/// The 2nd source tile. Max size is 1024 Bytes.
35+
#define _tile_dpbf8ps(dst, a, b) __builtin_ia32_tdpbf8ps((dst), (a), (b))
36+
37+
/// Perform the dot product of a BF8 value \a a by an HF8 value \a b
38+
/// accumulating into a Single Precision (FP32) source/dest \a dst.
39+
///
40+
/// \headerfile <immintrin.h>
41+
///
42+
/// \code
43+
/// void _tile_dpbhf8ps (__tile dst, __tile a, __tile b)
44+
/// \endcode
45+
///
46+
/// This intrinsic corresponds to the \c TDPBHF8PS instruction.
47+
///
48+
/// \param dst
49+
/// The destination tile. Max size is 1024 Bytes.
50+
/// \param a
51+
/// The 1st source tile. Max size is 1024 Bytes.
52+
/// \param b
53+
/// The 2nd source tile. Max size is 1024 Bytes.
54+
#define _tile_dpbhf8ps(dst, a, b) __builtin_ia32_tdpbhf8ps((dst), (a), (b))
55+
56+
/// Perform the dot product of an HF8 value \a a by a BF8 value \a b
57+
/// accumulating into a Single Precision (FP32) source/dest \a dst.
58+
///
59+
/// \headerfile <immintrin.h>
60+
///
61+
/// \code
62+
/// void _tile_dphbf8ps (__tile dst, __tile a, __tile b)
63+
/// \endcode
64+
///
65+
/// This intrinsic corresponds to the \c TDPHBF8PS instruction.
66+
///
67+
/// \param dst
68+
/// The destination tile. Max size is 1024 Bytes.
69+
/// \param a
70+
/// The 1st source tile. Max size is 1024 Bytes.
71+
/// \param b
72+
/// The 2nd source tile. Max size is 1024 Bytes.
73+
#define _tile_dphbf8ps(dst, a, b) __builtin_ia32_tdphbf8ps((dst), (a), (b))
74+
75+
/// Perform the dot product of an HF8 value \a a by an HF8 value \a b
76+
/// accumulating into a Single Precision (FP32) source/dest \a dst.
77+
///
78+
/// \headerfile <immintrin.h>
79+
///
80+
/// \code
81+
/// void _tile_dphf8ps (__tile dst, __tile a, __tile b)
82+
/// \endcode
83+
///
84+
/// This intrinsic corresponds to the \c TDPHF8PS instruction.
85+
///
86+
/// \param dst
87+
/// The destination tile. Max size is 1024 Bytes.
88+
/// \param a
89+
/// The 1st source tile. Max size is 1024 Bytes.
90+
/// \param b
91+
/// The 2nd source tile. Max size is 1024 Bytes.
92+
#define _tile_dphf8ps(dst, a, b) __builtin_ia32_tdphf8ps((dst), (a), (b))
93+
94+
#endif /* __x86_64__ */
95+
#endif /* __AMXFP8INTRIN_H */

clang/lib/Headers/immintrin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ _storebe_i64(void * __P, long long __D) {
648648
#include <amxcomplexintrin.h>
649649
#endif
650650

651+
#if !defined(__SCE__) || __has_feature(modules) || defined(__AMX_FP8__)
652+
#include <amxfp8intrin.h>
653+
#endif
654+
651655
#if !defined(__SCE__) || __has_feature(modules) || \
652656
defined(__AVX512VP2INTERSECT__)
653657
#include <avx512vp2intersectintrin.h>

clang/lib/Sema/SemaX86.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ bool SemaX86::CheckBuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall) {
640640
case X86::BI__builtin_ia32_tdpfp16ps:
641641
case X86::BI__builtin_ia32_tcmmimfp16ps:
642642
case X86::BI__builtin_ia32_tcmmrlfp16ps:
643+
case X86::BI__builtin_ia32_tdpbf8ps:
644+
case X86::BI__builtin_ia32_tdpbhf8ps:
645+
case X86::BI__builtin_ia32_tdphbf8ps:
646+
case X86::BI__builtin_ia32_tdphf8ps:
643647
return CheckBuiltinTileRangeAndDuplicate(TheCall, {0, 1, 2});
644648
}
645649
}

clang/test/CodeGen/X86/amx_fp8.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-fp8 \
2+
// RUN: -emit-llvm -o - -Werror -pedantic | FileCheck %s
3+
#include <immintrin.h>
4+
5+
void test_amx(void *data) {
6+
//CHECK-LABEL: @test_amx
7+
//CHECK: call void @llvm.x86.tdpbf8ps(i8 1, i8 2, i8 3)
8+
_tile_dpbf8ps(1, 2, 3);
9+
}
10+
11+
void test_amx2(void *data) {
12+
//CHECK-LABEL: @test_amx2
13+
//CHECK: call void @llvm.x86.tdpbhf8ps(i8 1, i8 2, i8 3)
14+
_tile_dpbhf8ps(1, 2, 3);
15+
}
16+
17+
void test_amx3(void *data) {
18+
//CHECK-LABEL: @test_amx3
19+
//CHECK: call void @llvm.x86.tdphbf8ps(i8 1, i8 2, i8 3)
20+
_tile_dphbf8ps(1, 2, 3);
21+
}
22+
23+
void test_amx4(void *data) {
24+
//CHECK-LABEL: @test_amx4
25+
//CHECK: call void @llvm.x86.tdphf8ps(i8 1, i8 2, i8 3)
26+
_tile_dphf8ps(1, 2, 3);
27+
}

0 commit comments

Comments
 (0)