{"id":13543906,"url":"https://github.com/pytorch/cpuinfo","last_synced_at":"2025-05-14T13:05:59.129Z","repository":{"id":39375605,"uuid":"83772175","full_name":"pytorch/cpuinfo","owner":"pytorch","description":"CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)","archived":false,"fork":false,"pushed_at":"2025-05-01T22:25:24.000Z","size":5241,"stargazers_count":1081,"open_issues_count":82,"forks_count":354,"subscribers_count":302,"default_branch":"main","last_synced_at":"2025-05-08T00:08:26.242Z","etag":null,"topics":["cpu","cpu-cache","cpu-model","cpu-topology","cpuid","instruction-set"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pytorch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-03T07:46:54.000Z","updated_at":"2025-05-02T01:17:57.000Z","dependencies_parsed_at":"2023-12-08T06:29:15.317Z","dependency_job_id":"44c18cac-8b91-4504-a98a-92a9da0c5d46","html_url":"https://github.com/pytorch/cpuinfo","commit_stats":{"total_commits":726,"total_committers":61,"mean_commits":"11.901639344262295","dds":"0.35123966942148765","last_synced_commit":"1e83a2fdd3102f65c6f1fb602c1b320486218a99"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fcpuinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fcpuinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fcpuinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fcpuinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pytorch","download_url":"https://codeload.github.com/pytorch/cpuinfo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149947,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","cpu-cache","cpu-model","cpu-topology","cpuid","instruction-set"],"created_at":"2024-08-01T11:00:38.325Z","updated_at":"2025-05-14T13:05:59.105Z","avatar_url":"https://github.com/pytorch.png","language":"C","readme":"# CPU INFOrmation library\n\n[![BSD (2 clause) License](https://img.shields.io/badge/License-BSD%202--Clause%20%22Simplified%22%20License-blue.svg)](https://github.com/pytorch/cpuinfo/blob/master/LICENSE)\n[![Linux/Mac build status](https://img.shields.io/travis/pytorch/cpuinfo.svg)](https://travis-ci.org/pytorch/cpuinfo)\n[![Windows build status](https://ci.appveyor.com/api/projects/status/g5khy9nr0xm458t7/branch/master?svg=true)](https://ci.appveyor.com/project/MaratDukhan/cpuinfo/branch/master)\n\ncpuinfo is a library to detect essential for performance optimization information about host CPU.\n\n## Features\n\n- **Cross-platform** availability:\n  - Linux, Windows, macOS, Android, iOS and FreeBSD operating systems\n  - x86, x86-64, ARM, and ARM64 architectures\n- Modern **C/C++ interface**\n  - Thread-safe\n  - No memory allocation after initialization\n  - No exceptions thrown\n- Detection of **supported instruction sets**, up to AVX512 (x86) and ARMv8.3 extensions\n- Detection of SoC and core information:\n  - **Processor (SoC) name**\n  - Vendor and **microarchitecture** for each CPU core\n  - ID (**MIDR** on ARM, **CPUID** leaf 1 EAX value on x86) for each CPU core\n- Detection of **cache information**:\n  - Cache type (instruction/data/unified), size and line size\n  - Cache associativity\n  - Cores and logical processors (hyper-threads) sharing the cache\n- Detection of **topology information** (relative between logical processors, cores, and processor packages)\n- Well-tested **production-quality** code:\n  - 60+ mock tests based on data from real devices\n  - Includes work-arounds for common bugs in hardware and OS kernels\n  - Supports systems with heterogenous cores, such as **big.LITTLE** and Max.Med.Min\n- Permissive **open-source** license (Simplified BSD)\n\n## Examples\n\nLog processor name:\n\n```c\ncpuinfo_initialize();\nprintf(\"Running on %s CPU\\n\", cpuinfo_get_package(0)-\u003ename);\n```\n\nDetect if target is a 32-bit or 64-bit ARM system:\n\n```c\n#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64\n    /* 32-bit ARM-specific code here */\n#endif\n```\n\nCheck if the host CPU supports ARM NEON\n\n```c\ncpuinfo_initialize();\nif (cpuinfo_has_arm_neon()) {\n    neon_implementation(arguments);\n}\n```\n\nCheck if the host CPU supports x86 AVX\n\n```c\ncpuinfo_initialize();\nif (cpuinfo_has_x86_avx()) {\n    avx_implementation(arguments);\n}\n```\n\nCheck if the thread runs on a Cortex-A53 core\n\n```c\ncpuinfo_initialize();\nswitch (cpuinfo_get_current_core()-\u003euarch) {\n    case cpuinfo_uarch_cortex_a53:\n        cortex_a53_implementation(arguments);\n        break;\n    default:\n        generic_implementation(arguments);\n        break;\n}\n```\n\nGet the size of level 1 data cache on the fastest core in the processor (e.g. big core in big.LITTLE ARM systems):\n\n```c\ncpuinfo_initialize();\nconst size_t l1_size = cpuinfo_get_processor(0)-\u003ecache.l1d-\u003esize;\n```\n\nPin thread to cores sharing L2 cache with the current core (Linux or Android)\n\n```c\ncpuinfo_initialize();\ncpu_set_t cpu_set;\nCPU_ZERO(\u0026cpu_set);\nconst struct cpuinfo_cache* current_l2 = cpuinfo_get_current_processor()-\u003ecache.l2;\nfor (uint32_t i = 0; i \u003c current_l2-\u003eprocessor_count; i++) {\n    CPU_SET(cpuinfo_get_processor(current_l2-\u003eprocessor_start + i)-\u003elinux_id, \u0026cpu_set);\n}\npthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), \u0026cpu_set);\n```\n\n## Use via pkg-config\n\nIf you would like to provide your project's build environment with the necessary compiler and linker flags in a portable manner, the library by default when built enables `CPUINFO_BUILD_PKG_CONFIG` and will generate a [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) manifest (_libcpuinfo.pc_). Here are several examples of how to use it:\n\n### Command Line\n\nIf you used your distro's package manager to install the library, you can verify that it is available to your build environment like so:\n\n```console\n$ pkg-config --cflags --libs libcpuinfo\n-I/usr/include/x86_64-linux-gnu/ -L/lib/x86_64-linux-gnu/ -lcpuinfo\n```\n\nIf you have installed the library from source into a non-standard prefix, pkg-config may need help finding it:\n\n```console\n$ PKG_CONFIG_PATH=\"/home/me/projects/cpuinfo/prefix/lib/pkgconfig/:$PKG_CONFIG_PATH\" pkg-config --cflags --libs libcpuinfo\n-I/home/me/projects/cpuinfo/prefix/include -L/home/me/projects/cpuinfo/prefix/lib -lcpuinfo\n```\n\n### GNU Autotools\n\nTo [use](https://autotools.io/pkgconfig/pkg_check_modules.html) with the GNU Autotools include the following snippet in your project's `configure.ac`:\n\n```makefile\n# CPU INFOrmation library...\nPKG_CHECK_MODULES(\n    [libcpuinfo], [libcpuinfo], [],\n    [AC_MSG_ERROR([libcpuinfo missing...])])\nYOURPROJECT_CXXFLAGS=\"$YOURPROJECT_CXXFLAGS $libcpuinfo_CFLAGS\"\nYOURPROJECT_LIBS=\"$YOURPROJECT_LIBS $libcpuinfo_LIBS\"\n```\n\n### Meson\n\nTo use with Meson you just need to add `dependency('libcpuinfo')` as a dependency for your executable.\n\n```meson\nproject(\n    'MyCpuInfoProject',\n    'cpp',\n    meson_version: '\u003e=0.55.0'\n)\n\nexecutable(\n    'MyCpuInfoExecutable',\n    sources: 'main.cpp',\n    dependencies: dependency('libcpuinfo')\n)\n```\n\n### Bazel\n\nThis project can be built using [Bazel](https://bazel.build/install). \n\nYou can also use this library as a dependency to your Bazel project. Add to the `WORKSPACE` file:\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\n\ngit_repository(\n    name = \"org_pytorch_cpuinfo\",\n    branch = \"master\",\n    remote = \"https://github.com/Vertexwahn/cpuinfo.git\",\n)\n```\n\nAnd to your `BUILD` file:\n\n```python\ncc_binary(\n    name = \"cpuinfo_test\",\n    srcs = [\n        # ...\n    ],\n    deps = [\n        \"@org_pytorch_cpuinfo//:cpuinfo\",\n    ],\n)\n```\n\n### CMake\n\nTo use with CMake use the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module. Here is an example:\n\n```cmake\ncmake_minimum_required(VERSION 3.6)\nproject(\"MyCpuInfoProject\")\n\nfind_package(PkgConfig)\npkg_check_modules(CpuInfo REQUIRED IMPORTED_TARGET libcpuinfo)\n\nadd_executable(${PROJECT_NAME} main.cpp)\ntarget_link_libraries(${PROJECT_NAME} PkgConfig::CpuInfo)\n```\n\n### Makefile\n\nTo use within a vanilla makefile, you can call pkg-config directly to supply compiler and linker flags using shell substitution.\n\n```makefile\nCFLAGS=-g3 -Wall -Wextra -Werror ...\nLDFLAGS=-lfoo ...\n...\nCFLAGS+= $(pkg-config --cflags libcpuinfo)\nLDFLAGS+= $(pkg-config --libs libcpuinfo)\n```\n\n## Exposed information\n- [x] Processor (SoC) name\n- [x] Microarchitecture\n- [x] Usable instruction sets\n- [ ] CPU frequency\n- [x] Cache\n  - [x] Size\n  - [x] Associativity\n  - [x] Line size\n  - [x] Number of partitions\n  - [x] Flags (unified, inclusive, complex hash function)\n  - [x] Topology (logical processors that share this cache level)\n- [ ] TLB\n  - [ ] Number of entries\n  - [ ] Associativity\n  - [ ] Covered page types (instruction, data)\n  - [ ] Covered page sizes\n- [x] Topology information\n  - [x] Logical processors\n  - [x] Cores\n  - [x] Packages (sockets)\n\n## Supported environments:\n- [x] Android\n  - [x] x86 ABI\n  - [x] x86_64 ABI\n  - [x] armeabi ABI\n  - [x] armeabiv7-a ABI\n  - [x] arm64-v8a ABI\n  - [ ] ~~mips ABI~~\n  - [ ] ~~mips64 ABI~~\n- [x] Linux\n  - [x] x86\n  - [x] x86-64\n  - [x] 32-bit ARM (ARMv5T and later)\n  - [x] ARM64\n  - [ ] PowerPC64\n- [x] iOS\n  - [x] x86 (iPhone simulator)\n  - [x] x86-64 (iPhone simulator)\n  - [x] ARMv7\n  - [x] ARM64\n- [x] macOS\n  - [x] x86\n  - [x] x86-64\n  - [x] ARM64 (Apple silicon)\n- [x] Windows\n  - [x] x86\n  - [x] x86-64\n  - [x] arm64\n- [x] FreeBSD\n  - [x] x86-64\n\n## Methods\n\n- Processor (SoC) name detection\n  - [x] Using CPUID leaves 0x80000002–0x80000004 on x86/x86-64\n  - [x] Using `/proc/cpuinfo` on ARM\n  - [x] Using `ro.chipname`, `ro.board.platform`, `ro.product.board`, `ro.mediatek.platform`, `ro.arch` properties (Android)\n  - [ ] Using kernel log (`dmesg`) on ARM Linux\n  - [x] Using Windows registry on ARM64 Windows\n- Vendor and microarchitecture detection\n  - [x] Intel-designed x86/x86-64 cores (up to Sunny Cove, Goldmont Plus, and Knights Mill)\n  - [x] AMD-designed x86/x86-64 cores (up to Puma/Jaguar and Zen 2)\n  - [ ] VIA-designed x86/x86-64 cores\n  - [ ] Other x86 cores (DM\u0026P, RDC, Transmeta, Cyrix, Rise)\n  - [x] ARM-designed ARM cores (up to Cortex-A55, Cortex-A77, and Neoverse E1/V1/N2/V2)\n  - [x] Qualcomm-designed ARM cores (Scorpion, Krait, and Kryo)\n  - [x] Nvidia-designed ARM cores (Denver and Carmel)\n  - [x] Samsung-designed ARM cores (Exynos)\n  - [x] Intel-designed ARM cores (XScale up to 3rd-gen)\n  - [x] Apple-designed ARM cores (up to Lightning and Thunder)\n  - [x] Cavium-designed ARM cores (ThunderX)\n  - [x] AppliedMicro-designed ARM cores (X-Gene)\n- Instruction set detection\n  - [x] Using CPUID (x86/x86-64)\n  - [x] Using `/proc/cpuinfo` on 32-bit ARM EABI (Linux)\n  - [x] Using microarchitecture heuristics on (32-bit ARM)\n  - [x] Using `FPSID` and `WCID` registers (32-bit ARM)\n  - [x] Using `getauxval` (Linux/ARM)\n  - [x] Using `/proc/self/auxv` (Android/ARM)\n  - [ ] Using instruction probing on ARM (Linux)\n  - [ ] Using CPUID registers on ARM64 (Linux)\n  - [x] Using IsProcessorFeaturePresent on ARM64 Windows\n- Cache detection\n  - [x] Using CPUID leaf 0x00000002 (x86/x86-64)\n  - [x] Using CPUID leaf 0x00000004 (non-AMD x86/x86-64)\n  - [ ] Using CPUID leaves 0x80000005-0x80000006 (AMD x86/x86-64)\n  - [x] Using CPUID leaf 0x8000001D (AMD x86/x86-64)\n  - [x] Using `/proc/cpuinfo` (Linux/pre-ARMv7)\n  - [x] Using microarchitecture heuristics (ARM)\n  - [x] Using chipset name (ARM)\n  - [x] Using `sysctlbyname` (Mach)\n  - [x] Using sysfs `typology` directories (ARM/Linux)\n  - [ ] Using sysfs `cache` directories (Linux)\n  - [x] Using `GetLogicalProcessorInformationEx` on ARM64 Windows\n- TLB detection\n  - [x] Using CPUID leaf 0x00000002 (x86/x86-64)\n  - [ ] Using CPUID leaves 0x80000005-0x80000006 and 0x80000019 (AMD x86/x86-64)\n  - [x] Using microarchitecture heuristics (ARM)\n- Topology detection\n  - [x] Using CPUID leaf 0x00000001 on x86/x86-64 (legacy APIC ID)\n  - [x] Using CPUID leaf 0x0000000B on x86/x86-64 (Intel APIC ID)\n  - [ ] Using CPUID leaf 0x8000001E on x86/x86-64 (AMD APIC ID)\n  - [x] Using `/proc/cpuinfo` (Linux)\n  - [x] Using `host_info` (Mach)\n  - [x] Using `GetLogicalProcessorInformationEx` (Windows)\n  - [x] Using sysfs (Linux)\n  - [x] Using chipset name (ARM/Linux)\n\n","funding_links":[],"categories":["CS大类","C","C++"],"sub_categories":["基本操作"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fcpuinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpytorch%2Fcpuinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fcpuinfo/lists"}