commit | 249d314cb9eff44e93ca7ad2015a38ddf684f168 | [log] [tgz] |
---|---|---|
author | Marat Dukhan <maratek@gmail.com> | Thu Mar 15 23:20:11 2018 -0700 |
committer | Marat Dukhan <maratek@gmail.com> | Thu Mar 15 23:20:11 2018 -0700 |
tree | 0e4011bfd9b3608a5d8341e099328e2df401cfd1 | |
parent | e2a71abf36df01619d152920f60d1e89216bc266 [diff] |
Support building cpuinfo for unsupported platforms and architectures. - Build will succeed and library can be linked as usual. - CMake will report a warning about unsupported OS/architecture. - CMake will define CPUINFO_SUPPORTED_PLATFORM=0 for targets depending on cpuinfo target (if platform is supported, it defines CPUINFO_SUPPORTED_PLATFORM=1) - cpuinfo_initialize() function will log an error about unsupported OS/architecture and return false. - cpuinfo_get_* functions will return NULL or 0.
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 support 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);
/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)clGetDeviceInfo
with CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
/CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
parameters (Android)/proc/cpuinfo
(Linux)host_info
(Mach)GetLogicalProcessorInformationEx
(Windows)