Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HardwareIntrinsics AVX-512 info #2412

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet</AssemblyTitle>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
adamsitnik marked this conversation as resolved.
Show resolved Hide resolved
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;CS3001;CS3003</NoWarn>
<AssemblyName>BenchmarkDotNet</AssemblyName>
Expand Down
45 changes: 44 additions & 1 deletion src/BenchmarkDotNet/Portability/Cpu/HardwareIntrinsics.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using BenchmarkDotNet.Environments;
using System.Diagnostics.CodeAnalysis;
#if NET6_0_OR_GREATER
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics.Arm;
Expand All @@ -16,6 +16,8 @@ internal static class HardwareIntrinsics

internal static string GetShortInfo()
{
if (IsX86Avx512FSupported)
return "AVX-512";
if (IsX86Avx2Supported)
return "AVX2";
else if (IsX86AvxSupported)
Expand Down Expand Up @@ -52,6 +54,12 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
{
case Platform.X86:
case Platform.X64:
if (IsX86Avx512FSupported) yield return "AVX-512F";
if (IsX86Avx512BWSupported) yield return "AVX-512BW";
if (IsX86Avx512CDSupported) yield return "AVX-512CD";
if (IsX86Avx512DQSupported) yield return "AVX-512DQ";
if (IsX86Avx512VbmiSupported) yield return "AVX-512VBMI";

Copy link
Member

@tannergooding tannergooding Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other main path is an if/else if pattern.

This new code will yield/return several AVX-512F ISAs and not in their reverse hierarchical order. -- It is also missing the AVX512VL ISA, which is nested under the respective classes (its one flag shared across all, but dependent on the containing class also being supported).

Is that intentional?


I'd imagine we want to cover Avx512F in the main if/else chain and the others to be on top to be "inline" with how the other works.

Notably certain combinations also have well-defined names and it may be "better" to list the well-known name to avoid a list that is 20 ISAs long.

That is, x86-64-v4 is the formal definition that includes AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL

x86-64-v3 is AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT, MOVBE, OSXSAVE

x86-64-v2 is CMPXCHG16B, POPCNT, SSE3, SSE4.1, SSE4.2, SSSE3

x86-64-v1 (baseline) is CMOV, CX8, x87FPU, FXSR, MMX, OSFXSR, SCE, SSE, SSE2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably argue against using x86-x64-v? since it not immediately obvious what's what.

Instead perhaps we could list it as AVX-512(X/Y/Z) e.g. AVX-512(F/BW/CD/DQ/VL). This makes set obvious and immediately visible.

if (IsX86Avx2Supported) yield return "AVX2";
else if (IsX86AvxSupported) yield return "AVX";
else if (IsX86Sse42Supported) yield return "SSE4.2";
Expand Down Expand Up @@ -153,6 +161,41 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)
GetIsSupported("System.Runtime.Intrinsics.X86.Avx2");
#endif

internal static bool IsX86Avx512FSupported =>
adamsitnik marked this conversation as resolved.
Show resolved Hide resolved
#if NET8_0_OR_GREATER
Avx512F.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512F");
#endif

internal static bool IsX86Avx512BWSupported =>
#if NET8_0_OR_GREATER
Avx512BW.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512BW");
#endif

internal static bool IsX86Avx512CDSupported =>
#if NET8_0_OR_GREATER
Avx512CD.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512CD");
#endif

internal static bool IsX86Avx512DQSupported =>
#if NET8_0_OR_GREATER
Avx512DQ.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512DQ");
#endif

internal static bool IsX86Avx512VbmiSupported =>
#if NET8_0_OR_GREATER
Avx512Vbmi.IsSupported;
#else
GetIsSupported("System.Runtime.Intrinsics.X86.Avx512Vbmi");
#endif

internal static bool IsX86AesSupported =>
#if NET6_0_OR_GREATER
System.Runtime.Intrinsics.X86.Aes.IsSupported;
Expand Down
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Portability/Libc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace BenchmarkDotNet.Portability
{
#pragma warning disable CS8981 // The type name 'libc' only contains lower-cased ascii characters. Such names may become reserved for the language.
internal static class libc
#pragma warning restore CS8981
{
[DllImport(nameof(libc))]
internal static extern int getppid();
Expand Down
8 changes: 7 additions & 1 deletion src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ private string GetILCompilerPackageReference()

private string GetTrimmingSettings()
=> rootAllApplicationAssemblies
? "" // use the defaults
// Use the defaults
? ""
// TrimMode is set in explicit way as for older versions it might have different default value
: "<TrimMode>link</TrimMode><TrimmerDefaultAction>link</TrimmerDefaultAction>";

Expand Down Expand Up @@ -234,6 +235,11 @@ private static IEnumerable<string> GetCurrentProcessInstructionSets(Platform pla
if (HardwareIntrinsics.IsX86Sse42Supported) yield return "sse4.2";
if (HardwareIntrinsics.IsX86AvxSupported) yield return "avx";
if (HardwareIntrinsics.IsX86Avx2Supported) yield return "avx2";
if (HardwareIntrinsics.IsX86Avx512FSupported) yield return "avx-512f";
if (HardwareIntrinsics.IsX86Avx512BWSupported) yield return "avx-512bw";
if (HardwareIntrinsics.IsX86Avx512CDSupported) yield return "avx-512cd";
if (HardwareIntrinsics.IsX86Avx512DQSupported) yield return "avx-512dq";
if (HardwareIntrinsics.IsX86Avx512VbmiSupported) yield return "avx-512vbmi";
if (HardwareIntrinsics.IsX86AesSupported) yield return "aes";
if (HardwareIntrinsics.IsX86Bmi1Supported) yield return "bmi";
if (HardwareIntrinsics.IsX86Bmi2Supported) yield return "bmi2";
Expand Down
Loading