pytorch/cpuinfo logo

pytorch/cpuinfo

Free

CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)

FreeFree tier
Type
Open Source
Company
PyTorch

About pytorch/cpuinfo

cpuinfo is a C/C++ library for detecting CPU information essential for performance optimization. It provides cross-platform support for Linux, Windows, macOS, Android, iOS, and FreeBSD on x86, x86-64, ARM, and ARM64 architectures. The library detects supported instruction sets (up to AVX512 and ARMv8.3), SoC and core details (vendor, microarchitecture, core ID), cache hierarchy (type, size, line size, associativity, shared processors), and topology (logical processors, cores, packages). It includes workarounds for common hardware and OS bugs, supports heterogeneous cores (big.LITTLE, Max.Med.Min), and is thread-safe with no memory allocation after initialization and no exceptions. The library is well-tested with 60+ mock tests from real devices and is available under a permissive Simplified BSD license.

Key Features

Cross-platform support (Linux, Windows, macOS, Android, iOS, FreeBSD)
Supports x86, x86-64, ARM, and ARM64 architectures
Detection of instruction sets up to AVX512 (x86) and ARMv8.3 extensions
Detection of SoC/core information: name, vendor, microarchitecture, core ID
Cache hierarchy detection: type, size, line size, associativity, shared processors
Topology detection between logical processors, cores, and packages
Support for heterogeneous cores (big.LITTLE, Max.Med.Min)
Thread-safe, no memory allocation after initialization, no exceptions
Well-tested with 60+ mock tests from real device data
Includes workarounds for common hardware and OS kernel bugs

Pros & Cons

Pros
  • Comprehensive CPU feature detection in a single library
  • Cross-platform and multi-architecture support
  • Thread-safe with no dynamic memory allocation after init
  • Robust with workarounds for common hardware/OS bugs
  • Permissive BSD license allows commercial use
  • Backed by PyTorch ecosystem and community
Cons
  • Library is C/C++ only; no native bindings for other languages
  • May require compilation and linking as a dependency
  • Focuses only on CPU detection; does not cover GPU or other accelerators

Best For

Optimizing software performance by tailoring code to specific CPU featuresDetecting available SIMD instruction sets (e.g., NEON, AVX) for vectorized codeIdentifying CPU microarchitecture for dispatch of optimized kernelsProfiling cache hierarchies to minimize memory latency in applicationsPorting performance-sensitive code across different platforms and architecturesImplementing cross-platform system monitoring or hardware diagnostics tools

FAQ

How do I check if the host CPU supports ARM NEON?
Initialize the library with `cpuinfo_initialize()`, then check `if (cpuinfo_has_arm_neon())` to run NEON-specific code.
How do I check if the host CPU supports x86 AVX?
Initialize the library with `cpuinfo_initialize()`, then check `if (cpuinfo_has_x86_avx())` to run AVX-specific code.
How can I get the L1 data cache size of the fastest core?
After `cpuinfo_initialize()`, use `const size_t l1_size = cpuinfo_get_processor(0)->cache.l1d->size;`.
What platforms and architectures does cpuinfo support?
cpuinfo supports Linux, Windows, macOS, Android, iOS, and FreeBSD on x86, x86-64, ARM, and ARM64 architectures.
Does cpuinfo handle heterogeneous cores like big.LITTLE?
Yes, cpuinfo supports systems with heterogeneous cores, such as ARM big.LITTLE and Max.Med.Min configurations.