Message ID | 20220610074704.7673-1-hongtao.liu@intel.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2945383EC65 for <patchwork@sourceware.org>; Fri, 10 Jun 2022 07:48:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2945383EC65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654847302; bh=QX86t9lJDWmwDyWRzImwBjvuWJGqEvc9zJQdixDWBrw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Zk5k+PZNpA8LTmJwk1Auu7dfmor7Rfb9WBnYrpPrP0DsAJGRivYit45nrx23xMv+2 MfgWJQE5DI4PsIu5KpX6Lomyvl+mP3P7Zky9wQfer/GpYJ+//kM00qkYPWJeuI+gVu x72rlZJrcMqafhSYvGfO8tE8XS4ukHFyJ1TYZIi0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by sourceware.org (Postfix) with ESMTPS id 69DEA383EC42 for <gcc-patches@gcc.gnu.org>; Fri, 10 Jun 2022 07:47:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69DEA383EC42 X-IronPort-AV: E=McAfee;i="6400,9594,10373"; a="278690018" X-IronPort-AV: E=Sophos;i="5.91,288,1647327600"; d="scan'208";a="278690018" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 00:47:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,288,1647327600"; d="scan'208";a="760406115" Received: from scymds01.sc.intel.com ([10.148.94.138]) by orsmga005.jf.intel.com with ESMTP; 10 Jun 2022 00:47:07 -0700 Received: from shliclel045.sh.intel.com (shliclel045.sh.intel.com [10.239.236.45]) by scymds01.sc.intel.com with ESMTP id 25A7l54W027885; Fri, 10 Jun 2022 00:47:05 -0700 To: x86-64-abi@googlegroups.com Subject: [PATCH] Add optional __Bfloat16 support Date: Fri, 10 Jun 2022 15:47:04 +0800 Message-Id: <20220610074704.7673-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: liuhongt via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: liuhongt <hongtao.liu@intel.com> Cc: llvm-dev@lists.llvm.org, libc-alpha@sourceware.org, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
Add optional __Bfloat16 support
|
|
Commit Message
Liu, Hongtao
June 10, 2022, 7:47 a.m. UTC
Pass and return __Bfloat16 values in XMM registers. Background: __Bfloat16 (BF16) is a new floating-point format that can accelerate machine learning (deep learning training, in particular) algorithms. It's first introduced by Intel AVX-512 extension called AVX-512_BF16. __Bfloat16 has 8 bits of exponent and 7 bits of mantissa and it's different from _Float16. Movivation: Currently __bfloat16 is a typedef of short, which creates a problem where the compiler does not raise any alarms if it is used to add, subtract, multiply or divide, but the result of the calculation is actually meaningless. To solve this problem, a real scalar type __Bfloat16 needs to be introduced. It is mainly used for intrinsics, not available for C standard operators. __Bfloat16 will also be used for movement like passing parameter, load and store, vector initialization, vector shuffle, and .etc. It creates a need for a corresponding psABI. --- x86-64-ABI/low-level-sys-info.tex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Comments
On Fri, Jun 10, 2022 at 3:47 PM liuhongt via Libc-alpha <libc-alpha@sourceware.org> wrote: > > Pass and return __Bfloat16 values in XMM registers. > > Background: > __Bfloat16 (BF16) is a new floating-point format that can accelerate machine learning (deep learning training, in particular) algorithms. > It's first introduced by Intel AVX-512 extension called AVX-512_BF16. __Bfloat16 has 8 bits of exponent and 7 bits of mantissa and it's different from _Float16. > > Movivation: > Currently __bfloat16 is a typedef of short, which creates a problem where the compiler does not raise any alarms if it is used to add, subtract, multiply or divide, but the result of the calculation is actually meaningless. > To solve this problem, a real scalar type __Bfloat16 needs to be introduced. It is mainly used for intrinsics, not available for C standard operators. __Bfloat16 will also be used for movement like passing parameter, load and store, vector initialization, vector shuffle, and .etc. It creates a need for a corresponding psABI. > > --- > x86-64-ABI/low-level-sys-info.tex | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/x86-64-ABI/low-level-sys-info.tex b/x86-64-ABI/low-level-sys-info.tex > index a8b69db..ba8db0d 100644 > --- a/x86-64-ABI/low-level-sys-info.tex > +++ b/x86-64-ABI/low-level-sys-info.tex > @@ -302,6 +302,12 @@ be used to represent the type, is a family of integer types. > This permits the use of these types in allocated arrays using the common > sizeof(Array)/sizeof(ElementType) pattern. > > +\subsubsection{Special Types} > + > +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. > +It is used for \code{BF16} related intrinsics, it cannot be > +used with standard C operators. > + > \subsubsection{Aggregates and Unions} > > Structures and unions assume the alignment of their most strictly > @@ -563,8 +569,8 @@ The basic types are assigned their natural classes: > \item Arguments of types (signed and unsigned) \code{_Bool}, \code{char}, > \code{short}, \code{int}, \code{long}, \code{long long}, and > pointers are in the INTEGER class. > -\item Arguments of types \code{_Float16}, \code{float}, \code{double}, > - \code{_Decimal32}, > +\item Arguments of types \code{_Float16}, \code{__Bfloat16}, \code{float}, > + \code{double}, \code{_Decimal32}, > \code{_Decimal64} and \code{__m64} are in class SSE. > \item Arguments of types \code{__float128}, \code{_Decimal128} > and \code{__m128} are split into two halves. The least significant > -- > 2.18.1 >
* liuhongt via Libc-alpha: > +\subsubsection{Special Types} > + > +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. > +It is used for \code{BF16} related intrinsics, it cannot be > +used with standard C operators. I think it's not necessary to specify whether the type supports certain C operators (surely assignment will work?). If they are added later, the ABI won't need changing. Thanks, Florian
On Fri, Jun 10, 2022 at 2:38 AM Florian Weimer <fweimer@redhat.com> wrote: > > * liuhongt via Libc-alpha: > > > +\subsubsection{Special Types} > > + > > +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. > > +It is used for \code{BF16} related intrinsics, it cannot be Please mention that this is an alternate encoding format for 16-bit floating point. It has the same size and alignment as _Float16. > > +used with standard C operators. > > I think it's not necessary to specify whether the type supports certain > C operators (surely assignment will work?). If they are added later, > the ABI won't need changing. > If _Bfloat16 becomes a fundamental type, the ABI should be changed to move it together with other scalar types.
On Fri, Jun 10, 2022 at 7:44 AM H.J. Lu <hjl.tools@gmail.com> wrote: > > On Fri, Jun 10, 2022 at 2:38 AM Florian Weimer <fweimer@redhat.com> wrote: > > > > * liuhongt via Libc-alpha: > > > > > +\subsubsection{Special Types} > > > + > > > +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. > > > +It is used for \code{BF16} related intrinsics, it cannot be > > Please mention that this is an alternate encoding format for 16-bit floating > point. It has the same size and alignment as _Float16. It also follows the same rules as _Float16 for parameter passing and function return. > > > +used with standard C operators. > > > > I think it's not necessary to specify whether the type supports certain > > C operators (surely assignment will work?). If they are added later, > > the ABI won't need changing. > > > > If _Bfloat16 becomes a fundamental type, the ABI should be changed to > move it together with other scalar types. > > -- > H.J.
On Sat, Jun 11, 2022 at 1:46 AM H.J. Lu <hjl.tools@gmail.com> wrote: > > On Fri, Jun 10, 2022 at 7:44 AM H.J. Lu <hjl.tools@gmail.com> wrote: > > > > On Fri, Jun 10, 2022 at 2:38 AM Florian Weimer <fweimer@redhat.com> wrote: > > > > > > * liuhongt via Libc-alpha: > > > > > > > +\subsubsection{Special Types} > > > > + > > > > +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. > > > > +It is used for \code{BF16} related intrinsics, it cannot be > > > > Please mention that this is an alternate encoding format for 16-bit floating > > point. It has the same size and alignment as _Float16. > > It also follows the same rules as _Float16 for parameter passing and function > return. How about +\subsubsection{Special Types} + +The \code{__Bfloat16} type has an alternate encoding format for 16-bit +floating point with 8-bit exponent and 7-bit mantissa. It has the same size, +alignment, parameter passing and return rules as _Float16. +It is used for \code{BF16} related intrinsics, it cannot be used with standard +C operators. + > > > > > +used with standard C operators. > > > > > > I think it's not necessary to specify whether the type supports certain > > > C operators (surely assignment will work?). If they are added later, > > > the ABI won't need changing. > > > > > > > If _Bfloat16 becomes a fundamental type, the ABI should be changed to > > move it together with other scalar types. > > > > -- > > H.J. > > > > -- > H.J. > > -- > You received this message because you are subscribed to the Google Groups "X86-64 System V Application Binary Interface" group. > To unsubscribe from this group and stop receiving emails from it, send an email to x86-64-abi+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/x86-64-abi/CAMe9rOrvrZRbksjQ%2BY8caC%3DYo%3D%3DoFY5%2BmuOGf9UZRh6L7pUQjw%40mail.gmail.com.
diff --git a/x86-64-ABI/low-level-sys-info.tex b/x86-64-ABI/low-level-sys-info.tex index a8b69db..ba8db0d 100644 --- a/x86-64-ABI/low-level-sys-info.tex +++ b/x86-64-ABI/low-level-sys-info.tex @@ -302,6 +302,12 @@ be used to represent the type, is a family of integer types. This permits the use of these types in allocated arrays using the common sizeof(Array)/sizeof(ElementType) pattern. +\subsubsection{Special Types} + +The \code{__Bfloat16} type uses a 8-bit exponent and 7-bit mantissa. +It is used for \code{BF16} related intrinsics, it cannot be +used with standard C operators. + \subsubsection{Aggregates and Unions} Structures and unions assume the alignment of their most strictly @@ -563,8 +569,8 @@ The basic types are assigned their natural classes: \item Arguments of types (signed and unsigned) \code{_Bool}, \code{char}, \code{short}, \code{int}, \code{long}, \code{long long}, and pointers are in the INTEGER class. -\item Arguments of types \code{_Float16}, \code{float}, \code{double}, - \code{_Decimal32}, +\item Arguments of types \code{_Float16}, \code{__Bfloat16}, \code{float}, + \code{double}, \code{_Decimal32}, \code{_Decimal64} and \code{__m64} are in class SSE. \item Arguments of types \code{__float128}, \code{_Decimal128} and \code{__m128} are split into two halves. The least significant