10 #ifndef EIGEN_GENERAL_BLOCK_PANEL_H
11 #define EIGEN_GENERAL_BLOCK_PANEL_H
17 template<
typename _LhsScalar,
typename _RhsScalar,
bool _ConjLhs=false,
bool _ConjRhs=false>
22 inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b)
28 inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdiff_t* l2=0)
30 static std::ptrdiff_t m_l1CacheSize = 0;
31 static std::ptrdiff_t m_l2CacheSize = 0;
34 m_l1CacheSize = manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
35 m_l2CacheSize = manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
41 eigen_internal_assert(l1!=0 && l2!=0);
45 else if(action==GetAction)
47 eigen_internal_assert(l1!=0 && l2!=0);
53 eigen_internal_assert(
false);
72 template<
typename LhsScalar,
typename RhsScalar,
int KcFactor,
typename SizeType>
75 EIGEN_UNUSED_VARIABLE(n);
83 std::ptrdiff_t l1, l2;
85 typedef gebp_traits<LhsScalar,RhsScalar> Traits;
87 kdiv = KcFactor * 2 * Traits::nr
88 * Traits::RhsProgress *
sizeof(RhsScalar),
89 mr = gebp_traits<LhsScalar,RhsScalar>::mr,
90 mr_mask = (0xffffffff/mr)*mr
93 manage_caching_sizes(GetAction, &l1, &l2);
94 k = std::min<SizeType>(k, l1/kdiv);
95 SizeType _m = k>0 ? l2/(4 *
sizeof(LhsScalar) * k) : 0;
96 if(_m<m) m = _m & mr_mask;
99 template<
typename LhsScalar,
typename RhsScalar,
typename SizeType>
102 computeProductBlockingSizes<LhsScalar,RhsScalar,1>(k, m, n);
105 #ifdef EIGEN_HAS_FUSE_CJMADD
106 #define MADD(CJ,A,B,C,T) C = CJ.pmadd(A,B,C);
111 template<
typename CJ,
typename A,
typename B,
typename C,
typename T>
struct gebp_madd_selector {
112 EIGEN_ALWAYS_INLINE
static void run(
const CJ& cj, A& a, B& b, C& c, T& )
118 template<
typename CJ,
typename T>
struct gebp_madd_selector<CJ,T,T,T,T> {
119 EIGEN_ALWAYS_INLINE
static void run(
const CJ& cj, T& a, T& b, T& c, T& t)
121 t = b; t = cj.pmul(a,t); c = padd(c,t);
125 template<
typename CJ,
typename A,
typename B,
typename C,
typename T>
126 EIGEN_STRONG_INLINE
void gebp_madd(
const CJ& cj, A& a, B& b, C& c, T& t)
128 gebp_madd_selector<CJ,A,B,C,T>::run(cj,a,b,c,t);
131 #define MADD(CJ,A,B,C,T) gebp_madd(CJ,A,B,C,T);
145 template<
typename _LhsScalar,
typename _RhsScalar,
bool _ConjLhs,
bool _ConjRhs>
149 typedef _LhsScalar LhsScalar;
150 typedef _RhsScalar RhsScalar;
151 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
156 Vectorizable = packet_traits<LhsScalar>::Vectorizable && packet_traits<RhsScalar>::Vectorizable,
157 LhsPacketSize = Vectorizable ? packet_traits<LhsScalar>::size : 1,
158 RhsPacketSize = Vectorizable ? packet_traits<RhsScalar>::size : 1,
159 ResPacketSize = Vectorizable ? packet_traits<ResScalar>::size : 1,
161 NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
164 nr = NumberOfRegisters/4,
167 mr = 2 * LhsPacketSize,
169 WorkSpaceFactor = nr * RhsPacketSize,
171 LhsProgress = LhsPacketSize,
172 RhsProgress = RhsPacketSize
175 typedef typename packet_traits<LhsScalar>::type _LhsPacket;
176 typedef typename packet_traits<RhsScalar>::type _RhsPacket;
177 typedef typename packet_traits<ResScalar>::type _ResPacket;
179 typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
180 typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
181 typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
183 typedef ResPacket AccPacket;
185 EIGEN_STRONG_INLINE
void initAcc(AccPacket& p)
187 p = pset1<ResPacket>(ResScalar(0));
190 EIGEN_STRONG_INLINE
void unpackRhs(DenseIndex n,
const RhsScalar* rhs, RhsScalar* b)
192 for(DenseIndex k=0; k<n; k++)
193 pstore1<RhsPacket>(&b[k*RhsPacketSize], rhs[k]);
196 EIGEN_STRONG_INLINE
void loadRhs(
const RhsScalar* b, RhsPacket& dest)
const
198 dest = pload<RhsPacket>(b);
201 EIGEN_STRONG_INLINE
void loadLhs(
const LhsScalar* a, LhsPacket& dest)
const
203 dest = pload<LhsPacket>(a);
206 EIGEN_STRONG_INLINE
void madd(
const LhsPacket& a,
const RhsPacket& b, AccPacket& c, AccPacket& tmp)
const
208 tmp = b; tmp = pmul(a,tmp); c = padd(c,tmp);
211 EIGEN_STRONG_INLINE
void acc(
const AccPacket& c,
const ResPacket& alpha, ResPacket& r)
const
213 r = pmadd(c,alpha,r);
221 template<
typename RealScalar,
bool _ConjLhs>
222 class gebp_traits<std::complex<RealScalar>, RealScalar, _ConjLhs, false>
225 typedef std::complex<RealScalar> LhsScalar;
226 typedef RealScalar RhsScalar;
227 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
232 Vectorizable = packet_traits<LhsScalar>::Vectorizable && packet_traits<RhsScalar>::Vectorizable,
233 LhsPacketSize = Vectorizable ? packet_traits<LhsScalar>::size : 1,
234 RhsPacketSize = Vectorizable ? packet_traits<RhsScalar>::size : 1,
235 ResPacketSize = Vectorizable ? packet_traits<ResScalar>::size : 1,
237 NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
238 nr = NumberOfRegisters/4,
239 mr = 2 * LhsPacketSize,
240 WorkSpaceFactor = nr*RhsPacketSize,
242 LhsProgress = LhsPacketSize,
243 RhsProgress = RhsPacketSize
246 typedef typename packet_traits<LhsScalar>::type _LhsPacket;
247 typedef typename packet_traits<RhsScalar>::type _RhsPacket;
248 typedef typename packet_traits<ResScalar>::type _ResPacket;
250 typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
251 typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
252 typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
254 typedef ResPacket AccPacket;
256 EIGEN_STRONG_INLINE
void initAcc(AccPacket& p)
258 p = pset1<ResPacket>(ResScalar(0));
261 EIGEN_STRONG_INLINE
void unpackRhs(DenseIndex n,
const RhsScalar* rhs, RhsScalar* b)
263 for(DenseIndex k=0; k<n; k++)
264 pstore1<RhsPacket>(&b[k*RhsPacketSize], rhs[k]);
267 EIGEN_STRONG_INLINE
void loadRhs(
const RhsScalar* b, RhsPacket& dest)
const
269 dest = pload<RhsPacket>(b);
272 EIGEN_STRONG_INLINE
void loadLhs(
const LhsScalar* a, LhsPacket& dest)
const
274 dest = pload<LhsPacket>(a);
277 EIGEN_STRONG_INLINE
void madd(
const LhsPacket& a,
const RhsPacket& b, AccPacket& c, RhsPacket& tmp)
const
279 madd_impl(a, b, c, tmp,
typename conditional<Vectorizable,true_type,false_type>::type());
282 EIGEN_STRONG_INLINE
void madd_impl(
const LhsPacket& a,
const RhsPacket& b, AccPacket& c, RhsPacket& tmp,
const true_type&)
const
284 tmp = b; tmp = pmul(a.v,tmp); c.v = padd(c.v,tmp);
287 EIGEN_STRONG_INLINE
void madd_impl(
const LhsScalar& a,
const RhsScalar& b, ResScalar& c, RhsScalar& ,
const false_type&)
const
292 EIGEN_STRONG_INLINE
void acc(
const AccPacket& c,
const ResPacket& alpha, ResPacket& r)
const
294 r = cj.pmadd(c,alpha,r);
298 conj_helper<ResPacket,ResPacket,ConjLhs,false> cj;
301 template<
typename RealScalar,
bool _ConjLhs,
bool _ConjRhs>
302 class gebp_traits<std::complex<RealScalar>, std::complex<RealScalar>, _ConjLhs, _ConjRhs >
305 typedef std::complex<RealScalar> Scalar;
306 typedef std::complex<RealScalar> LhsScalar;
307 typedef std::complex<RealScalar> RhsScalar;
308 typedef std::complex<RealScalar> ResScalar;
313 Vectorizable = packet_traits<RealScalar>::Vectorizable
314 && packet_traits<Scalar>::Vectorizable,
315 RealPacketSize = Vectorizable ? packet_traits<RealScalar>::size : 1,
316 ResPacketSize = Vectorizable ? packet_traits<ResScalar>::size : 1,
319 mr = 2 * ResPacketSize,
320 WorkSpaceFactor = Vectorizable ? 2*nr*RealPacketSize : nr,
322 LhsProgress = ResPacketSize,
323 RhsProgress = Vectorizable ? 2*ResPacketSize : 1
326 typedef typename packet_traits<RealScalar>::type RealPacket;
327 typedef typename packet_traits<Scalar>::type ScalarPacket;
334 typedef typename conditional<Vectorizable,RealPacket, Scalar>::type LhsPacket;
335 typedef typename conditional<Vectorizable,DoublePacket,Scalar>::type RhsPacket;
336 typedef typename conditional<Vectorizable,ScalarPacket,Scalar>::type ResPacket;
337 typedef typename conditional<Vectorizable,DoublePacket,Scalar>::type AccPacket;
339 EIGEN_STRONG_INLINE
void initAcc(Scalar& p) { p = Scalar(0); }
341 EIGEN_STRONG_INLINE
void initAcc(DoublePacket& p)
343 p.first = pset1<RealPacket>(RealScalar(0));
344 p.second = pset1<RealPacket>(RealScalar(0));
351 EIGEN_STRONG_INLINE
void unpackRhs(DenseIndex n,
const Scalar* rhs, Scalar* b)
353 for(DenseIndex k=0; k<n; k++)
357 pstore1<RealPacket>((RealScalar*)&b[k*ResPacketSize*2+0], real(rhs[k]));
358 pstore1<RealPacket>((RealScalar*)&b[k*ResPacketSize*2+ResPacketSize], imag(rhs[k]));
365 EIGEN_STRONG_INLINE
void loadRhs(
const RhsScalar* b, ResPacket& dest)
const { dest = *b; }
367 EIGEN_STRONG_INLINE
void loadRhs(
const RhsScalar* b, DoublePacket& dest)
const
369 dest.first = pload<RealPacket>((
const RealScalar*)b);
370 dest.second = pload<RealPacket>((
const RealScalar*)(b+ResPacketSize));
374 EIGEN_STRONG_INLINE
void loadLhs(
const LhsScalar* a, LhsPacket& dest)
const
376 dest = pload<LhsPacket>((
const typename unpacket_traits<LhsPacket>::type*)(a));
379 EIGEN_STRONG_INLINE
void madd(
const LhsPacket& a,
const RhsPacket& b, DoublePacket& c, RhsPacket& )
const
381 c.first = padd(pmul(a,b.first), c.first);
382 c.second = padd(pmul(a,b.second),c.second);
385 EIGEN_STRONG_INLINE
void madd(
const LhsPacket& a,
const RhsPacket& b, ResPacket& c, RhsPacket& )
const
390 EIGEN_STRONG_INLINE
void acc(
const Scalar& c,
const Scalar& alpha, Scalar& r)
const { r += alpha * c; }
392 EIGEN_STRONG_INLINE
void acc(
const DoublePacket& c,
const ResPacket& alpha, ResPacket& r)
const
396 if((!ConjLhs)&&(!ConjRhs))
398 tmp = pcplxflip(pconj(ResPacket(c.second)));
399 tmp = padd(ResPacket(c.first),tmp);
401 else if((!ConjLhs)&&(ConjRhs))
403 tmp = pconj(pcplxflip(ResPacket(c.second)));
404 tmp = padd(ResPacket(c.first),tmp);
406 else if((ConjLhs)&&(!ConjRhs))
408 tmp = pcplxflip(ResPacket(c.second));
409 tmp = padd(pconj(ResPacket(c.first)),tmp);
411 else if((ConjLhs)&&(ConjRhs))
413 tmp = pcplxflip(ResPacket(c.second));
414 tmp = psub(pconj(ResPacket(c.first)),tmp);
417 r = pmadd(tmp,alpha,r);
421 conj_helper<LhsScalar,RhsScalar,ConjLhs,ConjRhs> cj;
424 template<
typename RealScalar,
bool _ConjRhs>
425 class gebp_traits<RealScalar, std::complex<RealScalar>, false, _ConjRhs >
428 typedef std::complex<RealScalar> Scalar;
429 typedef RealScalar LhsScalar;
430 typedef Scalar RhsScalar;
431 typedef Scalar ResScalar;
436 Vectorizable = packet_traits<RealScalar>::Vectorizable
437 && packet_traits<Scalar>::Vectorizable,
438 LhsPacketSize = Vectorizable ? packet_traits<LhsScalar>::size : 1,
439 RhsPacketSize = Vectorizable ? packet_traits<RhsScalar>::size : 1,
440 ResPacketSize = Vectorizable ? packet_traits<ResScalar>::size : 1,
442 NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
444 mr = 2*ResPacketSize,
445 WorkSpaceFactor = nr*RhsPacketSize,
447 LhsProgress = ResPacketSize,
448 RhsProgress = ResPacketSize
451 typedef typename packet_traits<LhsScalar>::type _LhsPacket;
452 typedef typename packet_traits<RhsScalar>::type _RhsPacket;
453 typedef typename packet_traits<ResScalar>::type _ResPacket;
455 typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
456 typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
457 typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
459 typedef ResPacket AccPacket;
461 EIGEN_STRONG_INLINE
void initAcc(AccPacket& p)
463 p = pset1<ResPacket>(ResScalar(0));
466 EIGEN_STRONG_INLINE
void unpackRhs(DenseIndex n,
const RhsScalar* rhs, RhsScalar* b)
468 for(DenseIndex k=0; k<n; k++)
469 pstore1<RhsPacket>(&b[k*RhsPacketSize], rhs[k]);
472 EIGEN_STRONG_INLINE
void loadRhs(
const RhsScalar* b, RhsPacket& dest)
const
474 dest = pload<RhsPacket>(b);
477 EIGEN_STRONG_INLINE
void loadLhs(
const LhsScalar* a, LhsPacket& dest)
const
479 dest = ploaddup<LhsPacket>(a);
482 EIGEN_STRONG_INLINE
void madd(
const LhsPacket& a,
const RhsPacket& b, AccPacket& c, RhsPacket& tmp)
const
484 madd_impl(a, b, c, tmp,
typename conditional<Vectorizable,true_type,false_type>::type());
487 EIGEN_STRONG_INLINE
void madd_impl(
const LhsPacket& a,
const RhsPacket& b, AccPacket& c, RhsPacket& tmp,
const true_type&)
const
489 tmp = b; tmp.v = pmul(a,tmp.v); c = padd(c,tmp);
492 EIGEN_STRONG_INLINE
void madd_impl(
const LhsScalar& a,
const RhsScalar& b, ResScalar& c, RhsScalar& ,
const false_type&)
const
497 EIGEN_STRONG_INLINE
void acc(
const AccPacket& c,
const ResPacket& alpha, ResPacket& r)
const
499 r = cj.pmadd(alpha,c,r);
503 conj_helper<ResPacket,ResPacket,false,ConjRhs> cj;
513 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjugateLhs,
bool ConjugateRhs>
516 typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> Traits;
517 typedef typename Traits::ResScalar ResScalar;
518 typedef typename Traits::LhsPacket LhsPacket;
519 typedef typename Traits::RhsPacket RhsPacket;
520 typedef typename Traits::ResPacket ResPacket;
521 typedef typename Traits::AccPacket AccPacket;
524 Vectorizable = Traits::Vectorizable,
525 LhsProgress = Traits::LhsProgress,
526 RhsProgress = Traits::RhsProgress,
527 ResPacketSize = Traits::ResPacketSize
531 void operator()(ResScalar* res, Index resStride,
const LhsScalar* blockA,
const RhsScalar* blockB, Index rows, Index depth, Index cols, ResScalar alpha,
532 Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0, RhsScalar* unpackedB=0);
535 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjugateLhs,
bool ConjugateRhs>
537 void gebp_kernel<LhsScalar,RhsScalar,Index,mr,nr,ConjugateLhs,ConjugateRhs>
538 ::operator()(ResScalar* res, Index resStride,
const LhsScalar* blockA,
const RhsScalar* blockB, Index rows, Index depth, Index cols, ResScalar alpha,
539 Index strideA, Index strideB, Index offsetA, Index offsetB, RhsScalar* unpackedB)
543 if(strideA==-1) strideA = depth;
544 if(strideB==-1) strideB = depth;
545 conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj;
547 Index packet_cols = (cols/nr) * nr;
548 const Index peeled_mc = (rows/mr)*mr;
550 const Index peeled_mc2 = peeled_mc + (rows-peeled_mc >= LhsProgress ? LhsProgress : 0);
551 const Index peeled_kc = (depth/4)*4;
554 unpackedB =
const_cast<RhsScalar*
>(blockB - strideB * nr * RhsProgress);
557 for(Index j2=0; j2<packet_cols; j2+=nr)
559 traits.unpackRhs(depth*nr,&blockB[j2*strideB+offsetB*nr],unpackedB);
564 for(Index i=0; i<peeled_mc; i+=mr)
566 const LhsScalar* blA = &blockA[i*strideA+offsetA*mr];
570 AccPacket C0, C1, C2, C3, C4, C5, C6, C7;
573 if(nr==4) traits.initAcc(C2);
574 if(nr==4) traits.initAcc(C3);
577 if(nr==4) traits.initAcc(C6);
578 if(nr==4) traits.initAcc(C7);
580 ResScalar* r0 = &res[(j2+0)*resStride + i];
581 ResScalar* r1 = r0 + resStride;
582 ResScalar* r2 = r1 + resStride;
583 ResScalar* r3 = r2 + resStride;
593 const RhsScalar* blB = unpackedB;
594 for(Index k=0; k<peeled_kc; k+=4)
602 EIGEN_ASM_COMMENT(
"mybegin2");
603 traits.loadLhs(&blA[0*LhsProgress], A0);
604 traits.loadLhs(&blA[1*LhsProgress], A1);
605 traits.loadRhs(&blB[0*RhsProgress], B_0);
606 traits.madd(A0,B_0,C0,T0);
607 traits.madd(A1,B_0,C4,B_0);
608 traits.loadRhs(&blB[1*RhsProgress], B_0);
609 traits.madd(A0,B_0,C1,T0);
610 traits.madd(A1,B_0,C5,B_0);
612 traits.loadLhs(&blA[2*LhsProgress], A0);
613 traits.loadLhs(&blA[3*LhsProgress], A1);
614 traits.loadRhs(&blB[2*RhsProgress], B_0);
615 traits.madd(A0,B_0,C0,T0);
616 traits.madd(A1,B_0,C4,B_0);
617 traits.loadRhs(&blB[3*RhsProgress], B_0);
618 traits.madd(A0,B_0,C1,T0);
619 traits.madd(A1,B_0,C5,B_0);
621 traits.loadLhs(&blA[4*LhsProgress], A0);
622 traits.loadLhs(&blA[5*LhsProgress], A1);
623 traits.loadRhs(&blB[4*RhsProgress], B_0);
624 traits.madd(A0,B_0,C0,T0);
625 traits.madd(A1,B_0,C4,B_0);
626 traits.loadRhs(&blB[5*RhsProgress], B_0);
627 traits.madd(A0,B_0,C1,T0);
628 traits.madd(A1,B_0,C5,B_0);
630 traits.loadLhs(&blA[6*LhsProgress], A0);
631 traits.loadLhs(&blA[7*LhsProgress], A1);
632 traits.loadRhs(&blB[6*RhsProgress], B_0);
633 traits.madd(A0,B_0,C0,T0);
634 traits.madd(A1,B_0,C4,B_0);
635 traits.loadRhs(&blB[7*RhsProgress], B_0);
636 traits.madd(A0,B_0,C1,T0);
637 traits.madd(A1,B_0,C5,B_0);
638 EIGEN_ASM_COMMENT(
"myend");
642 EIGEN_ASM_COMMENT(
"mybegin4");
644 RhsPacket B_0, B1, B2, B3;
647 traits.loadLhs(&blA[0*LhsProgress], A0);
648 traits.loadLhs(&blA[1*LhsProgress], A1);
649 traits.loadRhs(&blB[0*RhsProgress], B_0);
650 traits.loadRhs(&blB[1*RhsProgress], B1);
652 traits.madd(A0,B_0,C0,T0);
653 traits.loadRhs(&blB[2*RhsProgress], B2);
654 traits.madd(A1,B_0,C4,B_0);
655 traits.loadRhs(&blB[3*RhsProgress], B3);
656 traits.loadRhs(&blB[4*RhsProgress], B_0);
657 traits.madd(A0,B1,C1,T0);
658 traits.madd(A1,B1,C5,B1);
659 traits.loadRhs(&blB[5*RhsProgress], B1);
660 traits.madd(A0,B2,C2,T0);
661 traits.madd(A1,B2,C6,B2);
662 traits.loadRhs(&blB[6*RhsProgress], B2);
663 traits.madd(A0,B3,C3,T0);
664 traits.loadLhs(&blA[2*LhsProgress], A0);
665 traits.madd(A1,B3,C7,B3);
666 traits.loadLhs(&blA[3*LhsProgress], A1);
667 traits.loadRhs(&blB[7*RhsProgress], B3);
668 traits.madd(A0,B_0,C0,T0);
669 traits.madd(A1,B_0,C4,B_0);
670 traits.loadRhs(&blB[8*RhsProgress], B_0);
671 traits.madd(A0,B1,C1,T0);
672 traits.madd(A1,B1,C5,B1);
673 traits.loadRhs(&blB[9*RhsProgress], B1);
674 traits.madd(A0,B2,C2,T0);
675 traits.madd(A1,B2,C6,B2);
676 traits.loadRhs(&blB[10*RhsProgress], B2);
677 traits.madd(A0,B3,C3,T0);
678 traits.loadLhs(&blA[4*LhsProgress], A0);
679 traits.madd(A1,B3,C7,B3);
680 traits.loadLhs(&blA[5*LhsProgress], A1);
681 traits.loadRhs(&blB[11*RhsProgress], B3);
683 traits.madd(A0,B_0,C0,T0);
684 traits.madd(A1,B_0,C4,B_0);
685 traits.loadRhs(&blB[12*RhsProgress], B_0);
686 traits.madd(A0,B1,C1,T0);
687 traits.madd(A1,B1,C5,B1);
688 traits.loadRhs(&blB[13*RhsProgress], B1);
689 traits.madd(A0,B2,C2,T0);
690 traits.madd(A1,B2,C6,B2);
691 traits.loadRhs(&blB[14*RhsProgress], B2);
692 traits.madd(A0,B3,C3,T0);
693 traits.loadLhs(&blA[6*LhsProgress], A0);
694 traits.madd(A1,B3,C7,B3);
695 traits.loadLhs(&blA[7*LhsProgress], A1);
696 traits.loadRhs(&blB[15*RhsProgress], B3);
697 traits.madd(A0,B_0,C0,T0);
698 traits.madd(A1,B_0,C4,B_0);
699 traits.madd(A0,B1,C1,T0);
700 traits.madd(A1,B1,C5,B1);
701 traits.madd(A0,B2,C2,T0);
702 traits.madd(A1,B2,C6,B2);
703 traits.madd(A0,B3,C3,T0);
704 traits.madd(A1,B3,C7,B3);
707 blB += 4*nr*RhsProgress;
711 for(Index k=peeled_kc; k<depth; k++)
719 traits.loadLhs(&blA[0*LhsProgress], A0);
720 traits.loadLhs(&blA[1*LhsProgress], A1);
721 traits.loadRhs(&blB[0*RhsProgress], B_0);
722 traits.madd(A0,B_0,C0,T0);
723 traits.madd(A1,B_0,C4,B_0);
724 traits.loadRhs(&blB[1*RhsProgress], B_0);
725 traits.madd(A0,B_0,C1,T0);
726 traits.madd(A1,B_0,C5,B_0);
731 RhsPacket B_0, B1, B2, B3;
734 traits.loadLhs(&blA[0*LhsProgress], A0);
735 traits.loadLhs(&blA[1*LhsProgress], A1);
736 traits.loadRhs(&blB[0*RhsProgress], B_0);
737 traits.loadRhs(&blB[1*RhsProgress], B1);
739 traits.madd(A0,B_0,C0,T0);
740 traits.loadRhs(&blB[2*RhsProgress], B2);
741 traits.madd(A1,B_0,C4,B_0);
742 traits.loadRhs(&blB[3*RhsProgress], B3);
743 traits.madd(A0,B1,C1,T0);
744 traits.madd(A1,B1,C5,B1);
745 traits.madd(A0,B2,C2,T0);
746 traits.madd(A1,B2,C6,B2);
747 traits.madd(A0,B3,C3,T0);
748 traits.madd(A1,B3,C7,B3);
751 blB += nr*RhsProgress;
757 ResPacket R0, R1, R2, R3, R4, R5, R6;
758 ResPacket alphav = pset1<ResPacket>(alpha);
760 R0 = ploadu<ResPacket>(r0);
761 R1 = ploadu<ResPacket>(r1);
762 R2 = ploadu<ResPacket>(r2);
763 R3 = ploadu<ResPacket>(r3);
764 R4 = ploadu<ResPacket>(r0 + ResPacketSize);
765 R5 = ploadu<ResPacket>(r1 + ResPacketSize);
766 R6 = ploadu<ResPacket>(r2 + ResPacketSize);
767 traits.acc(C0, alphav, R0);
769 R0 = ploadu<ResPacket>(r3 + ResPacketSize);
771 traits.acc(C1, alphav, R1);
772 traits.acc(C2, alphav, R2);
773 traits.acc(C3, alphav, R3);
774 traits.acc(C4, alphav, R4);
775 traits.acc(C5, alphav, R5);
776 traits.acc(C6, alphav, R6);
777 traits.acc(C7, alphav, R0);
782 pstoreu(r0 + ResPacketSize, R4);
783 pstoreu(r1 + ResPacketSize, R5);
784 pstoreu(r2 + ResPacketSize, R6);
785 pstoreu(r3 + ResPacketSize, R0);
789 ResPacket R0, R1, R4;
790 ResPacket alphav = pset1<ResPacket>(alpha);
792 R0 = ploadu<ResPacket>(r0);
793 R1 = ploadu<ResPacket>(r1);
794 R4 = ploadu<ResPacket>(r0 + ResPacketSize);
795 traits.acc(C0, alphav, R0);
797 R0 = ploadu<ResPacket>(r1 + ResPacketSize);
798 traits.acc(C1, alphav, R1);
799 traits.acc(C4, alphav, R4);
800 traits.acc(C5, alphav, R0);
802 pstoreu(r0 + ResPacketSize, R4);
803 pstoreu(r1 + ResPacketSize, R0);
808 if(rows-peeled_mc>=LhsProgress)
811 const LhsScalar* blA = &blockA[i*strideA+offsetA*LhsProgress];
815 AccPacket C0, C1, C2, C3;
818 if(nr==4) traits.initAcc(C2);
819 if(nr==4) traits.initAcc(C3);
822 const RhsScalar* blB = unpackedB;
823 for(Index k=0; k<peeled_kc; k+=4)
830 traits.loadLhs(&blA[0*LhsProgress], A0);
831 traits.loadRhs(&blB[0*RhsProgress], B_0);
832 traits.loadRhs(&blB[1*RhsProgress], B1);
833 traits.madd(A0,B_0,C0,B_0);
834 traits.loadRhs(&blB[2*RhsProgress], B_0);
835 traits.madd(A0,B1,C1,B1);
836 traits.loadLhs(&blA[1*LhsProgress], A0);
837 traits.loadRhs(&blB[3*RhsProgress], B1);
838 traits.madd(A0,B_0,C0,B_0);
839 traits.loadRhs(&blB[4*RhsProgress], B_0);
840 traits.madd(A0,B1,C1,B1);
841 traits.loadLhs(&blA[2*LhsProgress], A0);
842 traits.loadRhs(&blB[5*RhsProgress], B1);
843 traits.madd(A0,B_0,C0,B_0);
844 traits.loadRhs(&blB[6*RhsProgress], B_0);
845 traits.madd(A0,B1,C1,B1);
846 traits.loadLhs(&blA[3*LhsProgress], A0);
847 traits.loadRhs(&blB[7*RhsProgress], B1);
848 traits.madd(A0,B_0,C0,B_0);
849 traits.madd(A0,B1,C1,B1);
854 RhsPacket B_0, B1, B2, B3;
856 traits.loadLhs(&blA[0*LhsProgress], A0);
857 traits.loadRhs(&blB[0*RhsProgress], B_0);
858 traits.loadRhs(&blB[1*RhsProgress], B1);
860 traits.madd(A0,B_0,C0,B_0);
861 traits.loadRhs(&blB[2*RhsProgress], B2);
862 traits.loadRhs(&blB[3*RhsProgress], B3);
863 traits.loadRhs(&blB[4*RhsProgress], B_0);
864 traits.madd(A0,B1,C1,B1);
865 traits.loadRhs(&blB[5*RhsProgress], B1);
866 traits.madd(A0,B2,C2,B2);
867 traits.loadRhs(&blB[6*RhsProgress], B2);
868 traits.madd(A0,B3,C3,B3);
869 traits.loadLhs(&blA[1*LhsProgress], A0);
870 traits.loadRhs(&blB[7*RhsProgress], B3);
871 traits.madd(A0,B_0,C0,B_0);
872 traits.loadRhs(&blB[8*RhsProgress], B_0);
873 traits.madd(A0,B1,C1,B1);
874 traits.loadRhs(&blB[9*RhsProgress], B1);
875 traits.madd(A0,B2,C2,B2);
876 traits.loadRhs(&blB[10*RhsProgress], B2);
877 traits.madd(A0,B3,C3,B3);
878 traits.loadLhs(&blA[2*LhsProgress], A0);
879 traits.loadRhs(&blB[11*RhsProgress], B3);
881 traits.madd(A0,B_0,C0,B_0);
882 traits.loadRhs(&blB[12*RhsProgress], B_0);
883 traits.madd(A0,B1,C1,B1);
884 traits.loadRhs(&blB[13*RhsProgress], B1);
885 traits.madd(A0,B2,C2,B2);
886 traits.loadRhs(&blB[14*RhsProgress], B2);
887 traits.madd(A0,B3,C3,B3);
889 traits.loadLhs(&blA[3*LhsProgress], A0);
890 traits.loadRhs(&blB[15*RhsProgress], B3);
891 traits.madd(A0,B_0,C0,B_0);
892 traits.madd(A0,B1,C1,B1);
893 traits.madd(A0,B2,C2,B2);
894 traits.madd(A0,B3,C3,B3);
897 blB += nr*4*RhsProgress;
898 blA += 4*LhsProgress;
901 for(Index k=peeled_kc; k<depth; k++)
908 traits.loadLhs(&blA[0*LhsProgress], A0);
909 traits.loadRhs(&blB[0*RhsProgress], B_0);
910 traits.loadRhs(&blB[1*RhsProgress], B1);
911 traits.madd(A0,B_0,C0,B_0);
912 traits.madd(A0,B1,C1,B1);
917 RhsPacket B_0, B1, B2, B3;
919 traits.loadLhs(&blA[0*LhsProgress], A0);
920 traits.loadRhs(&blB[0*RhsProgress], B_0);
921 traits.loadRhs(&blB[1*RhsProgress], B1);
922 traits.loadRhs(&blB[2*RhsProgress], B2);
923 traits.loadRhs(&blB[3*RhsProgress], B3);
925 traits.madd(A0,B_0,C0,B_0);
926 traits.madd(A0,B1,C1,B1);
927 traits.madd(A0,B2,C2,B2);
928 traits.madd(A0,B3,C3,B3);
931 blB += nr*RhsProgress;
935 ResPacket R0, R1, R2, R3;
936 ResPacket alphav = pset1<ResPacket>(alpha);
938 ResScalar* r0 = &res[(j2+0)*resStride + i];
939 ResScalar* r1 = r0 + resStride;
940 ResScalar* r2 = r1 + resStride;
941 ResScalar* r3 = r2 + resStride;
943 R0 = ploadu<ResPacket>(r0);
944 R1 = ploadu<ResPacket>(r1);
945 if(nr==4) R2 = ploadu<ResPacket>(r2);
946 if(nr==4) R3 = ploadu<ResPacket>(r3);
948 traits.acc(C0, alphav, R0);
949 traits.acc(C1, alphav, R1);
950 if(nr==4) traits.acc(C2, alphav, R2);
951 if(nr==4) traits.acc(C3, alphav, R3);
955 if(nr==4) pstoreu(r2, R2);
956 if(nr==4) pstoreu(r3, R3);
958 for(Index i=peeled_mc2; i<rows; i++)
960 const LhsScalar* blA = &blockA[i*strideA+offsetA];
964 ResScalar C0(0), C1(0), C2(0), C3(0);
966 const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr];
967 for(Index k=0; k<depth; k++)
977 MADD(cj,A0,B_0,C0,B_0);
978 MADD(cj,A0,B1,C1,B1);
983 RhsScalar B_0, B1, B2, B3;
991 MADD(cj,A0,B_0,C0,B_0);
992 MADD(cj,A0,B1,C1,B1);
993 MADD(cj,A0,B2,C2,B2);
994 MADD(cj,A0,B3,C3,B3);
999 res[(j2+0)*resStride + i] += alpha*C0;
1000 res[(j2+1)*resStride + i] += alpha*C1;
1001 if(nr==4) res[(j2+2)*resStride + i] += alpha*C2;
1002 if(nr==4) res[(j2+3)*resStride + i] += alpha*C3;
1007 for(Index j2=packet_cols; j2<cols; j2++)
1010 traits.unpackRhs(depth, &blockB[j2*strideB+offsetB], unpackedB);
1012 for(Index i=0; i<peeled_mc; i+=mr)
1014 const LhsScalar* blA = &blockA[i*strideA+offsetA*mr];
1024 const RhsScalar* blB = unpackedB;
1025 for(Index k=0; k<depth; k++)
1031 traits.loadLhs(&blA[0*LhsProgress], A0);
1032 traits.loadLhs(&blA[1*LhsProgress], A1);
1033 traits.loadRhs(&blB[0*RhsProgress], B_0);
1034 traits.madd(A0,B_0,C0,T0);
1035 traits.madd(A1,B_0,C4,B_0);
1038 blA += 2*LhsProgress;
1041 ResPacket alphav = pset1<ResPacket>(alpha);
1043 ResScalar* r0 = &res[(j2+0)*resStride + i];
1045 R0 = ploadu<ResPacket>(r0);
1046 R4 = ploadu<ResPacket>(r0+ResPacketSize);
1048 traits.acc(C0, alphav, R0);
1049 traits.acc(C4, alphav, R4);
1052 pstoreu(r0+ResPacketSize, R4);
1054 if(rows-peeled_mc>=LhsProgress)
1056 Index i = peeled_mc;
1057 const LhsScalar* blA = &blockA[i*strideA+offsetA*LhsProgress];
1063 const RhsScalar* blB = unpackedB;
1064 for(Index k=0; k<depth; k++)
1068 traits.loadLhs(blA, A0);
1069 traits.loadRhs(blB, B_0);
1070 traits.madd(A0, B_0, C0, B_0);
1075 ResPacket alphav = pset1<ResPacket>(alpha);
1076 ResPacket R0 = ploadu<ResPacket>(&res[(j2+0)*resStride + i]);
1077 traits.acc(C0, alphav, R0);
1078 pstoreu(&res[(j2+0)*resStride + i], R0);
1080 for(Index i=peeled_mc2; i<rows; i++)
1082 const LhsScalar* blA = &blockA[i*strideA+offsetA];
1088 const RhsScalar* blB = &blockB[j2*strideB+offsetB];
1089 for(Index k=0; k<depth; k++)
1091 LhsScalar A0 = blA[k];
1092 RhsScalar B_0 = blB[k];
1093 MADD(cj, A0, B_0, C0, B_0);
1095 res[(j2+0)*resStride + i] += alpha*C0;
1117 template<
typename Scalar,
typename Index,
int Pack1,
int Pack2,
int StorageOrder,
bool Conjugate,
bool PanelMode>
1118 struct gemm_pack_lhs
1120 EIGEN_DONT_INLINE
void operator()(Scalar* blockA,
const Scalar* EIGEN_RESTRICT _lhs, Index lhsStride, Index depth, Index rows, Index stride=0, Index offset=0);
1123 template<
typename Scalar,
typename Index,
int Pack1,
int Pack2,
int StorageOrder,
bool Conjugate,
bool PanelMode>
1124 EIGEN_DONT_INLINE
void gemm_pack_lhs<Scalar, Index, Pack1, Pack2, StorageOrder, Conjugate, PanelMode>
1125 ::operator()(Scalar* blockA,
const Scalar* EIGEN_RESTRICT _lhs, Index lhsStride, Index depth, Index rows, Index stride, Index offset)
1127 typedef typename packet_traits<Scalar>::type Packet;
1128 enum { PacketSize = packet_traits<Scalar>::size };
1130 EIGEN_ASM_COMMENT(
"EIGEN PRODUCT PACK LHS");
1131 EIGEN_UNUSED_VARIABLE(stride)
1132 EIGEN_UNUSED_VARIABLE(offset)
1133 eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
1134 eigen_assert( (StorageOrder==
RowMajor) || ((Pack1%PacketSize)==0 && Pack1<=4*PacketSize) );
1135 conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
1136 const_blas_data_mapper<Scalar, Index, StorageOrder> lhs(_lhs,lhsStride);
1138 Index peeled_mc = (rows/Pack1)*Pack1;
1139 for(Index i=0; i<peeled_mc; i+=Pack1)
1141 if(PanelMode) count += Pack1 * offset;
1145 for(Index k=0; k<depth; k++)
1148 if(Pack1>=1*PacketSize) A = ploadu<Packet>(&lhs(i+0*PacketSize, k));
1149 if(Pack1>=2*PacketSize) B = ploadu<Packet>(&lhs(i+1*PacketSize, k));
1150 if(Pack1>=3*PacketSize) C = ploadu<Packet>(&lhs(i+2*PacketSize, k));
1151 if(Pack1>=4*PacketSize) D = ploadu<Packet>(&lhs(i+3*PacketSize, k));
1152 if(Pack1>=1*PacketSize) { pstore(blockA+count, cj.pconj(A)); count+=PacketSize; }
1153 if(Pack1>=2*PacketSize) { pstore(blockA+count, cj.pconj(B)); count+=PacketSize; }
1154 if(Pack1>=3*PacketSize) { pstore(blockA+count, cj.pconj(C)); count+=PacketSize; }
1155 if(Pack1>=4*PacketSize) { pstore(blockA+count, cj.pconj(D)); count+=PacketSize; }
1160 for(Index k=0; k<depth; k++)
1164 for(; w<Pack1-3; w+=4)
1166 Scalar a(cj(lhs(i+w+0, k))),
1167 b(cj(lhs(i+w+1, k))),
1168 c(cj(lhs(i+w+2, k))),
1169 d(cj(lhs(i+w+3, k)));
1170 blockA[count++] = a;
1171 blockA[count++] = b;
1172 blockA[count++] = c;
1173 blockA[count++] = d;
1177 blockA[count++] = cj(lhs(i+w, k));
1180 if(PanelMode) count += Pack1 * (stride-offset-depth);
1182 if(rows-peeled_mc>=Pack2)
1184 if(PanelMode) count += Pack2*offset;
1185 for(Index k=0; k<depth; k++)
1186 for(Index w=0; w<Pack2; w++)
1187 blockA[count++] = cj(lhs(peeled_mc+w, k));
1188 if(PanelMode) count += Pack2 * (stride-offset-depth);
1191 for(Index i=peeled_mc; i<rows; i++)
1193 if(PanelMode) count += offset;
1194 for(Index k=0; k<depth; k++)
1195 blockA[count++] = cj(lhs(i, k));
1196 if(PanelMode) count += (stride-offset-depth);
1207 template<
typename Scalar,
typename Index,
int nr,
bool Conjugate,
bool PanelMode>
1208 struct gemm_pack_rhs<Scalar, Index, nr,
ColMajor, Conjugate, PanelMode>
1210 typedef typename packet_traits<Scalar>::type Packet;
1211 enum { PacketSize = packet_traits<Scalar>::size };
1212 EIGEN_DONT_INLINE
void operator()(Scalar* blockB,
const Scalar* rhs, Index rhsStride, Index depth, Index cols, Index stride=0, Index offset=0);
1215 template<
typename Scalar,
typename Index,
int nr,
bool Conjugate,
bool PanelMode>
1216 EIGEN_DONT_INLINE
void gemm_pack_rhs<Scalar, Index, nr, ColMajor, Conjugate, PanelMode>
1217 ::operator()(Scalar* blockB,
const Scalar* rhs, Index rhsStride, Index depth, Index cols, Index stride, Index offset)
1219 EIGEN_ASM_COMMENT(
"EIGEN PRODUCT PACK RHS COLMAJOR");
1220 EIGEN_UNUSED_VARIABLE(stride)
1221 EIGEN_UNUSED_VARIABLE(offset)
1222 eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
1223 conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
1224 Index packet_cols = (cols/nr) * nr;
1226 for(Index j2=0; j2<packet_cols; j2+=nr)
1229 if(PanelMode) count += nr * offset;
1230 const Scalar* b0 = &rhs[(j2+0)*rhsStride];
1231 const Scalar* b1 = &rhs[(j2+1)*rhsStride];
1232 const Scalar* b2 = &rhs[(j2+2)*rhsStride];
1233 const Scalar* b3 = &rhs[(j2+3)*rhsStride];
1234 for(Index k=0; k<depth; k++)
1236 blockB[count+0] = cj(b0[k]);
1237 blockB[count+1] = cj(b1[k]);
1238 if(nr==4) blockB[count+2] = cj(b2[k]);
1239 if(nr==4) blockB[count+3] = cj(b3[k]);
1243 if(PanelMode) count += nr * (stride-offset-depth);
1247 for(Index j2=packet_cols; j2<cols; ++j2)
1249 if(PanelMode) count += offset;
1250 const Scalar* b0 = &rhs[(j2+0)*rhsStride];
1251 for(Index k=0; k<depth; k++)
1253 blockB[count] = cj(b0[k]);
1256 if(PanelMode) count += (stride-offset-depth);
1261 template<
typename Scalar,
typename Index,
int nr,
bool Conjugate,
bool PanelMode>
1262 struct gemm_pack_rhs<Scalar, Index, nr,
RowMajor, Conjugate, PanelMode>
1264 enum { PacketSize = packet_traits<Scalar>::size };
1265 EIGEN_DONT_INLINE
void operator()(Scalar* blockB,
const Scalar* rhs, Index rhsStride, Index depth, Index cols, Index stride=0, Index offset=0);
1268 template<
typename Scalar,
typename Index,
int nr,
bool Conjugate,
bool PanelMode>
1269 EIGEN_DONT_INLINE
void gemm_pack_rhs<Scalar, Index, nr, RowMajor, Conjugate, PanelMode>
1270 ::operator()(Scalar* blockB,
const Scalar* rhs, Index rhsStride, Index depth, Index cols, Index stride, Index offset)
1272 EIGEN_ASM_COMMENT(
"EIGEN PRODUCT PACK RHS ROWMAJOR");
1273 EIGEN_UNUSED_VARIABLE(stride)
1274 EIGEN_UNUSED_VARIABLE(offset)
1275 eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
1276 conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
1277 Index packet_cols = (cols/nr) * nr;
1279 for(Index j2=0; j2<packet_cols; j2+=nr)
1282 if(PanelMode) count += nr * offset;
1283 for(Index k=0; k<depth; k++)
1285 const Scalar* b0 = &rhs[k*rhsStride + j2];
1286 blockB[count+0] = cj(b0[0]);
1287 blockB[count+1] = cj(b0[1]);
1288 if(nr==4) blockB[count+2] = cj(b0[2]);
1289 if(nr==4) blockB[count+3] = cj(b0[3]);
1293 if(PanelMode) count += nr * (stride-offset-depth);
1296 for(Index j2=packet_cols; j2<cols; ++j2)
1298 if(PanelMode) count += offset;
1299 const Scalar* b0 = &rhs[j2];
1300 for(Index k=0; k<depth; k++)
1302 blockB[count] = cj(b0[k*rhsStride]);
1305 if(PanelMode) count += stride-offset-depth;
1315 std::ptrdiff_t l1, l2;
1316 internal::manage_caching_sizes(GetAction, &l1, &l2);
1324 std::ptrdiff_t l1, l2;
1325 internal::manage_caching_sizes(GetAction, &l1, &l2);
1336 internal::manage_caching_sizes(SetAction, &l1, &l2);
1341 #endif // EIGEN_GENERAL_BLOCK_PANEL_H
void computeProductBlockingSizes(SizeType &k, SizeType &m, SizeType &n)
Computes the blocking parameters for a m x k times k x n matrix product.
Definition: GeneralBlockPanelKernel.h:73
Definition: Constants.h:264
std::ptrdiff_t l2CacheSize()
Definition: GeneralBlockPanelKernel.h:1322
void setCpuCacheSizes(std::ptrdiff_t l1, std::ptrdiff_t l2)
Definition: GeneralBlockPanelKernel.h:1334
Definition: Constants.h:266
std::ptrdiff_t l1CacheSize()
Definition: GeneralBlockPanelKernel.h:1313