public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add avx2 fake-capability, like tls
@ 2017-01-03 19:53 Victor Rodriguez
  2017-01-11  0:56 ` Victor Rodriguez
  2017-03-17  3:39 ` Mike Frysinger
  0 siblings, 2 replies; 5+ messages in thread
From: Victor Rodriguez @ 2017-01-03 19:53 UTC (permalink / raw)
  To: libc-alpha; +Cc: Victor Rodriguez

The idea of the patch is to provide AVX2 capability to glibc, original
patch from: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>.
It has been proved that the use of AVX2 improves the performance of current
numerical applications. With this patch the Linux distributions will be able to
handle AVX2 in glibc

Signed-off-by: Victor Rodriguez <victor.rodriguez.bahena@intel.com>
---
 ChangeLog       |  6 ++++++
 elf/dl-cache.c  |  6 +++++-
 elf/dl-hwcaps.c | 17 +++++++++++++++++
 elf/ldconfig.c  |  1 +
 4 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index bbda2a7f2c..8a24afa918 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-30  Victor Rodriguez  <victor.rodriguez.bahena@intel.com>
+
+	* elf/dl-cache: Define AVX platform
+	* elf/dl-hwcaps.c : Adding avx2 cap support
+	* elf/ldconfig.c : Add avx2 to hwcap_extra
+
 2016-12-31  Joseph Myers  <joseph@codesourcery.com>
 
 	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index cfa335eb32..ae5047046d 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -259,8 +259,9 @@ _dl_load_cache_lookup (const char *name)
 	platform = 1ULL << platform;
 
 #define _DL_HWCAP_TLS_MASK (1LL << 63)
+#define _DL_HWCAP_AVX2_MASK (1LL << 62)
       uint64_t hwcap_exclude = ~((GLRO(dl_hwcap) & GLRO(dl_hwcap_mask))
-				 | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK);
+				 | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK | _DL_HWCAP_AVX2_MASK);
 
       /* Only accept hwcap if it's for the right platform.  */
 #define HWCAP_CHECK \
@@ -271,6 +272,9 @@ _dl_load_cache_lookup (const char *name)
       if (_DL_PLATFORMS_COUNT						      \
 	  && (lib->hwcap & _DL_HWCAP_PLATFORM) != 0			      \
 	  && (lib->hwcap & _DL_HWCAP_PLATFORM) != platform)		      \
+	continue; \
+      if (!HAS_ARCH_FEATURE (AVX2_Usable) &&			\
+	    (lib->hwcap & _DL_HWCAP_AVX2_MASK)) \
 	continue
       SEARCH_CACHE (cache_new);
     }
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
index 6004ff264d..4e46b752e7 100644
--- a/elf/dl-hwcaps.c
+++ b/elf/dl-hwcaps.c
@@ -111,6 +111,9 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
   /* For TLS enabled builds always add 'tls'.  */
   ++cnt;
 
+  /* Add 'avx2' capability on x86_64 */
+  ++cnt;
+
   /* Create temporary data structure to generate result table.  */
   struct r_strlenpair temp[cnt];
   m = 0;
@@ -163,6 +166,20 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
   temp[m].len = 3;
   ++m;
 
+  if (HAS_ARCH_FEATURE (AVX2_Usable))
+    {
+      if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
+	_dl_debug_printf ("  adding avx2 cap support\n");
+      temp[m].str = "avx2";
+      temp[m].len = 4;
+      ++m;
+    }
+  else {
+    if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
+      _dl_debug_printf ("  not adding avx2 cap support\n");
+    --cnt;
+  }
+
   assert (m == cnt);
 
   /* Determine the total size of all strings together.  */
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 467ca8266a..ee2121786c 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -1298,6 +1298,7 @@ main (int argc, char **argv)
      under which TLS support was optional.  The entry is no longer needed, but
      must remain for compatibility.  */
   hwcap_extra[63 - _DL_FIRST_EXTRA] = "tls";
+  hwcap_extra[62 - _DL_FIRST_EXTRA] = "avx2";
 
   set_hwcap ();
 
-- 
2.11.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add avx2 fake-capability, like tls
  2017-01-03 19:53 [PATCH] Add avx2 fake-capability, like tls Victor Rodriguez
@ 2017-01-11  0:56 ` Victor Rodriguez
  2017-03-17  3:39 ` Mike Frysinger
  1 sibling, 0 replies; 5+ messages in thread
From: Victor Rodriguez @ 2017-01-11  0:56 UTC (permalink / raw)
  To: Victor Rodriguez; +Cc: libc-alpha

On Tue, Jan 3, 2017 at 1:53 PM, Victor Rodriguez
<victor.rodriguez.bahena@intel.com> wrote:
> The idea of the patch is to provide AVX2 capability to glibc, original
> patch from: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>.
> It has been proved that the use of AVX2 improves the performance of current
> numerical applications. With this patch the Linux distributions will be able to
> handle AVX2 in glibc
>
> Signed-off-by: Victor Rodriguez <victor.rodriguez.bahena@intel.com>
> ---
>  ChangeLog       |  6 ++++++
>  elf/dl-cache.c  |  6 +++++-
>  elf/dl-hwcaps.c | 17 +++++++++++++++++
>  elf/ldconfig.c  |  1 +
>  4 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index bbda2a7f2c..8a24afa918 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2016-12-30  Victor Rodriguez  <victor.rodriguez.bahena@intel.com>
> +
> +       * elf/dl-cache: Define AVX platform
> +       * elf/dl-hwcaps.c : Adding avx2 cap support
> +       * elf/ldconfig.c : Add avx2 to hwcap_extra
> +
>  2016-12-31  Joseph Myers  <joseph@codesourcery.com>
>
>         * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
> diff --git a/elf/dl-cache.c b/elf/dl-cache.c
> index cfa335eb32..ae5047046d 100644
> --- a/elf/dl-cache.c
> +++ b/elf/dl-cache.c
> @@ -259,8 +259,9 @@ _dl_load_cache_lookup (const char *name)
>         platform = 1ULL << platform;
>
>  #define _DL_HWCAP_TLS_MASK (1LL << 63)
> +#define _DL_HWCAP_AVX2_MASK (1LL << 62)
>        uint64_t hwcap_exclude = ~((GLRO(dl_hwcap) & GLRO(dl_hwcap_mask))
> -                                | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK);
> +                                | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK | _DL_HWCAP_AVX2_MASK);
>
>        /* Only accept hwcap if it's for the right platform.  */
>  #define HWCAP_CHECK \
> @@ -271,6 +272,9 @@ _dl_load_cache_lookup (const char *name)
>        if (_DL_PLATFORMS_COUNT                                                \
>           && (lib->hwcap & _DL_HWCAP_PLATFORM) != 0                           \
>           && (lib->hwcap & _DL_HWCAP_PLATFORM) != platform)                   \
> +       continue; \
> +      if (!HAS_ARCH_FEATURE (AVX2_Usable) &&                   \
> +           (lib->hwcap & _DL_HWCAP_AVX2_MASK)) \
>         continue
>        SEARCH_CACHE (cache_new);
>      }
> diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
> index 6004ff264d..4e46b752e7 100644
> --- a/elf/dl-hwcaps.c
> +++ b/elf/dl-hwcaps.c
> @@ -111,6 +111,9 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
>    /* For TLS enabled builds always add 'tls'.  */
>    ++cnt;
>
> +  /* Add 'avx2' capability on x86_64 */
> +  ++cnt;
> +
>    /* Create temporary data structure to generate result table.  */
>    struct r_strlenpair temp[cnt];
>    m = 0;
> @@ -163,6 +166,20 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
>    temp[m].len = 3;
>    ++m;
>
> +  if (HAS_ARCH_FEATURE (AVX2_Usable))
> +    {
> +      if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
> +       _dl_debug_printf ("  adding avx2 cap support\n");
> +      temp[m].str = "avx2";
> +      temp[m].len = 4;
> +      ++m;
> +    }
> +  else {
> +    if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
> +      _dl_debug_printf ("  not adding avx2 cap support\n");
> +    --cnt;
> +  }
> +
>    assert (m == cnt);
>
>    /* Determine the total size of all strings together.  */
> diff --git a/elf/ldconfig.c b/elf/ldconfig.c
> index 467ca8266a..ee2121786c 100644
> --- a/elf/ldconfig.c
> +++ b/elf/ldconfig.c
> @@ -1298,6 +1298,7 @@ main (int argc, char **argv)
>       under which TLS support was optional.  The entry is no longer needed, but
>       must remain for compatibility.  */
>    hwcap_extra[63 - _DL_FIRST_EXTRA] = "tls";
> +  hwcap_extra[62 - _DL_FIRST_EXTRA] = "avx2";
>
>    set_hwcap ();
>
> --
> 2.11.0
>

Hi team

Is there any feedback from this ?

Regards

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add avx2 fake-capability, like tls
  2017-01-03 19:53 [PATCH] Add avx2 fake-capability, like tls Victor Rodriguez
  2017-01-11  0:56 ` Victor Rodriguez
@ 2017-03-17  3:39 ` Mike Frysinger
  2017-03-17 19:18   ` Rodriguez Bahena, Victor
  1 sibling, 1 reply; 5+ messages in thread
From: Mike Frysinger @ 2017-03-17  3:39 UTC (permalink / raw)
  To: Victor Rodriguez; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

On 03 Jan 2017 19:53, Victor Rodriguez wrote:
> The idea of the patch is to provide AVX2 capability to glibc, original
> patch from: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>.
> It has been proved that the use of AVX2 improves the performance of current
> numerical applications. With this patch the Linux distributions will be able to
> handle AVX2 in glibc

i don't think this description is accurate/relevant.  looks like you're
trying to add a new search path to ldconfig/ld.so.cache so that people
can build libs w/-mavx2 turned on and then put them under a path e.g.
/lib64/avx2/ ?

you can't add arch-specific functionality to common code like this.
this patch will break all non-x86 arches.

i think you want to actually be updating these files:
	sysdeps/i386/dl-procinfo.[ch]
	sysdeps/x86_64/dl-procinfo.[ch]
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add avx2 fake-capability, like tls
  2017-03-17  3:39 ` Mike Frysinger
@ 2017-03-17 19:18   ` Rodriguez Bahena, Victor
  2017-04-06 22:20     ` H.J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Rodriguez Bahena, Victor @ 2017-03-17 19:18 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: libc-alpha


On 3/16/17, 9:39 PM, "Mike Frysinger" <vapier@gentoo.org> wrote:

>On 03 Jan 2017 19:53, Victor Rodriguez wrote:
>> The idea of the patch is to provide AVX2 capability to glibc, original
>> patch from: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>.
>> It has been proved that the use of AVX2 improves the performance of
>>current
>> numerical applications. With this patch the Linux distributions will be
>>able to
>> handle AVX2 in glibc
>
>i don't think this description is accurate/relevant.  looks like you're
>trying to add a new search path to ldconfig/ld.so.cache so that people
>can build libs w/-mavx2 turned on and then put them under a path e.g.
>/lib64/avx2/ ?
>
>you can't add arch-specific functionality to common code like this.
>this patch will break all non-x86 arches.
>
>i think you want to actually be updating these files:
>	sysdeps/i386/dl-procinfo.[ch]
>	sysdeps/x86_64/dl-procinfo.[ch]
>-mike

Thanks for the feedback , working on V2

>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add avx2 fake-capability, like tls
  2017-03-17 19:18   ` Rodriguez Bahena, Victor
@ 2017-04-06 22:20     ` H.J. Lu
  0 siblings, 0 replies; 5+ messages in thread
From: H.J. Lu @ 2017-04-06 22:20 UTC (permalink / raw)
  To: Rodriguez Bahena, Victor; +Cc: Mike Frysinger, libc-alpha

On Fri, Mar 17, 2017 at 12:18 PM, Rodriguez Bahena, Victor
<victor.rodriguez.bahena@intel.com> wrote:
>
> On 3/16/17, 9:39 PM, "Mike Frysinger" <vapier@gentoo.org> wrote:
>
>>On 03 Jan 2017 19:53, Victor Rodriguez wrote:
>>> The idea of the patch is to provide AVX2 capability to glibc, original
>>> patch from: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>.
>>> It has been proved that the use of AVX2 improves the performance of
>>>current
>>> numerical applications. With this patch the Linux distributions will be
>>>able to
>>> handle AVX2 in glibc
>>
>>i don't think this description is accurate/relevant.  looks like you're
>>trying to add a new search path to ldconfig/ld.so.cache so that people
>>can build libs w/-mavx2 turned on and then put them under a path e.g.
>>/lib64/avx2/ ?
>>
>>you can't add arch-specific functionality to common code like this.
>>this patch will break all non-x86 arches.
>>
>>i think you want to actually be updating these files:
>>       sysdeps/i386/dl-procinfo.[ch]
>>       sysdeps/x86_64/dl-procinfo.[ch]
>>-mike
>
> Thanks for the feedback , working on V2
>
>>

Please take a look at hjl/hwcap/master branch at:

https://sourceware.org/git/?p=glibc.git;a=summary

It sets dl_hwcap from CPU features.

-- 
H.J.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-06 22:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-03 19:53 [PATCH] Add avx2 fake-capability, like tls Victor Rodriguez
2017-01-11  0:56 ` Victor Rodriguez
2017-03-17  3:39 ` Mike Frysinger
2017-03-17 19:18   ` Rodriguez Bahena, Victor
2017-04-06 22:20     ` H.J. Lu

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).