10 #ifndef EIGEN_GENERAL_MATRIX_MATRIX_H 11 #define EIGEN_GENERAL_MATRIX_MATRIX_H 22 typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
23 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs>
27 static EIGEN_STRONG_INLINE
void run(
28 Index rows, Index cols, Index depth,
29 const LhsScalar* lhs, Index lhsStride,
30 const RhsScalar* rhs, Index rhsStride,
31 ResScalar* res, Index resStride,
41 ::run(cols,rows,depth,rhs,rhsStride,lhs,lhsStride,res,resStride,alpha,blocking,info);
49 typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
50 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs>
55 static void run(Index rows, Index cols, Index depth,
56 const LhsScalar* _lhs, Index lhsStride,
57 const RhsScalar* _rhs, Index rhsStride,
58 ResScalar* res, Index resStride,
68 Index kc = blocking.kc();
69 Index mc = (std::min)(rows,blocking.mc());
76 #ifdef EIGEN_HAS_OPENMP 80 Index tid = omp_get_thread_num();
81 Index threads = omp_get_num_threads();
83 std::size_t sizeA = kc*mc;
84 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
85 ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, 0);
86 ei_declare_aligned_stack_constructed_variable(RhsScalar, w, sizeW, 0);
88 RhsScalar* blockB = blocking.blockB();
89 eigen_internal_assert(blockB!=0);
92 for(Index k=0; k<depth; k+=kc)
94 const Index actual_kc = (std::min)(k+kc,depth)-k;
98 pack_lhs(blockA, &lhs(0,k), lhsStride, actual_kc, mc);
106 while(info[tid].users!=0) {}
107 info[tid].users += threads;
109 pack_rhs(blockB+info[tid].rhs_start*actual_kc, &rhs(k,info[tid].rhs_start), rhsStride, actual_kc, info[tid].rhs_length);
115 for(Index shift=0; shift<threads; ++shift)
117 Index j = (tid+shift)%threads;
123 while(info[j].sync!=k) {}
125 gebp(res+info[j].rhs_start*resStride, resStride, blockA, blockB+info[j].rhs_start*actual_kc, mc, actual_kc, info[j].rhs_length, alpha, -1,-1,0,0, w);
129 for(Index i=mc; i<rows; i+=mc)
131 const Index actual_mc = (std::min)(i+mc,rows)-i;
134 pack_lhs(blockA, &lhs(i,k), lhsStride, actual_kc, actual_mc);
137 gebp(res+i, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1,-1,0,0, w);
142 for(Index j=0; j<threads; ++j)
150 #endif // EIGEN_HAS_OPENMP 152 EIGEN_UNUSED_VARIABLE(info);
155 std::size_t sizeA = kc*mc;
156 std::size_t sizeB = kc*cols;
157 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
159 ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
160 ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
161 ei_declare_aligned_stack_constructed_variable(RhsScalar, blockW, sizeW, blocking.blockW());
165 for(Index k2=0; k2<depth; k2+=kc)
167 const Index actual_kc = (std::min)(k2+kc,depth)-k2;
173 pack_rhs(blockB, &rhs(k2,0), rhsStride, actual_kc, cols);
177 for(Index i2=0; i2<rows; i2+=mc)
179 const Index actual_mc = (std::min)(i2+mc,rows)-i2;
184 pack_lhs(blockA, &lhs(i2,k2), lhsStride, actual_kc, actual_mc);
187 gebp(res+i2, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1, -1, 0, 0, blockW);
200 template<
typename Lhs,
typename Rhs>
202 :
traits<ProductBase<GeneralProduct<Lhs,Rhs,GemmProduct>, Lhs, Rhs> >
205 template<
typename Scalar,
typename Index,
typename Gemm,
typename Lhs,
typename Rhs,
typename Dest,
typename BlockingType>
208 gemm_functor(
const Lhs& lhs,
const Rhs& rhs, Dest& dest,
const Scalar& actualAlpha,
209 BlockingType& blocking)
210 : m_lhs(lhs), m_rhs(rhs), m_dest(dest), m_actualAlpha(actualAlpha), m_blocking(blocking)
213 void initParallelSession()
const 215 m_blocking.allocateB();
223 Gemm::run(rows, cols, m_lhs.cols(),
224 &m_lhs.coeffRef(row,0), m_lhs.outerStride(),
225 &m_rhs.coeffRef(0,col), m_rhs.outerStride(),
226 (Scalar*)&(m_dest.coeffRef(row,col)), m_dest.outerStride(),
227 m_actualAlpha, m_blocking, info);
234 Scalar m_actualAlpha;
235 BlockingType& m_blocking;
238 template<
int StorageOrder,
typename LhsScalar,
typename RhsScalar,
int MaxRows,
int MaxCols,
int MaxDepth,
int KcFactor=1,
241 template<
typename _LhsScalar,
typename _RhsScalar>
244 typedef _LhsScalar LhsScalar;
245 typedef _RhsScalar RhsScalar;
259 : m_blockA(0), m_blockB(0), m_blockW(0), m_mc(0), m_nc(0), m_kc(0)
262 inline DenseIndex mc()
const {
return m_mc; }
263 inline DenseIndex nc()
const {
return m_nc; }
264 inline DenseIndex kc()
const {
return m_kc; }
266 inline LhsScalar* blockA() {
return m_blockA; }
267 inline RhsScalar* blockB() {
return m_blockB; }
268 inline RhsScalar* blockW() {
return m_blockW; }
271 template<
int StorageOrder,
typename _LhsScalar,
typename _RhsScalar,
int MaxRows,
int MaxCols,
int MaxDepth,
int KcFactor>
274 typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type,
275 typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type>
279 ActualRows =
Transpose ? MaxCols : MaxRows,
280 ActualCols =
Transpose ? MaxRows : MaxCols
286 SizeA = ActualRows * MaxDepth,
287 SizeB = ActualCols * MaxDepth,
288 SizeW = MaxDepth * Traits::WorkSpaceFactor
291 EIGEN_ALIGN16 LhsScalar m_staticA[SizeA];
292 EIGEN_ALIGN16 RhsScalar m_staticB[SizeB];
293 EIGEN_ALIGN16 RhsScalar m_staticW[SizeW];
299 this->m_mc = ActualRows;
300 this->m_nc = ActualCols;
301 this->m_kc = MaxDepth;
302 this->m_blockA = m_staticA;
303 this->m_blockB = m_staticB;
304 this->m_blockW = m_staticW;
307 inline void allocateA() {}
308 inline void allocateB() {}
309 inline void allocateW() {}
310 inline void allocateAll() {}
313 template<
int StorageOrder,
typename _LhsScalar,
typename _RhsScalar,
int MaxRows,
int MaxCols,
int MaxDepth,
int KcFactor>
316 typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type,
317 typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type>
338 computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, this->m_mc, this->m_nc);
339 m_sizeA = this->m_mc * this->m_kc;
340 m_sizeB = this->m_kc * this->m_nc;
341 m_sizeW = this->m_kc*Traits::WorkSpaceFactor;
346 if(this->m_blockA==0)
347 this->m_blockA = aligned_new<LhsScalar>(m_sizeA);
352 if(this->m_blockB==0)
353 this->m_blockB = aligned_new<RhsScalar>(m_sizeB);
358 if(this->m_blockW==0)
359 this->m_blockW = aligned_new<RhsScalar>(m_sizeW);
371 aligned_delete(this->m_blockA, m_sizeA);
372 aligned_delete(this->m_blockB, m_sizeB);
373 aligned_delete(this->m_blockW, m_sizeW);
379 template<
typename Lhs,
typename Rhs>
381 :
public ProductBase<GeneralProduct<Lhs,Rhs,GemmProduct>, Lhs, Rhs>
384 MaxDepthAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(Lhs::MaxColsAtCompileTime,Rhs::MaxRowsAtCompileTime)
391 typedef Scalar ResScalar;
395 #if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG)) 397 EIGEN_CHECK_BINARY_COMPATIBILIY(BinOp,LhsScalar,RhsScalar);
401 template<
typename Dest>
void scaleAndAddTo(Dest& dst,
const Scalar& alpha)
const 403 eigen_assert(dst.rows()==m_lhs.rows() && dst.cols()==m_rhs.cols());
404 if(m_lhs.cols()==0 || m_lhs.rows()==0 || m_rhs.cols()==0)
410 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(m_lhs)
411 * RhsBlasTraits::extractScalarFactor(m_rhs);
414 Dest::MaxRowsAtCompileTime,Dest::MaxColsAtCompileTime,MaxDepthAtCompileTime> BlockingType;
420 LhsScalar, (_ActualLhsType::Flags&
RowMajorBit) ?
RowMajor : ColMajor,
bool(LhsBlasTraits::NeedToConjugate),
421 RhsScalar, (_ActualRhsType::Flags&
RowMajorBit) ?
RowMajor : ColMajor,
bool(RhsBlasTraits::NeedToConjugate),
425 BlockingType blocking(dst.rows(), dst.cols(), lhs.cols());
427 internal::parallelize_gemm<(Dest::MaxRowsAtCompileTime>32 || Dest::MaxRowsAtCompileTime==
Dynamic)>(GemmFunctor(lhs, rhs, dst, actualAlpha, blocking), this->rows(), this->cols(), Dest::Flags&
RowMajorBit);
433 #endif // EIGEN_GENERAL_MATRIX_MATRIX_H Expression of the product of two general matrices or vectors.
Definition: GeneralProduct.h:36
Definition: GeneralBlockPanelKernel.h:1118
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
Definition: GeneralBlockPanelKernel.h:18
Definition: ProductBase.h:63
Expression of the transpose of a matrix.
Definition: Transpose.h:57
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Definition: BlasUtil.h:35
Definition: Functors.h:47
Definition: GeneralMatrixMatrix.h:17
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Definition: XprHelper.h:371
Definition: BlasUtil.h:136
Definition: GeneralBlockPanelKernel.h:514
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Definition: GeneralMatrixMatrix.h:206
Definition: GeneralMatrixMatrix.h:239
Definition: Parallelizer.h:74
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Definition: BlasUtil.h:25