public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Haochen Jiang <jianghc@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8781] i386: Add syscall to enable AMX for latest kernels Date: Thu, 22 Sep 2022 06:50:22 +0000 (GMT) [thread overview] Message-ID: <20220922065022.E5E443858028@sourceware.org> (raw) https://gcc.gnu.org/g:dc4cf9fe202b9813cf2a68aeff7cc00cf882aa7d commit r12-8781-gdc4cf9fe202b9813cf2a68aeff7cc00cf882aa7d Author: Haochen Jiang <haochen.jiang@intel.com> Date: Thu Jun 16 00:15:53 2022 -0700 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. Diff: --- 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 ) {
reply other threads:[~2022-09-22 6:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220922065022.E5E443858028@sourceware.org \ --to=jianghc@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).