This bugzilla service is closed. All entries have been migrated to

Bug 930

Summary: Add MeasureCacheSizes unsupported module as fallback when CPU caches can't be queried
Product: Eigen Reporter: Benoit Jacob <jacob.benoit.1>
Component: Unsupported modulesAssignee: Nobody <eigen.nobody>
Status: NEW ---    
Severity: Unknown CC:, chtz, gael.guennebaud
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 937    
Description Flags
Add MeasureCacheSizes unsupported module.
Add MeasureCacheSizes unsupported module. none

Description Benoit Jacob 2015-01-16 22:34:17 UTC
Created attachment 515 [details]
Add MeasureCacheSizes unsupported module.

Eigen is able to use CPUID to query the cache structure on x86. That's great and the next question is how to do the same on ARM; unfortunately, the equivalent thing on ARM is generally not accessible from userspace. See:

On ARM architectures, it is up to the operating system to expose this information to userspace; unfortunately, as of 2015, Android kernels don't.

So for now, if we want to run optimally fast on Android, we probably have to resort to empirically measuring cache sizes by running some kind of benchmark.

The proposed patch here adds an unsupported module doing that.

It offers only one function, measure_cache_sizes, returning all the cache sizes in an array of integers. It's not too bad; in practice, it runs in no more than 1 second and successfully detects the cache structure of various x86 and ARM CPUs that I've tested it on.

This module intentionally doesn't try to offer functions to teach Eigen itself about this cache structure. Instead, we intentionally leave that up to the application. Some applications may only want to directly pass that to Eigen, while other applications may want to cache the resulting values on disk... it doesn't feel like Eigen should try to help with that.

Here is a sample program using this function to dump the cache structure:

#include <unsupported/Eigen/CXX11/MeasureCacheSizes>
#include <iostream>

int main()
  std::vector<size_t> cache_sizes;
  for (size_t i = 0; i < cache_sizes.size(); i++) {
    std::cout << "L" << (i+1) << " cache size: "
              << cache_sizes[i] << std::endl;

Output on a Core i7:

L1 cache size: 32768
L2 cache size: 262144
L3 cache size: 8388608

real	0m0.989s
user	0m0.987s
sys	0m0.000s

On a Nexus 4 phone:

L1 cache size: 16384
L2 cache size: 1048576

    0m0.83s real     0m0.70s user     0m0.09s system

So in both cases it finds the right values in about 1 second.
Comment 1 Benoit Jacob 2015-01-16 22:51:01 UTC
Created attachment 516 [details]
Add MeasureCacheSizes unsupported module.
Comment 2 Benoit Jacob 2015-01-16 22:51:25 UTC
Comment on attachment 516 [details]
Add MeasureCacheSizes unsupported module.

Gael - please review!
Comment 3 Benoit Jacob 2015-01-19 22:10:10 UTC
Bug 931 has the patches to actually make use of this in products.
Comment 4 Benoit Jacob 2015-01-28 18:16:35 UTC
See bug 937 comment 8: we mostly agree that for now we only need to know L1 and last level of cache, so only 2 values. So only the front() and back() of the vector returned by measure_cache_sizes matter. I think I'll still let this function return a vector, it's a bit nicer and if something goes wrong and it returns wrong values, the extra values in the middle of the vector can be very interesting to understand what happened.
Comment 5 Benoit Jacob 2015-01-28 18:17:11 UTC
Comment on attachment 516 [details]
Add MeasureCacheSizes unsupported module.

Cancelling review because I'm burdening you a lot already and you said that for an unsupported module I dont need a review.
Comment 6 Nobody 2019-12-04 14:03:40 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: