Can I use .NET SIMD on Raspberry Pi 4?

Ivan Koshelev

I'm writing code that will subtract corresponding bytes in two arrays and count the number of resulting bytes surpassing a given threshold. AFAIU, it would really benefit from .NET SIMD, but System.Numerics.Vector.IsHardwareAccelerated returns false when I compile C# on Raspberry Pi 4.

My dotnet version is 3.1.406, I've added

  <PropertyGroup>
    <Optimize>true</Optimize>
  </PropertyGroup>

to the csproj and running release configuration.

Is there any way I can leverage SIMD support in .NET on Raspberry Pi 4? Maybe with .NET 5?

Update I installed .NET 5 and tried .NET Intrinsics, but none is supported:

Console.WriteLine(System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Aes.IsSupported);  //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.ArmBase.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Crc32.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Dp.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Rdm.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha1.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha256.IsSupported); //false

I'm on 32-bit Raspbian (Debian derivative), is there any chance I need 64-bit version for this to work?

P.S. To clarify, in plain C# the algorhytm looks like this:

        public static int ScalarTest(byte[] lhs, byte[] rhs)
        {
            var result = 0;

            for (int index = 0; index < lhs.Length; index++)
            {
                var a = lhs[index];
                var b = rhs[index];
                if (b > a)
                {
                    (b, a) = (a, b);
                }
                result += ((a - b) >= 16) ? 1 : 0;
            }

            return result;
        }
Soonts

Despite the API is done and even documented, the implementation is missing. Take a look. 8-byte SIMD vectors is essential part of NEON ISA for decades now (was introduced in 2005), yet the .NET runtime only implements them when compiling for ARM64 (released in 2013).

I don’t work for Microsoft and have no idea how exactly they compile their binaries, but the source code tells they have at least some support for NEON when building for ARM64 target. If you want these intrinsics in .NET, you can try the 64-bit OS.

There’s a workaround — implement your performance-critical pieces in C++, compile a shared library for Linux, then use [DllImport] to consume these functions from .NET. I have built non-trivial Linux software that way (example), using the following gcc flags to build the DLLs: -march=native -mfpu=neon-fp16 -mfp16-format=ieee -ffast-math -O3 -fPIC This way it will work for 32-bit OS, and won’t require anything special from .NET runtime, I’ve tested with .NET Core 2.1.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can I use .NET SIMD on Raspberry Pi 4?

From Dev

Can I use Ubuntu One on the Raspberry Pi?

From Dev

Why can't I use python-mosquitto on the Raspberry Pi?

From Dev

Can you install Ubuntu on the Raspberry Pi 4

From Dev

Can I run matlab on raspberry pi?

From Dev

Raspberry Pi What can I do with it?

From Dev

Can I run mythbackend on Raspberry Pi?

From Dev

How can I compile scanbd on Raspberry Pi?

From Dev

How can I modify default page for UV4L streaming server at Raspberry Pi?

From Dev

How can I modify default page for UV4L streaming server at Raspberry Pi?

From Dev

Can I use the USB port of the raspberry pi (model B+) for serial communication (RS232)

From Dev

How can I use the google voice api on my raspberry pi running debian and chromium

From Dev

Can I use Google Translate to make my Raspberry Pi speak in different languages on demand?

From Dev

How can I use the google voice api on my raspberry pi running debian and chromium

From Dev

Can I use AUX port in Raspberry Pi 3 (Model B) to plug a microphone to get audio signals in?

From Dev

Can't install any applications on Raspberry Pi 4

From Dev

Can't connect with SSH to Ubuntu server (20.04) on raspberry pi 4

From Dev

How can I compile Rust code to run on a Raspberry Pi 2?

From Dev

Can I run a C# application on a Raspberry Pi?

From Dev

How can i get JavaFX working on raspberry pi 3

From Dev

Raspberry Pi: Can I turn on a monitor over HDMI?

From Dev

How can I install Ubuntu with APT (not Snappy) on the Raspberry Pi 2?

From Dev

How can I run lightdm on Xvfb on a Raspberry Pi?

From Dev

Can I automatically run a program in raspberry pi when it is turned on?

From Dev

can I use visual studio 2013 (run on windows 8.1 ) to Create raspberry pi 2 app (RPI2 Running Windows 10 )?

From Dev

can I use visual studio 2013 (run on windows 8.1 ) to Create raspberry pi 2 app (RPI2 Running Windows 10 )?

From Dev

Installing Steam on Raspberry Pi 4

From Dev

Raspberry Pi 4 updated bootloader

From Dev

Use raspberry pi to spoof dns

Related Related

  1. 1

    Can I use .NET SIMD on Raspberry Pi 4?

  2. 2

    Can I use Ubuntu One on the Raspberry Pi?

  3. 3

    Why can't I use python-mosquitto on the Raspberry Pi?

  4. 4

    Can you install Ubuntu on the Raspberry Pi 4

  5. 5

    Can I run matlab on raspberry pi?

  6. 6

    Raspberry Pi What can I do with it?

  7. 7

    Can I run mythbackend on Raspberry Pi?

  8. 8

    How can I compile scanbd on Raspberry Pi?

  9. 9

    How can I modify default page for UV4L streaming server at Raspberry Pi?

  10. 10

    How can I modify default page for UV4L streaming server at Raspberry Pi?

  11. 11

    Can I use the USB port of the raspberry pi (model B+) for serial communication (RS232)

  12. 12

    How can I use the google voice api on my raspberry pi running debian and chromium

  13. 13

    Can I use Google Translate to make my Raspberry Pi speak in different languages on demand?

  14. 14

    How can I use the google voice api on my raspberry pi running debian and chromium

  15. 15

    Can I use AUX port in Raspberry Pi 3 (Model B) to plug a microphone to get audio signals in?

  16. 16

    Can't install any applications on Raspberry Pi 4

  17. 17

    Can't connect with SSH to Ubuntu server (20.04) on raspberry pi 4

  18. 18

    How can I compile Rust code to run on a Raspberry Pi 2?

  19. 19

    Can I run a C# application on a Raspberry Pi?

  20. 20

    How can i get JavaFX working on raspberry pi 3

  21. 21

    Raspberry Pi: Can I turn on a monitor over HDMI?

  22. 22

    How can I install Ubuntu with APT (not Snappy) on the Raspberry Pi 2?

  23. 23

    How can I run lightdm on Xvfb on a Raspberry Pi?

  24. 24

    Can I automatically run a program in raspberry pi when it is turned on?

  25. 25

    can I use visual studio 2013 (run on windows 8.1 ) to Create raspberry pi 2 app (RPI2 Running Windows 10 )?

  26. 26

    can I use visual studio 2013 (run on windows 8.1 ) to Create raspberry pi 2 app (RPI2 Running Windows 10 )?

  27. 27

    Installing Steam on Raspberry Pi 4

  28. 28

    Raspberry Pi 4 updated bootloader

  29. 29

    Use raspberry pi to spoof dns

HotTag

Archive