diff --git a/Eigen/src/Core/products/GeneralMatrixMatrix.h b/Eigen/src/Core/products/GeneralMatrixMatrix.h index cbb389542..c1d42d387 100644 --- a/Eigen/src/Core/products/GeneralMatrixMatrix.h +++ b/Eigen/src/Core/products/GeneralMatrixMatrix.h @@ -40,7 +40,7 @@ struct ei_general_matrix_matrix_product* info = 0) { // transpose the product such that the result is column major ei_general_matrix_matrix_product* info = 0) { ei_const_blas_data_mapper lhs(_lhs,lhsStride); ei_const_blas_data_mapper rhs(_rhs,rhsStride); @@ -218,11 +218,13 @@ struct ei_traits > template struct ei_gemm_functor { + typedef typename Rhs::Scalar BlockBScalar; + ei_gemm_functor(const Lhs& lhs, const Rhs& rhs, Dest& dest, Scalar actualAlpha) : m_lhs(lhs), m_rhs(rhs), m_dest(dest), m_actualAlpha(actualAlpha) {} - void operator() (int row, int rows, int col=0, int cols=-1, GemmParallelInfo* info=0) const + void operator() (int row, int rows, int col=0, int cols=-1, GemmParallelInfo* info=0) const { if(cols==-1) cols = m_rhs.cols(); @@ -234,6 +236,12 @@ struct ei_gemm_functor info); } + + int sharedBlockBSize() const + { + return std::min(ei_product_blocking_traits::Max_kc,m_rhs.rows()) * m_rhs.cols(); + } + protected: const Lhs& m_lhs; const Rhs& m_rhs; @@ -275,7 +283,7 @@ class GeneralProduct _ActualRhsType, Dest> GemmFunctor; - ei_parallelize_gemm32>(GemmFunctor(lhs, rhs, dst, actualAlpha), this->rows(), this->cols()); + ei_parallelize_gemm<(Dest::MaxRowsAtCompileTime>32)>(GemmFunctor(lhs, rhs, dst, actualAlpha), this->rows(), this->cols()); } }; diff --git a/Eigen/src/Core/products/Parallelizer.h b/Eigen/src/Core/products/Parallelizer.h index 62cf16047..03d85c1ce 100644 --- a/Eigen/src/Core/products/Parallelizer.h +++ b/Eigen/src/Core/products/Parallelizer.h @@ -25,16 +25,16 @@ #ifndef EIGEN_PARALLELIZER_H #define EIGEN_PARALLELIZER_H -struct GemmParallelInfo +template struct GemmParallelInfo { - GemmParallelInfo() : sync(-1), users(0) {} + GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0), blockB(0) {} int volatile sync; int volatile users; int rhs_start; int rhs_length; - float* blockB; + BlockBScalar* blockB; }; template @@ -51,9 +51,10 @@ void ei_parallelize_gemm(const Functor& func, int rows, int cols) int blockCols = (cols / threads) & ~0x3; int blockRows = (rows / threads) & ~0x7; - float* sharedBlockB = new float[2048*2048*4]; + typedef typename Functor::BlockBScalar BlockBScalar; + BlockBScalar* sharedBlockB = new BlockBScalar[func.sharedBlockBSize()]; - GemmParallelInfo* info = new GemmParallelInfo[threads]; + GemmParallelInfo* info = new GemmParallelInfo[threads]; #pragma omp parallel for schedule(static,1) for(int i=0; i