Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-12 05:47:32

0001 #ifndef RecoTracker_MkFitCore_src_MatriplexPackers_h
0002 #define RecoTracker_MkFitCore_src_MatriplexPackers_h
0003 
0004 #include "Matrix.h"
0005 
0006 #include "RecoTracker/MkFitCore/interface/Hit.h"
0007 #include "RecoTracker/MkFitCore/interface/Track.h"
0008 
0009 namespace mkfit {
0010 
0011   //==============================================================================
0012   // MatriplexPackerSlurpIn
0013   //==============================================================================
0014 
0015   template <typename D>
0016   class MatriplexPackerSlurpIn {
0017   protected:
0018     alignas(64) int m_idx[NN];
0019 
0020     const D* m_base;
0021     int m_pos;
0022 
0023   public:
0024     MatriplexPackerSlurpIn(const D* base) : m_base(base), m_pos(0) {}
0025 
0026     void reset() { m_pos = 0; }
0027 
0028     void addNullInput() { m_idx[m_pos++] = 0; }
0029 
0030     void addInput(const D& item) {
0031       // Could issue prefetch requests here.
0032 
0033       m_idx[m_pos] = &item - m_base;
0034 
0035       ++m_pos;
0036     }
0037 
0038     void addInputAt(int pos, const D& item) {
0039       while (m_pos < pos) {
0040         // We might not care about initialization / reset to 0.
0041         // Or we could be building an additional mask (on top of N_proc).
0042         m_idx[m_pos++] = 0;
0043       }
0044 
0045       addInput(item);
0046     }
0047 
0048     template <typename TM>
0049     void pack(TM& mplex, int base_offset) {
0050       assert(m_pos > 0 && m_pos <= NN);
0051 
0052 #if defined(GATHER_INTRINSICS)
0053       GATHER_IDX_LOAD(vi, m_idx);
0054       mplex.slurpIn(m_base + base_offset, vi, D(), m_pos);
0055 #else
0056       mplex.slurpIn(m_base + base_offset, m_idx, m_pos);
0057 #endif
0058     }
0059   };
0060 
0061   //==============================================================================
0062   // MatriplexErrParPackerSlurpIn
0063   //==============================================================================
0064 
0065   // T - input class (Track or Hit), D - data type (float)
0066 
0067   template <typename T, typename D>
0068   class MatriplexErrParPackerSlurpIn : public MatriplexPackerSlurpIn<D> {
0069     int m_off_param;
0070 
0071   public:
0072     MatriplexErrParPackerSlurpIn(const T* t)
0073         : MatriplexPackerSlurpIn<D>(t ? t->errArray() : nullptr), m_off_param(t ? (t->posArray() - this->m_base) : 0) {}
0074 
0075     void addInput(const T& item) {
0076       // Could issue L1 prefetch requests here.
0077 
0078       this->m_idx[this->m_pos] = item.errArray() - this->m_base;
0079 
0080       ++this->m_pos;
0081     }
0082 
0083     void addInputAt(int pos, const T& item) {
0084       while (this->m_pos < pos) {
0085         // We might not care about initialization / reset to 0.
0086         // Or we could be building an additional mask (on top of N_proc).
0087         this->m_idx[this->m_pos++] = 0;
0088       }
0089 
0090       addInput(item);
0091     }
0092 
0093     template <typename TMerr, typename TMpar>
0094     void pack(TMerr& err, TMpar& par) {
0095       assert(this->m_pos > 0 && this->m_pos <= NN);
0096 
0097 #if defined(GATHER_INTRINSICS)
0098       GATHER_IDX_LOAD(vi, this->m_idx);
0099       err.slurpIn(this->m_base, vi, D(), this->m_pos);
0100       par.slurpIn(this->m_base + m_off_param, vi, D(), this->m_pos);
0101 #else
0102       err.slurpIn(this->m_base, this->m_idx, this->m_pos);
0103       par.slurpIn(this->m_base + m_off_param, this->m_idx, this->m_pos);
0104 #endif
0105     }
0106   };
0107 
0108   //==============================================================================
0109   // MatriplexTrackPackerPlexify
0110   //==============================================================================
0111 
0112   template <typename T, typename D>
0113   class MatriplexTrackPackerPlexify  // : public MatriplexTrackPackerBase
0114   {
0115   public:
0116     MatriplexTrackPackerPlexify(const T& t) {}
0117 
0118     void reset() {}
0119 
0120     void addNullInput() {}
0121 
0122     void addInput(const T& item) {}
0123 
0124     void addInputAt(int pos, const T& item) {}
0125 
0126     template <typename TMerr, typename TMpar>
0127     void pack(TMerr& err, TMpar& par) {}
0128   };
0129 
0130   //==============================================================================
0131   // Packer Selection
0132   //==============================================================================
0133 
0134   // Optionally ifdef with defines from Makefile.config
0135 
0136   using MatriplexHitPacker = MatriplexErrParPackerSlurpIn<Hit, float>;
0137   using MatriplexTrackPacker = MatriplexErrParPackerSlurpIn<TrackBase, float>;
0138 
0139   using MatriplexHoTPacker = MatriplexPackerSlurpIn<HitOnTrack>;
0140 }  // namespace mkfit
0141 
0142 #endif