CMS 3D CMS Logo

SiPixelRawToClusterGPUKernel.h
Go to the documentation of this file.
1 #ifndef RecoLocalTracker_SiPixelClusterizer_plugins_SiPixelRawToClusterGPUKernel_h
2 #define RecoLocalTracker_SiPixelClusterizer_plugins_SiPixelRawToClusterGPUKernel_h
3 
4 #include <algorithm>
5 #include <cuda_runtime.h>
6 
18 
19 // #define GPU_DEBUG
20 
21 // local include(s)
23 
26 
27 namespace pixelgpudetails {
28 
29  inline namespace phase1geometry {
30  const uint32_t layerStartBit = 20;
31  const uint32_t ladderStartBit = 12;
32  const uint32_t moduleStartBit = 2;
33 
34  const uint32_t panelStartBit = 10;
35  const uint32_t diskStartBit = 18;
36  const uint32_t bladeStartBit = 12;
37 
38  const uint32_t layerMask = 0xF;
39  const uint32_t ladderMask = 0xFF;
40  const uint32_t moduleMask = 0x3FF;
41  const uint32_t panelMask = 0x3;
42  const uint32_t diskMask = 0xF;
43  const uint32_t bladeMask = 0x3F;
44  } // namespace phase1geometry
45 
46  const uint32_t maxROCIndex = 8;
47  const uint32_t numRowsInRoc = 80;
48  const uint32_t numColsInRoc = 52;
49 
50  const uint32_t MAX_WORD = 2000;
51 
52  struct DetIdGPU {
53  uint32_t rawId;
54  uint32_t rocInDet;
55  uint32_t moduleId;
56  };
57 
58  struct Pixel {
59  uint32_t row;
60  uint32_t col;
61  };
62 
64 
65  inline constexpr uint32_t pack(uint32_t row, uint32_t col, uint32_t adc, uint32_t flag = 0) {
66  constexpr pixelchannelidentifierimpl::Packing thePacking = packing();
67  adc = std::min(adc, uint32_t(thePacking.max_adc));
68 
69  return (row << thePacking.row_shift) | (col << thePacking.column_shift) | (adc << thePacking.adc_shift);
70  }
71 
72  constexpr uint32_t pixelToChannel(int row, int col) {
73  constexpr pixelchannelidentifierimpl::Packing thePacking = packing();
74  return (row << thePacking.column_width) | col;
75  }
76 
77  template <typename TrackerTraits>
79  public:
81  public:
82  WordFedAppender(uint32_t words, cudaStream_t stream)
83  : word_{cms::cuda::make_host_unique<unsigned int[]>(words, stream)},
84  fedId_{cms::cuda::make_host_unique<unsigned char[]>(words, stream)} {}
85 
86  void initializeWordFed(int fedId, unsigned int index, cms_uint32_t const* src, unsigned int length) {
87  std::memcpy(word_.get() + index, src, sizeof(cms_uint32_t) * length);
88  std::memset(fedId_.get() + index / 2, fedId - FEDNumbering::MINSiPixeluTCAFEDID, length / 2);
89  }
90 
91  const unsigned int* word() const { return word_.get(); }
92  const unsigned char* fedId() const { return fedId_.get(); }
93 
94  private:
97  };
98 
99  SiPixelRawToClusterGPUKernel() = default;
100  ~SiPixelRawToClusterGPUKernel() = default;
101 
106 
107  void makePhase1ClustersAsync(const SiPixelClusterThresholds clusterThresholds,
108  const SiPixelROCsStatusAndMapping* cablingMap,
109  const unsigned char* modToUnp,
111  const WordFedAppender& wordFed,
113  const uint32_t wordCounter,
114  const uint32_t fedCounter,
115  bool useQualityInfo,
116  bool includeErrors,
117  bool debug,
118  cudaStream_t stream);
119 
120  void makePhase2ClustersAsync(const SiPixelClusterThresholds clusterThresholds,
121  const uint16_t* moduleIds,
122  const uint16_t* xDigis,
123  const uint16_t* yDigis,
124  const uint16_t* adcDigis,
125  const uint32_t* packedData,
126  const uint32_t* rawIds,
127  const uint32_t numDigis,
128  cudaStream_t stream);
129 
130  std::pair<SiPixelDigisCUDA, SiPixelClustersCUDA> getResults() {
134  // need to explicitly deallocate while the associated CUDA
135  // stream is still alive
136  //
137  // technically the statement above is not true anymore now that
138  // the CUDA streams are cached within the cms::cuda::StreamCache, but it is
139  // still better to release as early as possible
140  nModules_Clusters_h.reset();
141  return std::make_pair(std::move(digis_d), std::move(clusters_d));
142  }
143 
145 
146  private:
147  uint32_t nDigis;
148 
149  // Data to be put in the event
154  };
155 
156 } // namespace pixelgpudetails
157 
158 #endif // RecoLocalTracker_SiPixelClusterizer_plugins_SiPixelRawToClusterGPUKernel_h
void makePhase1ClustersAsync(const SiPixelClusterThresholds clusterThresholds, const SiPixelROCsStatusAndMapping *cablingMap, const unsigned char *modToUnp, const SiPixelGainForHLTonGPU *gains, const WordFedAppender &wordFed, SiPixelFormatterErrors &&errors, const uint32_t wordCounter, const uint32_t fedCounter, bool useQualityInfo, bool includeErrors, bool debug, cudaStream_t stream)
void initializeWordFed(int fedId, unsigned int index, cms_uint32_t const *src, unsigned int length)
cms::cuda::host::unique_ptr< uint32_t[]> nModules_Clusters_h
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
assert(be >=bs)
void makePhase2ClustersAsync(const SiPixelClusterThresholds clusterThresholds, const uint16_t *moduleIds, const uint16_t *xDigis, const uint16_t *yDigis, const uint16_t *adcDigis, const uint32_t *packedData, const uint32_t *rawIds, const uint32_t numDigis, cudaStream_t stream)
static constexpr Packing thePacking
std::pair< SiPixelDigisCUDA, SiPixelClustersCUDA > getResults()
unsigned int cms_uint32_t
Definition: typedefs.h:15
constexpr float gains[NGAINS]
Definition: EcalConstants.h:20
void setNClusters(uint32_t nClusters, int32_t offsetBPIX2)
#define debug
Definition: HDRShower.cc:19
constexpr pixelchannelidentifierimpl::Packing packing()
constexpr uint32_t pack(uint32_t row, uint32_t col, uint32_t adc, uint32_t flag=0)
col
Definition: cuy.py:1009
void setNModulesDigis(uint32_t nModules, uint32_t nDigis)
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: errors.py:1
constexpr uint32_t pixelToChannel(int row, int col)
std::map< cms_uint32_t, std::vector< SiPixelRawDataError > > SiPixelFormatterErrors
def move(src, dest)
Definition: eostools.py:511
SiPixelRawToClusterGPUKernel & operator=(const SiPixelRawToClusterGPUKernel &)=delete
uint16_t *__restrict__ uint16_t const *__restrict__ adc