make bench_gemm print out the queried cache sizes

This commit is contained in:
Gael Guennebaud 2010-06-21 12:07:05 +02:00
parent e54635da11
commit 4cd38b333c
2 changed files with 11 additions and 7 deletions

View File

@ -601,7 +601,7 @@ public:
/** \internal /** \internal
* \returns the size in Bytes of the L1 data cache */ * \returns the size in Bytes of the L1 data cache */
inline std::ptrdiff_t ei_fetchL1CacheSize() inline std::ptrdiff_t ei_queryL1CacheSize()
{ {
int abcd[4]; int abcd[4];
@ -644,7 +644,7 @@ inline std::ptrdiff_t ei_fetchL1CacheSize()
/** \internal /** \internal
* \returns the size in Bytes of the L2 or L3 cache if this later is present */ * \returns the size in Bytes of the L2 or L3 cache if this later is present */
inline std::ptrdiff_t ei_fetchTopLevelCacheSize() inline std::ptrdiff_t ei_queryTopLevelCacheSize()
{ {
int abcd[4]; int abcd[4];
EIGEN_CPUID(abcd,0x80000006); EIGEN_CPUID(abcd,0x80000006);

View File

@ -57,6 +57,7 @@ void blas_gemm(const MatrixXd& a, const MatrixXd& b, MatrixXd& c)
#endif #endif
template<typename M>
void gemm(const M& a, const M& b, M& c) void gemm(const M& a, const M& b, M& c)
{ {
c.noalias() += a * b; c.noalias() += a * b;
@ -64,6 +65,9 @@ void gemm(const M& a, const M& b, M& c)
int main(int argc, char ** argv) 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";
int rep = 1; // number of repetitions per try int rep = 1; // number of repetitions per try
int tries = 5; // number of tries, we keep the best int tries = 5; // number of tries, we keep the best
@ -90,11 +94,6 @@ int main(int argc, char ** argv)
if(cache_size>0) if(cache_size>0)
setCpuCacheSizes(cache_size,32*cache_size); setCpuCacheSizes(cache_size,32*cache_size);
std::cout << "Matrix size = " << s << "\n";
std::ptrdiff_t cm, cn, ck;
getBlockingSizes<Scalar>(ck, cm, cn);
std::cout << "blocking size = " << cm << " x " << ck << "\n";
int m = s; int m = s;
int n = s; int n = s;
int p = s; int p = s;
@ -102,6 +101,11 @@ int main(int argc, char ** argv)
M b(n,p); b.setRandom(); M b(n,p); b.setRandom();
M c(m,p); c.setOnes(); M c(m,p); c.setOnes();
std::cout << "Matrix sizes = " << m << "x" << p << " * " << p << "x" << n << "\n";
std::ptrdiff_t cm, cn, ck;
getBlockingSizes<Scalar>(ck, cm, cn);
std::cout << "blocking size = " << cm << " x " << ck << "\n";
M r = c; M r = c;
// check the parallel product is correct // check the parallel product is correct