Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title ![CPUCapabilities.NET](etc/img/Logo.png)

Introduction

CPUCapabilities.NET provides detailed information about the underlying CPU to applications running on the Microsoft .NET Framework. It consists of two components: A tiny "unmanaged" helper library (written in C++), which performs the actual CPU detection, and a "managed" wrapper class (written in C#), which encapsulates the required P/Invoke calls.

The information provided by CPUCapabilities.NET include the CPU architecture, the number of (logical) CPU cores, the CPU "vendor" and "brand" strings, the CPU "model" and "family" IDs as well as the supported CPU capabilities (instruction set extensions), such as MMX, 3DNow!, SSE, SSE2, SSE3, SSSE3, SSE4.1/4.2, SSE4a, FMA3, FMA4, XOP, AVX, AVX2 or AVX-512.

The "unmanaged" library is provided as separate 32‑Bit (x86) and 64‑Bit (x64) DLL files, allowing it to work on both platforms; AnyCPU assemblies automatically use the appropriate DLL.

Background

To the best of my knowledge, the Microsoft .NET Framework does not provide a built-in way to acquire detailed information about the underlying CPU. The Environment class can be used to check wether we are running on a 64‑Bit operating system, which would imply that we are running on a 64‑Bit (x64) processor, but it does not provide any further information about the CPU. The Microsoft .NET Framework also provides APIs for consuming data and events from the WMI (Windows Management Instrumentation) infrastructure. Unfortunately, even though the the Win32_Processor WMI class can provide various information about the CPU, it does not reveal the supported CPU capabilities (i.e. instruction set extensions).

If using P/Invoke is an option, then we can query the Win32 API directly. The functions GetNativeSystemInfo() and especially IsProcessorFeaturePresent() look promising at a first glance, but it quickly becomes evident that these functions do not support "modern" CPU instruction set extensions, such as AVX, AVX2 or AVX-512. There also is the GetEnabledXStateFeatures() function, which may be used to detect whether AVX support is enabled on the operating system-level, which would imply that at least AVX is supported by the CPU. But, unfortunately, there is no way to detect whether AVX2 or AVX-512 are supported too. The Win32 API does not currently provide a way to detect AVX2 or AVX-512.

After all, using the CPUID instruction is the only reliable way to detect the supported CPU capabilities, including all the instruction set extensions that were are interested in. The XGETBV instruction is also required, in order to test whether AVX support is enabled on the operating system-level. However, since it is not possible to call these instructions directly from "managed" code in the Microsoft .NET Framework, it becomes necessary to use an "unmanaged" helper library for this purpose. This is exactly how the CPUCapabilities.NET library works!

Managed API

Information about the CPU are provided by the CPU class, which is located in the Muldersoft.CPUCapabilitiesDotNet namespace.

All information are provided by a set of read-only properties. The following properties are available:

License

This work has been released under the CC0 1.0 Universal license.

For details, please refer to:
https://creativecommons.org/publicdomain/zero/1.0/legalcode

About

Detect CPU capabilities (MMX, SSE/2/3/4, AVX/2, etc. pp.) from Microsoft.NET applications.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages