-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[X86][AMX] Support AMX-FP8 #113850
[X86][AMX] Support AMX-FP8 #113850
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*===------------- amxfp8intrin.h - AMX intrinsics -*- C++ -*----------------=== | ||
* | ||
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See https://llvm.org/LICENSE.txt for license information. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
*===------------------------------------------------------------------------=== | ||
*/ | ||
|
||
#ifndef __IMMINTRIN_H | ||
#error "Never use <amxfp8intrin.h> directly; include <immintrin.h> instead." | ||
#endif /* __IMMINTRIN_H */ | ||
|
||
#ifndef __AMXFP8INTRIN_H | ||
#define __AMXFP8INTRIN_H | ||
#ifdef __x86_64__ | ||
|
||
|
||
/// Compute dot-product of brain-float8 (BF8) or hybrid-float8 (HF8) | ||
/// floating-point pairs in tiles \a a and \a b, accumulating the | ||
/// intermediate single-precision (32-bit) floating-point elements with | ||
/// elements in \a dst, and store the 32-bit result back to tile \a dst. | ||
/// | ||
/// \headerfile <immintrin.h> | ||
/// | ||
/// \code | ||
/// void _tile_dpbf8ps (__tile dst, __tile a, __tile b) | ||
/// \endcode | ||
/// | ||
/// This intrinsic corresponds to the \c TDPBF8PS instruction. | ||
/// | ||
/// \param dst | ||
/// The destination tile. Max size is 1024 Bytes. | ||
/// \param a | ||
/// The 1st source tile. Max size is 1024 Bytes. | ||
/// \param b | ||
/// The 2nd source tile. Max size is 1024 Bytes. | ||
#define _tile_dpbf8ps __builtin_ia32_tdpbf8ps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/// \code | ||
/// void _tile_dpbhf8ps (__tile dst, __tile a, __tile b) | ||
/// \endcode | ||
/// | ||
/// This intrinsic corresponds to the \c TDPBHF8PS instruction. | ||
/// | ||
/// \param dst | ||
/// The destination tile. Max size is 1024 Bytes. | ||
/// \param a | ||
/// The 1st source tile. Max size is 1024 Bytes. | ||
/// \param b | ||
/// The 2nd source tile. Max size is 1024 Bytes. | ||
#define _tile_dpbhf8ps __builtin_ia32_tdpbhf8ps | ||
|
||
/// \code | ||
/// void _tile_dphbf8ps (__tile dst, __tile a, __tile b) | ||
/// \endcode | ||
/// | ||
/// This intrinsic corresponds to the \c TDPHBF8PS instruction. | ||
/// | ||
/// \param dst | ||
/// The destination tile. Max size is 1024 Bytes. | ||
/// \param a | ||
/// The 1st source tile. Max size is 1024 Bytes. | ||
/// \param b | ||
/// The 2nd source tile. Max size is 1024 Bytes. | ||
#define _tile_dphbf8ps __builtin_ia32_tdphbf8ps | ||
|
||
/// \code | ||
/// void _tile_dphf8ps (__tile dst, __tile a, __tile b) | ||
/// \endcode | ||
/// | ||
/// This intrinsic corresponds to the \c TDPHF8PS instruction. | ||
/// | ||
/// \param dst | ||
/// The destination tile. Max size is 1024 Bytes. | ||
/// \param a | ||
/// The 1st source tile. Max size is 1024 Bytes. | ||
/// \param b | ||
/// The 2nd source tile. Max size is 1024 Bytes. | ||
#define _tile_dphf8ps __builtin_ia32_tdphf8ps | ||
|
||
#endif /* __x86_64__ */ | ||
#endif /* __AMXFP8INTRIN_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-fp8 \ | ||
// RUN: -emit-llvm -o - -Werror -pedantic | FileCheck %s | ||
#include <immintrin.h> | ||
|
||
void test_amx(void *data) { | ||
//CHECK-LABEL: @test_amx | ||
//CHECK: call void @llvm.x86.tdpbf8ps(i8 1, i8 2, i8 3) | ||
_tile_dpbf8ps(1, 2, 3); | ||
} | ||
|
||
void test_amx2(void *data) { | ||
//CHECK-LABEL: @test_amx2 | ||
//CHECK: call void @llvm.x86.tdpbhf8ps(i8 1, i8 2, i8 3) | ||
_tile_dpbhf8ps(1, 2, 3); | ||
} | ||
|
||
void test_amx3(void *data) { | ||
//CHECK-LABEL: @test_amx3 | ||
//CHECK: call void @llvm.x86.tdphbf8ps(i8 1, i8 2, i8 3) | ||
_tile_dphbf8ps(1, 2, 3); | ||
} | ||
|
||
void test_amx4(void *data) { | ||
//CHECK-LABEL: @test_amx4 | ||
//CHECK: call void @llvm.x86.tdphf8ps(i8 1, i8 2, i8 3) | ||
_tile_dphf8ps(1, 2, 3); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-tile -target-feature +amx-fp8 -verify | ||
|
||
#include <immintrin.h> | ||
|
||
void test_amx(void *data) { | ||
_tile_dpbf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
_tile_dpbhf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
_tile_dphbf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
_tile_dphf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-fp8 -emit-llvm -o - -Wall -Werror -pedantic | FileCheck %s | ||
|
||
void f_tilemul(short a) | ||
{ | ||
//CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdpbf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
__asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
"tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
"tdpbf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
"tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
||
//CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdpbhf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
__asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
"tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
"tdpbhf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
"tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
||
//CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdphbf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
__asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
"tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
"tdphbf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
"tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
||
//CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdphf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
__asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
"tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
"tdphf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
"tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
::: "memory", "tmm0", "tmm6", "tmm7"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5994,6 +5994,23 @@ let TargetPrefix = "x86" in { | |
[llvm_i16_ty, llvm_i16_ty, llvm_i16_ty, | ||
llvm_x86amx_ty, llvm_x86amx_ty, | ||
llvm_x86amx_ty], []>; | ||
|
||
def int_x86_tdpbf8ps : ClangBuiltin<"__builtin_ia32_tdpbf8ps">, | ||
Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
[ImmArg<ArgIndex<0>>, | ||
ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
def int_x86_tdpbhf8ps : ClangBuiltin<"__builtin_ia32_tdpbhf8ps">, | ||
Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
[ImmArg<ArgIndex<0>>, | ||
ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
def int_x86_tdphbf8ps : ClangBuiltin<"__builtin_ia32_tdphbf8ps">, | ||
Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
[ImmArg<ArgIndex<0>>, | ||
ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
def int_x86_tdphf8ps : ClangBuiltin<"__builtin_ia32_tdphf8ps">, | ||
Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
[ImmArg<ArgIndex<0>>, | ||
ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
Comment on lines
+5997
to
+6013
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move them to line 5919. This is for internal intrinsics. |
||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1876,6 +1876,10 @@ const StringMap<bool> sys::getHostCPUFeatures() { | |
MaxLevel >= 0x19 && !getX86CpuIDAndInfo(0x19, &EAX, &EBX, &ECX, &EDX); | ||
Features["widekl"] = HasLeaf7 && HasLeaf19 && ((EBX >> 2) & 1); | ||
|
||
bool HasLeaf1E = | ||
MaxLevel >= 0x1e && !getX86CpuIDAndInfo(0x1e, &EAX, &EBX, &ECX, &EDX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Features["amx-fp8"] = HasLeaf1E && ((EAX >> 4) & 1) && HasAMXSave; | ||
|
||
bool HasLeaf24 = | ||
MaxLevel >= 0x24 && !getX86CpuIDAndInfo(0x24, &EAX, &EBX, &ECX, &EDX); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment need to be added for all intrinsics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'll copy description from instruction set extension document for the file and each intrinsic.