Archspec
Archspec is a Python library designed to provide a standard set of human-understandable labels for system architectures, primarily focusing on CPU microarchitectures. It offers APIs to detect, query, and compare different CPU types. The project originated from Spack and is under active development. The current version is 0.2.5. While it does not follow a strict release cadence, its update history, including a significant release in October 2024, indicates ongoing maintenance and development.
Common errors
-
archspec.cpu.UnsupportedMicroarchitecture: Host microarchitecture is not supported.
cause The CPU microarchitecture of the host system could not be identified by Archspec, or it is not present in its internal database.fixThis often occurs on newer or less common architectures. Check the `archspec.cpu.detect.why_not()` function for a more detailed reason. You might need to update Archspec to a newer version or contribute your architecture's data. -
archspec.cpu.InvalidCompilerVersion: Invalid format for compiler version.
cause An incorrect or unparseable string was provided for a compiler version when querying optimization flags or similar features.fixEnsure that compiler versions are provided as dot-separated digits (e.g., '10.0.0' for GCC 10.0.0).
Warnings
- breaking The naming scheme for Graviton chips changed in v0.2. Graviton is now named 'cortex_a72', Graviton2 is 'neoverse_n1', and 'neoverse_v1' was introduced instead of Graviton3.
- breaking Support for Python 2.7 and Python 3.5 was dropped in v0.2.
- gotcha Installing directly from the GitHub repository for development requires Poetry.
Install
-
pip install archspec
Imports
- host
from archspec.cpu.detect import host
- Microarchitecture
from archspec.cpu import Microarchitecture
Quickstart
import archspec.cpu.detect
try:
host_cpu = archspec.cpu.detect.host()
if host_cpu:
print(f"Detected host CPU microarchitecture: {host_cpu.name}")
# Example of accessing properties
# print(f"Vendor: {host_cpu.vendor}")
# print(f"Ancestors: {[a.name for a in host_cpu.ancestors]}")
else:
print("Could not detect host CPU microarchitecture.")
print(f"Reason: {archspec.cpu.detect.why_not('native')}")
except archspec.cpu.UnsupportedMicroarchitecture:
print("Host microarchitecture is not recognized or supported by archspec.")
except Exception as e:
print(f"An unexpected error occurred: {e}")