[SPR] i386: Add syscall to enable AMX for latest kernels

gcc/testsuite/ChangeLog:

	* gcc.target/i386/amx-check.h (request_perm_xtile_data):
	New function to check if AMX is usable and enable AMX.
	(main): Run test if AMX is usable.

url:https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5e377d21f1f345d8b157b9bc306e02bb9bd45e01
This commit is contained in:
Haochen Jiang 2022-11-09 15:13:09 +08:00 committed by Hu, Lin1
parent 96e2f15137
commit 7954b2133e
2 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,77 @@
From 5e377d21f1f345d8b157b9bc306e02bb9bd45e01 Mon Sep 17 00:00:00 2001
From: Haochen Jiang <haochen.jiang@intel.com>
Date: Thu, 16 Jun 2022 00:15:53 -0700
Subject: [PATCH] i386: Add syscall to enable AMX for latest kernels
gcc/testsuite/ChangeLog:
* gcc.target/i386/amx-check.h (request_perm_xtile_data):
New function to check if AMX is usable and enable AMX.
(main): Run test if AMX is usable.
---
gcc/testsuite/gcc.target/i386/amx-check.h | 30 +++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/gcc/testsuite/gcc.target/i386/amx-check.h b/gcc/testsuite/gcc.target/i386/amx-check.h
index 434b0e59703..6fff5ff4631 100644
--- a/gcc/testsuite/gcc.target/i386/amx-check.h
+++ b/gcc/testsuite/gcc.target/i386/amx-check.h
@@ -4,11 +4,24 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
+#include <unistd.h>
+#ifdef __linux__
+#include <sys/syscall.h>
+#endif
#ifdef DEBUG
#include <stdio.h>
#endif
#include "cpuid.h"
+#define XFEATURE_XTILECFG 17
+#define XFEATURE_XTILEDATA 18
+#define XFEATURE_MASK_XTILECFG (1 << XFEATURE_XTILECFG)
+#define XFEATURE_MASK_XTILEDATA (1 << XFEATURE_XTILEDATA)
+#define XFEATURE_MASK_XTILE (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)
+
+#define ARCH_GET_XCOMP_PERM 0x1022
+#define ARCH_REQ_XCOMP_PERM 0x1023
+
/* TODO: The tmm emulation is temporary for current
AMX implementation with no tmm regclass, should
be changed in the future. */
@@ -44,6 +57,20 @@ typedef struct __tile
/* Stride (colum width in byte) used for tileload/store */
#define _STRIDE 64
+#ifdef __linux__
+/* We need syscall to use amx functions */
+int request_perm_xtile_data()
+{
+ unsigned long bitmask;
+
+ if (syscall (SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA) ||
+ syscall (SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask))
+ return 0;
+
+ return (bitmask & XFEATURE_MASK_XTILE) != 0;
+}
+#endif
+
/* Initialize tile config by setting all tmm size to 16x64 */
void init_tile_config (__tilecfg_u *dst)
{
@@ -185,6 +212,9 @@ main ()
#endif
#ifdef AMX_BF16
&& __builtin_cpu_supports ("amx-bf16")
+#endif
+#ifdef __linux__
+ && request_perm_xtile_data ()
#endif
)
{
--
2.18.2

View File

@ -84,7 +84,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: %{?scl_prefix}gcc
Version: 12.2.1
Release: 5
Release: 6
# libgcc, libgfortran, libgomp, libstdc++ and crtstuff have
# GCC Runtime Exception.
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
@ -133,6 +133,7 @@ Provides: %{?scl_prefix}gcc(major) = %{gcc_major}
Patch0: 0001-change-gcc-version.patch
Patch1: 0002-i386-Add-syscall-to-enable-AMX-for-latest-kernels.patch
# On ARM EABI systems, we do want -gnueabi to be part of the
@ -591,6 +592,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%setup -q -n gcc-12.2.0
%patch0 -p1
%patch1 -p1
echo 'openEuler %{version}-%{release}' > gcc/DEV-PHASE
@ -2647,6 +2649,9 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Wed Nov 09 2022 Haochen Jiang <haochen.jiang@intel.com> 12.2.1-6
- i386: Add syscall to enable AMX for latest kernels
* Wed Nov 02 2022 liyancheng <412998149@qq.com> 12.2.1-5
- Change isl dependency from Source to BuildRequire