In order to check whether AVX or SSE is available, the compiler usually sets SSE or AVX true. However is there an option, how to receive during compile time the size of the cache?
Edit: I refrase the question a little bit, since it is not clear enough.
I want information about the cache during compile time. The more the better. I would like to have it for optimization purposes (i.e. cache-blocking,...). In my current task - spatial blocking - the size of the cache is mostly relevant. But the comments bellow rightly asked, which level of cache am i asking for. In addition caches can behave very differrently, if you consider their evicting strategy, size of cache line, amount of levels, how they are shared between cores... The list goes on.
So my general question: How do i recieve any information about the cache during compile time?
For my current task, it would be sufficient to readout /proc/cpuinfo and use the cachesize given there. However the general question is far more interesting.
How do i recieve information about the cpu (with focus on its cache) during compile time?
(I am not considering of crosscompiling at all. The code compiled will be run on the SAME machine.)
Apparently, no compiler is capable of having such detailed information about a cpu AND making it available to the compiling program. However i have found a library, which seems to do exactly that. Sadly again only at runtime. However it is at least a comfortable solution.
(I found it by accident. I was not looking for it :) If you ever look for something, 1) google 2) look here)
You can compile several versions of your library for various cache sizes and then pick them dynamically. That is the only possible approach for adding cache size info at compile-time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With