commit | 83c4800c21959581039067d2adacc21b8b35b530 | [log] [tgz] |
---|---|---|
author | Ma Mingfei <mingfei.ma@intel.com> | Wed Apr 17 23:29:37 2024 +0800 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Apr 17 08:35:17 2024 -0700 |
tree | 148ca8d922151abdab55df1fda200a1e7e5c9a1e | |
parent | 50d2114fc59949a6848172573f093a70617bfd8a [diff] |
add detection for intel new isa: avx_ne_convert, avx_vnni_int8, avx_vnni_int16 (#232) Test Plan: ``` bash scripts/local-build.sh ISAS=() OPTIONS=() PLATFORMS=() OPTIONS+=(-quark); PLATFORMS+=("Quark") OPTIONS+=(-p4); PLATFORMS+=("Pentium4") OPTIONS+=(-p4p); PLATFORMS+=("Pentium4 Prescott") OPTIONS+=(-mrm); PLATFORMS+=("Merom") OPTIONS+=(-pnr); PLATFORMS+=("Penryn") OPTIONS+=(-nhm); PLATFORMS+=("Nehalem") OPTIONS+=(-wsm); PLATFORMS+=("Westmere") OPTIONS+=(-snb); PLATFORMS+=("Sandy Bridge") OPTIONS+=(-ivb); PLATFORMS+=("Ivy Bridge") OPTIONS+=(-hsw); PLATFORMS+=("Haswell") OPTIONS+=(-bdw); PLATFORMS+=("Broadwell") OPTIONS+=(-slt); PLATFORMS+=("Saltwell") OPTIONS+=(-slm); PLATFORMS+=("Silvermont") OPTIONS+=(-glm); PLATFORMS+=("Goldmont") OPTIONS+=(-glp); PLATFORMS+=("Goldmont Plus") OPTIONS+=(-tnt); PLATFORMS+=("Tremont") OPTIONS+=(-snr); PLATFORMS+=("Snow Ridge") OPTIONS+=(-skl); PLATFORMS+=("Skylake") OPTIONS+=(-cnl); PLATFORMS+=("Cannon Lake") OPTIONS+=(-icl); PLATFORMS+=("Ice Lake") OPTIONS+=(-skx); PLATFORMS+=("Skylake server") OPTIONS+=(-clx); PLATFORMS+=("Cascade Lake") OPTIONS+=(-cpx); PLATFORMS+=("Cooper Lake") OPTIONS+=(-icx); PLATFORMS+=("Ice Lake server") OPTIONS+=(-knl); PLATFORMS+=("Knights landing") OPTIONS+=(-knm); PLATFORMS+=("Knights mill") OPTIONS+=(-tgl); PLATFORMS+=("Tiger Lake") OPTIONS+=(-adl); PLATFORMS+=("Alder Lake") OPTIONS+=(-mtl); PLATFORMS+=("Meteor Lake") OPTIONS+=(-rpl); PLATFORMS+=("Raptor Lake") OPTIONS+=(-spr); PLATFORMS+=("Sapphire Rapids") OPTIONS+=(-gnr); PLATFORMS+=("Granite Rapids") OPTIONS+=(-gnr256); PLATFORMS+=("Granite Rapids (AVX10.1 / 256VL)") OPTIONS+=(-srf); PLATFORMS+=("Sierra Forest") OPTIONS+=(-arl); PLATFORMS+=("Arrow Lake") OPTIONS+=(-lnl); PLATFORMS+=("Lunar Lake") OPTIONS+=(-future); PLATFORMS+=("Future chip") ISAS+=("AVX_VNNI_INT8") ISAS+=("AVX_VNNI_INT16") ISAS+=("AVX_NE_CONVERT") SDE_BIN="/home/mingfeim/packages/sde-external-9.33.0-2024-01-07-lin/sde" for I in "${!PLATFORMS[@]}"; do echo "${PLATFORMS["${I}"]}" for J in "${!ISAS[@]}"; do "${SDE_BIN}" "${OPTIONS[$I]}" -- ./build/local/isa-info | grep ${ISAS[$J]} done done ``` Results: ``` Quark SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM or by the input cpuid definition file SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM or by the input cpuid definition file SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM or by the input cpuid definition file Pentium4 SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM4 or by the input cpuid definition file SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM4 or by the input cpuid definition file SDE-ERROR: 64 bits applications are not supported by input chip: PENTIUM4 or by the input cpuid definition file Pentium4 Prescott AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Merom AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Penryn AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Nehalem AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Westmere AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Sandy Bridge AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Ivy Bridge AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Haswell AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Broadwell AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Saltwell AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Silvermont AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Goldmont AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Goldmont Plus AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Tremont AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Snow Ridge AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Skylake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Cannon Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Ice Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Skylake server AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Cascade Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Cooper Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Ice Lake server AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Knights landing AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Knights mill AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Tiger Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Alder Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Meteor Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Raptor Lake AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Sapphire Rapids AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Granite Rapids AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Granite Rapids (AVX10.1 / 256VL) AVX_VNNI_INT8: no AVX_VNNI_INT16: no AVX_NE_CONVERT: no Sierra Forest AVX_VNNI_INT8: yes AVX_VNNI_INT16: no AVX_NE_CONVERT: yes Arrow Lake AVX_VNNI_INT8: yes AVX_VNNI_INT16: yes AVX_NE_CONVERT: yes Lunar Lake AVX_VNNI_INT8: yes AVX_VNNI_INT16: yes AVX_NE_CONVERT: yes Future chip AVX_VNNI_INT8: yes AVX_VNNI_INT16: yes AVX_NE_CONVERT: yes ``` GitOrigin-RevId: 3c8b1533ac03dd6531ab6e7b9245d488f13a82a5 Change-Id: I4bc362f7ddb4837143fbccd3dc93ad1eba056ac9
cpuinfo is a library to detect essential for performance optimization information about host CPU.
Log processor name:
cpuinfo_initialize(); printf("Running on %s CPU\n", cpuinfo_get_package(0)->name);
Detect if target is a 32-bit or 64-bit ARM system:
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 /* 32-bit ARM-specific code here */ #endif
Check if the host CPU supports ARM NEON
cpuinfo_initialize(); if (cpuinfo_has_arm_neon()) { neon_implementation(arguments); }
Check if the host CPU supports x86 AVX
cpuinfo_initialize(); if (cpuinfo_has_x86_avx()) { avx_implementation(arguments); }
Check if the thread runs on a Cortex-A53 core
cpuinfo_initialize(); switch (cpuinfo_get_current_core()->uarch) { case cpuinfo_uarch_cortex_a53: cortex_a53_implementation(arguments); break; default: generic_implementation(arguments); break; }
Get the size of level 1 data cache on the fastest core in the processor (e.g. big core in big.LITTLE ARM systems):
cpuinfo_initialize(); const size_t l1_size = cpuinfo_get_processor(0)->cache.l1d->size;
Pin thread to cores sharing L2 cache with the current core (Linux or Android)
cpuinfo_initialize(); cpu_set_t cpu_set; CPU_ZERO(&cpu_set); const struct cpuinfo_cache* current_l2 = cpuinfo_get_current_processor()->cache.l2; for (uint32_t i = 0; i < current_l2->processor_count; i++) { CPU_SET(cpuinfo_get_processor(current_l2->processor_start + i)->linux_id, &cpu_set); } pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpu_set);
If 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 manifest (libcpuinfo.pc). Here are several examples of how to use it:
If you used your distro's package manager to install the library, you can verify that it is available to your build environment like so:
$ pkg-config --cflags --libs libcpuinfo -I/usr/include/x86_64-linux-gnu/ -L/lib/x86_64-linux-gnu/ -lcpuinfo
If you have installed the library from source into a non-standard prefix, pkg-config may need help finding it:
$ PKG_CONFIG_PATH="/home/me/projects/cpuinfo/prefix/lib/pkgconfig/:$PKG_CONFIG_PATH" pkg-config --cflags --libs libcpuinfo -I/home/me/projects/cpuinfo/prefix/include -L/home/me/projects/cpuinfo/prefix/lib -lcpuinfo
To use with the GNU Autotools include the following snippet in your project's configure.ac
:
# CPU INFOrmation library... PKG_CHECK_MODULES( [libcpuinfo], [libcpuinfo], [], [AC_MSG_ERROR([libcpuinfo missing...])]) YOURPROJECT_CXXFLAGS="$YOURPROJECT_CXXFLAGS $libcpuinfo_CFLAGS" YOURPROJECT_LIBS="$YOURPROJECT_LIBS $libcpuinfo_LIBS"
To use with Meson you just need to add dependency('libcpuinfo')
as a dependency for your executable.
project( 'MyCpuInfoProject', 'cpp', meson_version: '>=0.55.0' ) executable( 'MyCpuInfoExecutable', sources: 'main.cpp', dependencies: dependency('libcpuinfo') )
This project can be built using Bazel.
You can also use this library as a dependency to your Bazel project. Add to the WORKSPACE
file:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "org_pytorch_cpuinfo", branch = "master", remote = "https://github.com/Vertexwahn/cpuinfo.git", )
And to your BUILD
file:
cc_binary( name = "cpuinfo_test", srcs = [ # ... ], deps = [ "@org_pytorch_cpuinfo//:cpuinfo", ], )
To use with CMake use the FindPkgConfig module. Here is an example:
cmake_minimum_required(VERSION 3.6) project("MyCpuInfoProject") find_package(PkgConfig) pkg_check_modules(CpuInfo REQUIRED IMPORTED_TARGET libcpuinfo) add_executable(${PROJECT_NAME} main.cpp) target_link_libraries(${PROJECT_NAME} PkgConfig::CpuInfo)
To use within a vanilla makefile, you can call pkg-config directly to supply compiler and linker flags using shell substitution.
CFLAGS=-g3 -Wall -Wextra -Werror ... LDFLAGS=-lfoo ... ... CFLAGS+= $(pkg-config --cflags libcpuinfo) LDFLAGS+= $(pkg-config --libs libcpuinfo)
/proc/cpuinfo
on ARMro.chipname
, ro.board.platform
, ro.product.board
, ro.mediatek.platform
, ro.arch
properties (Android)dmesg
) on ARM Linux/proc/cpuinfo
on 32-bit ARM EABI (Linux)FPSID
and WCID
registers (32-bit ARM)getauxval
(Linux/ARM)/proc/self/auxv
(Android/ARM)/proc/cpuinfo
(Linux/pre-ARMv7)sysctlbyname
(Mach)typology
directories (ARM/Linux)cache
directories (Linux)GetLogicalProcessorInformationEx
on ARM64 Windows/proc/cpuinfo
(Linux)host_info
(Mach)GetLogicalProcessorInformationEx
(Windows)