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.
Created attachment 516 [details] Add MeasureCacheSizes unsupported module.
Comment on attachment 516 [details] Add MeasureCacheSizes unsupported module. Gael - please review!
Bug 931 has the patches to actually make use of this in products.
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 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.
-- 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.