dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.27k stars 5.9k forks source link

Docs on SIMD platform support are incorrect #23041

Open filipnavara opened 3 years ago

filipnavara commented 3 years ago

Issue description

The docs about SIMD support (https://github.com/dotnet/docs/blob/master/docs/standard/simd.md) state the following:

The SIMD-accelerated types are implemented in such a way that they can be used with non-SIMD-accelerated hardware or JIT compilers. To take advantage of SIMD instructions, your 64-bit apps must be run by the runtime that uses the RyuJIT compiler. A RyuJIT compiler is included in .NET Core and in .NET Framework 4.6 and later. SIMD support is only provided when targeting 64-bit processors.

The information is out of date. As of .NET Core 2.0 all backend code generators were migrated to RyuJIT backend (https://devblogs.microsoft.com/dotnet/the-ryujit-transition-is-complete/). The SIMD types are supported on all platforms targeted by RyuJIT, including 32-bit x86 and ARM.

Additionally, the SIMD types are also supported on Mono, and in MonoVM in .NET 6. This is independent implementation not related to RyuJIT. The support matrix for Mono and Xamarin based products is non-trivial though.

I'd suggest to update the docs to state the hardware accelerated SIMD support is available on all platforms where System.Numerics.Vector.IsHardwareAccelerated returns true. This will return true for all supported .NET 5+ and .NET Core versions. .NET Framework is an exception which may require a more specific mention.

Target framework


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

adegeo commented 3 years ago

Thank you for opening this issue. I'll add it to the backlog. If you would like to contribute, you can submit a fix by editing the original article. Click on the Content Source link at the bottom of your original comment. To learn how to edit, see the Editing files in a repository article from GitHub.

Thanks again!

Ping @tannergooding

tannergooding commented 3 years ago

The SIMD types are supported on all platforms targeted by RyuJIT, including 32-bit x86 and ARM.

We do not support SIMD codegen on 32-bit ARM and you will get the software fallbacks or a PlatformNotSupportedException (depending on whether the API is meant for general use or hardware specific use). I believe we are also more limited in some aspects on 32-bit x86 Unix.

I'd suggest to update the docs to state the hardware accelerated SIMD support is available on all platforms where System.Numerics.Vector.IsHardwareAccelerated returns true. This will return true for all supported .NET 5+ and .NET Core versions. .NET Framework is an exception which may require a more specific mention.

I agree the doc could use rewording and could likely also give a reference to the newer hardware intrinsics feature (System.Runtime.Intrinsics.*).

filipnavara commented 3 years ago

We do not support SIMD codegen on 32-bit ARM

Ah, I stand corrected. I only checked part of the source code and missed the condition in CMake for FEATURE_SIMD.

I believe we are also more limited in some aspects on 32-bit x86 Unix.

The same CMake condition excludes x86 Unix completely:

  if ((TARGETDETAILS_ARCH STREQUAL "x64") OR (TARGETDETAILS_ARCH STREQUAL "arm64") OR ((TARGETDETAILS_ARCH STREQUAL "x86") AND NOT (TARGETDETAILS_OS STREQUAL "unix")))
    target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE FEATURE_SIMD)
    target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE FEATURE_HW_INTRINSICS)
  endif ()

My main concern was that it implied that the types would not be optimized on x86 at all. That was not true for quite some time. I am not sure how to reword it, preferably in a way that would not need to be edited again due to additional platforms (WASM) or VMs (MonoVM in .NET 6).

tannergooding commented 3 years ago

I think your suggestion on checking and depending on IsHardwareAccelerated is sufficient here. If that API returns true, then at least some of the methods are accelerated on the given platform (even on x64, there are a few overloads that can't be accelerated, but those may differ from those that can't be on say ARM64). If it returns false, then no APIs are hardware accelerated.