Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:19

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