Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add HardwareIntrinsics AVX-512 info
  • Loading branch information
nietras committed Aug 20, 2023
commit 18633be1c14cb4ae717351efff1040dd954acf55
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>
<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 =>
#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