mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +08:00
fix in case we don't know how to query the L1/L2 cache sizes
This commit is contained in:
parent
0212eec23f
commit
98686ab86c
@ -35,8 +35,8 @@ inline void ei_manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::pt
|
||||
m_l1CacheSize = ei_queryL1CacheSize();
|
||||
m_l2CacheSize = ei_queryTopLevelCacheSize();
|
||||
|
||||
if(m_l1CacheSize==0) m_l1CacheSize = 8 * 1024;
|
||||
if(m_l2CacheSize==0) m_l2CacheSize = 1 * 1024 * 1024;
|
||||
if(m_l1CacheSize<=0) m_l1CacheSize = 8 * 1024;
|
||||
if(m_l2CacheSize<=0) m_l2CacheSize = 1 * 1024 * 1024;
|
||||
}
|
||||
|
||||
if(action==SetAction)
|
||||
|
@ -603,6 +603,7 @@ public:
|
||||
* \returns the size in Bytes of the L1 data cache */
|
||||
inline std::ptrdiff_t ei_queryL1CacheSize()
|
||||
{
|
||||
#ifdef EIGEN_CPUID
|
||||
int abcd[4];
|
||||
|
||||
// try the direct method using extended level
|
||||
@ -640,17 +641,24 @@ inline std::ptrdiff_t ei_queryL1CacheSize()
|
||||
}
|
||||
|
||||
return l1*1024;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \returns the size in Bytes of the L2 or L3 cache if this later is present */
|
||||
inline std::ptrdiff_t ei_queryTopLevelCacheSize()
|
||||
{
|
||||
#ifdef EIGEN_CPUID
|
||||
int abcd[4];
|
||||
EIGEN_CPUID(abcd,0x80000006);
|
||||
std::ptrdiff_t l2 = std::ptrdiff_t(abcd[2] >> 16) * 1024;
|
||||
std::ptrdiff_t l3 = std::ptrdiff_t((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024;
|
||||
return std::max(l2,l3);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // EIGEN_MEMORY_H
|
||||
|
@ -65,8 +65,10 @@ void gemm(const M& a, const M& b, M& c)
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
std::cout << "L1 cache size = " << ei_queryL1CacheSize()/1024 << " KB\n";
|
||||
std::cout << "L2/L3 cache size = " << ei_queryTopLevelCacheSize()/1024 << " KB\n";
|
||||
std::ptrdiff_t l1 = ei_queryL1CacheSize();
|
||||
std::ptrdiff_t l2 = ei_queryTopLevelCacheSize();
|
||||
std::cout << "L1 cache size = " << (l1>0 ? l1/1024 : -1) << " KB\n";
|
||||
std::cout << "L2/L3 cache size = " << (l2>0 ? l2/1024 : -1) << " KB\n";
|
||||
|
||||
setCpuCacheSizes(ei_queryL1CacheSize()/1,ei_queryTopLevelCacheSize()/2);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user