This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 930 - Add MeasureCacheSizes unsupported module as fallback when CPU caches can't be queried
Summary: Add MeasureCacheSizes unsupported module as fallback when CPU caches can't be...
Status: NEW
Alias: None
Product: Eigen
Classification: Unclassified
Component: Unsupported modules (show other bugs)
Version: unspecified
Hardware: All All
: Normal Unknown
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 937
  Show dependency treegraph
 
Reported: 2015-01-16 22:34 UTC by Benoit Jacob
Modified: 2019-12-04 14:03 UTC (History)
3 users (show)



Attachments
Add MeasureCacheSizes unsupported module. (18.05 KB, patch)
2015-01-16 22:34 UTC, Benoit Jacob
no flags Details | Diff
Add MeasureCacheSizes unsupported module. (17.99 KB, patch)
2015-01-16 22:51 UTC, Benoit Jacob
no flags Details | Diff

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:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344f/Chdebced.html

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;
  Eigen::measure_cache_sizes(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 gitlab.com'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: https://gitlab.com/libeigen/eigen/issues/930.

Note You need to log in before you can comment on or make changes to this bug.