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 
6 #include <cuda_runtime.h>
7 
20 
21 //#define GPU_DEBUG
22 
25 
26 namespace pixelgpudetails {
27 
28  inline namespace phase1geometry {
29  const uint32_t layerStartBit = 20;
30  const uint32_t ladderStartBit = 12;
31  const uint32_t moduleStartBit = 2;
32 
33  const uint32_t panelStartBit = 10;
34  const uint32_t diskStartBit = 18;
35  const uint32_t bladeStartBit = 12;
36 
37  const uint32_t layerMask = 0xF;
38  const uint32_t ladderMask = 0xFF;
39  const uint32_t moduleMask = 0x3FF;
40  const uint32_t panelMask = 0x3;
41  const uint32_t diskMask = 0xF;
42  const uint32_t bladeMask = 0x3F;
43  } // namespace phase1geometry
44 
45  const uint32_t maxROCIndex = 8;
46  const uint32_t numRowsInRoc = 80;
47  const uint32_t numColsInRoc = 52;
48 
49  const uint32_t MAX_WORD = 2000;
50 
51  struct DetIdGPU {
52  uint32_t rawId;
53  uint32_t rocInDet;
54  uint32_t moduleId;
55  };
56 
57  struct Pixel {
58  uint32_t row;
59  uint32_t col;
60  };
61 
63 
64  inline constexpr uint32_t pack(uint32_t row, uint32_t col, uint32_t adc, uint32_t flag = 0) {
66  adc = std::min(adc, uint32_t(thePacking.max_adc));
67 
68  return (row << thePacking.row_shift) | (col << thePacking.column_shift) | (adc << thePacking.adc_shift);
69  }
70 
71  constexpr uint32_t pixelToChannel(int row, int col) {
73  return (row << thePacking.column_width) | col;
74  }
75 
76  template <typename TrackerTraits>
78  public:
80  public:
81  WordFedAppender(uint32_t words, cudaStream_t stream)
82  : word_{cms::cuda::make_host_unique<unsigned int[]>(words, stream)},
83  fedId_{cms::cuda::make_host_unique<unsigned char[]>(words, stream)} {}
84 
85  void initializeWordFed(int fedId, unsigned int index, cms_uint32_t const* src, unsigned int length) {
86  std::memcpy(word_.get() + index, src, sizeof(cms_uint32_t) * length);
87  std::memset(fedId_.get() + index / 2, fedId - FEDNumbering::MINSiPixeluTCAFEDID, length / 2);
88  }
89 
90  const unsigned int* word() const { return word_.get(); }
91  const unsigned char* fedId() const { return fedId_.get(); }
92 
93  private:
96  };
97 
98  SiPixelRawToClusterGPUKernel() = default;
100 
105 
106  void makePhase1ClustersAsync(const SiPixelClusterThresholds clusterThresholds,
107  const SiPixelROCsStatusAndMapping* cablingMap,
108  const unsigned char* modToUnp,
110  const WordFedAppender& wordFed,
112  const uint32_t wordCounter,
113  const uint32_t fedCounter,
114  bool useQualityInfo,
115  bool includeErrors,
116  bool debug,
117  cudaStream_t stream);
118 
119  void makePhase2ClustersAsync(const SiPixelClusterThresholds clusterThresholds,
120  const uint16_t* moduleIds,
121  const uint16_t* xDigis,
122  const uint16_t* yDigis,
123  const uint16_t* adcDigis,
124  const uint32_t* packedData,
125  const uint32_t* rawIds,
126  const uint32_t numDigis,
127  cudaStream_t stream);
128 
129  std::pair<SiPixelDigisCUDA, SiPixelClustersCUDA> getResults() {
133 
134 #ifdef GPU_DEBUG
135  std::cout << "SiPixelClusterizerCUDA results:" << std::endl
136  << " > no. of digis: " << nDigis << std::endl
137  << " > no. of active modules: " << nModules_Clusters_h[0] << std::endl
138  << " > no. of clusters: " << nModules_Clusters_h[1] << std::endl
139  << " > bpix2 offset: " << nModules_Clusters_h[2] << std::endl;
140 #endif
141  // need to explicitly deallocate while the associated CUDA
142  // stream is still alive
143  //
144  // technically the statement above is not true anymore now that
145  // the CUDA streams are cached within the cms::cuda::StreamCache, but it is
146  // still better to release as early as possible
147  nModules_Clusters_h.reset();
148  return std::make_pair(std::move(digis_d), std::move(clusters_d));
149  }
150 
152 
153  private:
154  uint32_t nDigis;
155 
156  // Data to be put in the event
161  };
162 
163 } // namespace pixelgpudetails
164 
165 #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