Skip to content

Avx2.IsSupported not reflecting Avx2.Permute4x64 support on MacOS (GitHub Actions build with macos-latest) #43812

Description

@stefanrbk

Description

I am working on a double implementation of some matrix structs which use SIMD like the built in float matrix structs. It uses Avx2.Permute4x64 to move some values around in the Vector256 similar to how Matrix4x4 uses Sse.Shuffle in the matrix * matrix operator function. When I build my project on Github Actions with MacOS my tests fail as Avx2.Permute4x64 is not supported when it tries running in the test.

            if (Avx2.IsSupported)
            {
                var vector = Avx.LoadVector256(&left.M11);
                Avx.Store(&result.M11, Avx.Add(Avx.Add(Avx.Multiply(Avx2.Permute4x64(vector, 0),
                                                                    Avx.LoadVector256(&right.M11)),
                                                       Avx.Multiply(Avx2.Permute4x64(vector, 85),
                                                                    Avx.LoadVector256(&right.M21))),
                                               Avx.Multiply(Avx2.Permute4x64(vector, 170),
                                                            Avx.LoadVector256(&right.M31))));
                vector = Avx.LoadVector256(&left.M21);
                Avx.Store(&result.M21, Avx.Add(Avx.Add(Avx.Multiply(Avx2.Permute4x64(vector, 0),
                                                                    Avx.LoadVector256(&right.M11)),
                                                       Avx.Multiply(Avx2.Permute4x64(vector, 85),
                                                                    Avx.LoadVector256(&right.M21))),
                                               Avx.Multiply(Avx2.Permute4x64(vector, 170),
                                                            Avx.LoadVector256(&right.M31))));
                vector = Avx.LoadVector256(&left.M31);
                Avx.Store(&result.M31, Avx.Add(Avx.Add(Avx.Multiply(Avx2.Permute4x64(vector, 0),
                                                                    Avx.LoadVector256(&right.M11)),
                                                       Avx.Multiply(Avx2.Permute4x64(vector, 85),
                                                                    Avx.LoadVector256(&right.M21))),
                                               Avx.Multiply(Avx2.Permute4x64(vector, 170),
                                                            Avx.LoadVector256(&right.M31))));
            }

I test if Avx2 is supported or not and I would expect a false return for Avx2.IsSupported if any of the Avx2 intrinsics can fail.

Configuration

I'm building with .net 5.0.100-rc.2.20479.15 with GitHub Actions using
os: [ubuntu-latest, windows-latest, macos-latest]
macos-latest is which is throwing.

Regression?

I don't know currently. I will keep trying new .net versions as they come out.

Other information

Output from the build logs:

  Failed IdentityMultiplyTest [46 ms]
  Error Message:
   System.PlatformNotSupportedException : Operation is not supported on this platform.
  Stack Trace:
     at System.Runtime.Intrinsics.X86.Avx2.Permute4x64(Vector256`1 value, Byte control)
   at MathStructs.Matrix3x3D.op_Multiply(Matrix3x3D left, Matrix3x3D right) in /Users/runner/work/MathStructs/MathStructs/MathStructs/MathStructs/Matrix3x3D.cs:line 181
   at Tests.MathTesting.IdentityMultiplyTest() in /Users/runner/work/MathStructs/MathStructs/MathStructs/Tests/MathTesting.cs:line 66

Since I'm only reasonably competent with just c#. I wouldn't even know where to look back in the compiler or CLR to find the issue. Avx2.cs and Avx2.PlatformNotSupported.cs are not where the actual intrinsics magic happens and I don't know where to look from there.

Activity

  1. changed the title [-]Avx2.IsSupported not reflecting Avx2.Permute4x64 support.[/-] [+]Avx2.IsSupported not reflecting Avx2.Permute4x64 support on MacOS (GitHub Actions build with macos-latest)[/+] on Oct 25, 2020
  2. MichalStrehovsky commented on Oct 26, 2020

    @MichalStrehovsky
    Member

    Can you make sure you're really running RC2 on the Mac? You'll often get an old mac without AVX2 support because it's expensive hardware and build labs use it until it dies.

    This looks a lot like #42912 that was a mystery issue caused by the "is AVX supported?" check actually checking "is multithreading supported?". It was fixed in RC2.

  3. MichalStrehovsky commented on Oct 26, 2020

    @MichalStrehovsky
    Member
  4. tannergooding commented on Oct 26, 2020

    @tannergooding
    Member

    This looks a lot like #42912 that was a mystery issue caused by the "is AVX supported?" check actually checking "is multithreading supported?". It was fixed in RC2.

    That would be my guess as well.

  5. tannergooding commented on Oct 26, 2020

    @tannergooding
    Member

    Marked this as a bug until we can get confirmation or a repro showing it is a dupe of #42912

  6. stefanrbk commented on Oct 28, 2020

    @stefanrbk
    Author

    Yes, the logs show rc2. I was dumb and deleted the GitHub Action reports with the failing MacOS records after I removed Avx2 from my code, but you can see the versioning in another build action here

  7. stefanrbk commented on Oct 28, 2020

    @stefanrbk
    Author

    I'm not sure if it was a versioning issue, but I reverted my previous change to remove all Avx2 code and everything builds and passes all tests. I have a test in my project now consisting of

    [Test]
    public void Avx2IsSupportedTest()
    {
        Assert.That(Avx2.IsSupported, Is.EqualTo((X86Base.CpuId(7, 0).Ebx & (1 << 5)) != 0));
    }

    to try to catch the issue if it ever arises again!

  8. MichalStrehovsky commented on Oct 28, 2020

    @MichalStrehovsky
    Member

    I'm not sure if it was a versioning issue, but I reverted my previous change to remove all Avx2 code and everything builds and passes all tests

    Thanks for confirming! Looks like this can be closed then.

    to try to catch the issue if it ever arises again!

    Nit: That test will also fail when someone runs bcdedit.exe /set xsavedisable 1 on Windows and reboots (this disables OS level support for AVX). Checking for this is hard; that's why Avx2.IsSupported really needs to reliably work.

  9. stefanrbk commented on Oct 28, 2020

    @stefanrbk
    Author

    Thank you for the heads up @MichalStrehovsky. I'll put a note in the test code in case that test throws in the future. At least I'll know it passes if the test works on my windows machine!

  10. ghost locked as resolved and limited conversation to collaborators on Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions