Wednesday, February 21, 2024

Re: -current Haskell ports aborting with SIGILL

Stuart Henderson <stu@spacehopper.org> writes:

> On 2024/02/18 16:56, Evan Silberman wrote:
>> Something like this? I'm out of my depth and heavily pattern-matching
>> against the fix to simdutf and other references. Genuinely no idea if
>> I'm using inline asm correctly, etc. Works on my machine, however.
>
> That seems right to me. I don't have an AVX512 machine handy though.
> Here's a combined diff. (No idea what happened with the distinfo that's
> in tree but let's normalise it while there).
>
> The simdutf update is merged (https://github.com/haskell/text/pull/564),
> so we probably want to try a PR for your diff against
> https://github.com/haskell/text/blob/master/cbits/measure_off.c
> if everyone's here is happy with it.

Thanks Evan & Stuart for resolving this. I'm running `make test` on my
end, but I imagine it will work fine. So, OK gnezdo@.

Evan, if you have abundant time, could you try to run `make test` with
and without the patches? `make clean` in the middle is probably the
easiest way to ensure the patches get applied as expected.



>
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/lang/ghc/Makefile,v
> retrieving revision 1.220
> diff -u -p -r1.220 Makefile
> --- Makefile 5 Feb 2024 01:49:50 -0000 1.220
> +++ Makefile 21 Feb 2024 12:35:13 -0000
> @@ -14,6 +14,7 @@ USE_NOEXECONLY = Yes
> USE_NOBTCFI = Yes
>
> GHC_VERSION = 9.6.4
> +REVISION = 0
> DISTNAME = ghc-${GHC_VERSION}
> CATEGORIES = lang devel
> HOMEPAGE = https://www.haskell.org/ghc/
> Index: distinfo
> ===================================================================
> RCS file: /cvs/ports/lang/ghc/distinfo,v
> retrieving revision 1.73
> diff -u -p -r1.73 distinfo
> --- distinfo 5 Feb 2024 01:49:28 -0000 1.73
> +++ distinfo 21 Feb 2024 12:35:13 -0000
> @@ -1,10 +1,10 @@
> -SHA256 (ghc/ghc-9.6.4.20240111-amd64.tar.xz) = CedJ29vBFZyl1e+DgcUqPfjHMDRKmEOsXP9gH4Wka6E=
> -SHA256 (ghc/ghc-9.6.4.20240111-shlibs-amd64.tar.gz) = Nb3trqnIF8H5kfKEkeGLr+sl4rPeFsbW/gfkelRprrY=
> SHA256 (ghc/ghc-9.6.4-src.tar.xz) = EL8luLBxdP3ZhotcDFbBfA7x7ctiR7S4ZL6TNlG/1MA=
> SHA256 (ghc/ghc-9.6.4-testsuite.tar.xz) = bhMoL76//b+gpJiJQ3REyakM/ldgxHlpzUJFhUwzjXM=
> +SHA256 (ghc/ghc-9.6.4.20240111-amd64.tar.xz) = CedJ29vBFZyl1e+DgcUqPfjHMDRKmEOsXP9gH4Wka6E=
> +SHA256 (ghc/ghc-9.6.4.20240111-shlibs-amd64.tar.gz) = Nb3trqnIF8H5kfKEkeGLr+sl4rPeFsbW/gfkelRprrY=
> SHA256 (ghc/hadrian-sources-9.6.4.20240111.tar.gz) = wMMJfyP7Pr6xjb/tj9Kz5iZugGr6+duMwJ23aGsUWy0=
> SIZE (ghc/ghc-9.6.4-src.tar.xz) = 29451856
> SIZE (ghc/ghc-9.6.4-testsuite.tar.xz) = 7075820
> SIZE (ghc/ghc-9.6.4.20240111-amd64.tar.xz) = 74706384
> SIZE (ghc/ghc-9.6.4.20240111-shlibs-amd64.tar.gz) = 3544885
> -SIZE (ghc/hadrian-sources-9.6.4.20240111.tar.gz) = 2125322
> \ No newline at end of file
> +SIZE (ghc/hadrian-sources-9.6.4.20240111.tar.gz) = 2125322
> Index: patches/patch-libraries_text_cbits_measure_off_c
> ===================================================================
> RCS file: patches/patch-libraries_text_cbits_measure_off_c
> diff -N patches/patch-libraries_text_cbits_measure_off_c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-libraries_text_cbits_measure_off_c 21 Feb 2024 12:35:13 -0000
> @@ -0,0 +1,23 @@
> +Don't attempt to use avx512 kernels when the OS doesn't support them
> +
> +Index: libraries/text/cbits/measure_off.c
> +--- libraries/text/cbits/measure_off.c.orig
> ++++ libraries/text/cbits/measure_off.c
> +@@ -44,12 +44,16 @@
> + bool has_avx512_vl_bw() {
> + #if (__GNUC__ >= 7 || __GNUC__ == 6 && __GNUC_MINOR__ >= 3) || defined(__clang_major__)
> + uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
> ++ uint64_t xcr0;
> + __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
> + // https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features
> ++ // __asm__("xgetbv\n\t" : "=a" (xcr0) : "c" (0));
> + const bool has_avx512_bw = ebx & (1 << 30);
> + const bool has_avx512_vl = ebx & (1 << 31);
> ++ // XCR0 bits 5, 6, and 7
> ++ const bool avx512_os_enabled = (xcr0 & 0xE0) == 0xE0;
> + // printf("cpuid=%d=cpuid\n", has_avx512_bw && has_avx512_vl);
> +- return has_avx512_bw && has_avx512_vl;
> ++ return has_avx512_bw && has_avx512_vl && avx512_os_enabled;
> + #else
> + return false;
> +

No comments:

Post a Comment