CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
CandsGPU::BestCands< MaxCandsPerSeed, BlockSize > Struct Template Reference

#include <BestCands.h>

Public Member Functions

__device__ bool better (int icand_fst, int fst, int icand_snd, int snd)
 
__device__ void copy_node (int icand_fst, int fst, int icand_snd, int snd)
 
__device__ int count_valid_cands (int itrack)
 
__device__ void get_cand_info (const int tid, const int cid, int &my_trkIdx, int &my_hitIdx, int &my_nhits, float &my_chi2)
 
__device__ int get_nhits (const int tid, const int cid)
 
__device__ void heap_sort (int icand, int heap_size)
 
__device__ void heapify (int itrack, int idx, int heap_size)
 
__device__ int left (int idx)
 
__device__ void merge_cands_for_seed (int iseed, int icand)
 
__device__ void print_heap (const int tid)
 
__device__ void reset (int itrack)
 
__device__ int right (int idx)
 
__device__ void swap_nodes (int icand_fst, int fst, int icand_snd, int snd)
 
__device__ void update (int itrack, int cand_trIdx, int cand_hitIdx, int cand_nhits, float cand_chi2)
 

Public Attributes

float chi2 [MaxCandsPerSeed][BlockSize]
 
int hitIdx [MaxCandsPerSeed][BlockSize]
 
int nhits [MaxCandsPerSeed][BlockSize]
 
int trkIdx [MaxCandsPerSeed][BlockSize]
 

Detailed Description

template<int MaxCandsPerSeed, int BlockSize>
struct CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >

Definition at line 24 of file BestCands.h.

Member Function Documentation

◆ better()

template<int M, int B>
__device__ bool CandsGPU::BestCands< M, B >::better ( int  icand_fst,
int  fst,
int  icand_snd,
int  snd 
)

Definition at line 101 of file BestCands.h.

References hltPixelTracks_cff::chi2, and nhits.

101  {
102  return (nhits[fst][icand_fst] > nhits[snd][icand_snd]) ||
103  ((nhits[fst][icand_fst] == nhits[snd][icand_snd]) && (chi2[fst][icand_fst] < chi2[snd][icand_snd]));
104  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28

◆ copy_node()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::copy_node ( int  icand_fst,
int  fst,
int  icand_snd,
int  snd 
)

Definition at line 115 of file BestCands.h.

References hltPixelTracks_cff::chi2, and nhits.

115  {
116  trkIdx[snd][icand_snd] = trkIdx[fst][icand_fst];
117  hitIdx[snd][icand_snd] = hitIdx[fst][icand_fst];
118  nhits[snd][icand_snd] = nhits[fst][icand_fst];
119  chi2[snd][icand_snd] = chi2[fst][icand_fst];
120  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

◆ count_valid_cands()

template<int M, int B>
__device__ int CandsGPU::BestCands< M, B >::count_valid_cands ( int  itrack)

Definition at line 222 of file BestCands.h.

References submitPVResolutionJobs::count, mps_fire::i, and CandsGPU::trkIdx_sentinel.

222  {
223  int count = 0;
224  for (int i = 0; i < M; ++i) {
225  if (trkIdx[i][itrack] != trkIdx_sentinel)
226  ++count;
227  }
228  return count;
229  }
constexpr int trkIdx_sentinel
Definition: BestCands.h:11
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26

◆ get_cand_info()

template<int MaxCandsPerSeed, int BlockSize>
__device__ void CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::get_cand_info ( const int  tid,
const int  cid,
int &  my_trkIdx,
int &  my_hitIdx,
int &  my_nhits,
float &  my_chi2 
)

Definition at line 211 of file BestCands.h.

References ecaldqm::BlockSize, hltPixelTracks_cff::chi2, and nhits.

212  {
213  if (cid < MaxCandsPerSeed && tid < BlockSize) {
214  my_trkIdx = trkIdx[cid][tid];
215  my_hitIdx = hitIdx[cid][tid];
216  my_nhits = nhits[cid][tid];
217  my_chi2 = chi2[cid][tid];
218  }
219  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

◆ get_nhits()

template<int MaxCandsPerSeed, int BlockSize>
__device__ int CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::get_nhits ( const int  tid,
const int  cid 
)
inline

Definition at line 49 of file BestCands.h.

References CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::nhits.

49 { return nhits[cid][tid]; }
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28

◆ heap_sort()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::heap_sort ( int  icand,
int  heap_size 
)

Definition at line 201 of file BestCands.h.

References mps_fire::i.

201  {
202  int num_unsorted_elts = heap_size;
203  // Assume that we have a heap with the worst one at the root.
204  for (int i = heap_size - 1; i > 0; --i) {
205  swap_nodes(icand, 0, icand, i); // worst at the end
206  heapify(icand, 0, --num_unsorted_elts);
207  }
208  }
__device__ void swap_nodes(int icand_fst, int fst, int icand_snd, int snd)
Definition: BestCands.h:107
__device__ void heapify(int itrack, int idx, int heap_size)
Definition: BestCands.h:123

◆ heapify()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::heapify ( int  itrack,
int  idx,
int  heap_size 
)

Definition at line 123 of file BestCands.h.

References heavyIonCSV_trainingSettings::idx.

123  {
124  // We want to move idx down so the smallest value is at the root
125  int smallest = -1;
126  while (idx != smallest) {
127  if (idx < 0 || idx >= heap_size / 2)
128  return;
129 
130  smallest = idx;
131  if (heap_size > left(idx) && better(icand, smallest, icand, left(idx)))
132  smallest = left(idx);
133  if (heap_size > right(idx) && better(icand, smallest, icand, right(idx)))
134  smallest = right(idx);
135 
136  if (smallest != idx) {
137  swap_nodes(icand, smallest, icand, idx);
138  idx = smallest;
139  smallest = -1;
140  }
141  }
142  }
__device__ int left(int idx)
Definition: BestCands.h:91
__device__ void swap_nodes(int icand_fst, int fst, int icand_snd, int snd)
Definition: BestCands.h:107
__device__ int right(int idx)
Definition: BestCands.h:96
__device__ bool better(int icand_fst, int fst, int icand_snd, int snd)
Definition: BestCands.h:101

◆ left()

template<int M, int B>
__device__ int CandsGPU::BestCands< M, B >::left ( int  idx)

Definition at line 91 of file BestCands.h.

References heavyIonCSV_trainingSettings::idx.

Referenced by svgfig.Curve.Samples::__len__().

91  {
92  return (++idx << 1) - 1;
93  }

◆ merge_cands_for_seed()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::merge_cands_for_seed ( int  iseed,
int  icand 
)

Definition at line 145 of file BestCands.h.

References cms::cudacompat::__syncthreads(), B, mps_fire::i, iseed, and dqmiolumiharvest::j.

145  {
146  int itrack = iseed * M + icand;
147 // TODO: Need a better way to reduce candidates.
148 // So far, binary tree reduction is a bit slower than the naive approach
149 #if 1
150  if (icand) {
151  heap_sort(itrack, M);
152  }
153  __syncthreads(); // cand 0 waits;
154  if (icand)
155  return; // reduction by the first cand of each seed
156 
157  for (int i = itrack + 1; i < itrack + M; ++i) { // over cands
158  for (int j = 0; j < M; ++j) { // inside heap
159  if (better(i, j, itrack, 0)) {
160  copy_node(i, j, itrack, 0);
161  heapify(itrack, 0, M);
162  } else {
163  break;
164  }
165  }
166  }
167  heap_sort(itrack, M);
168  __syncthreads(); // TODO: Volta: sync only on MaxCandsPerSeeds threads
169 #else
170 
171  for (int step = 2; step <= Config::maxCandsPerSeed; step <<= 1) {
172  if (icand % step == step / 2) {
173  heap_sort(itrack, M);
174  }
175  __syncthreads();
176 
177  if (icand % step == 0) {
178  int i = itrack + step / 2;
179  if ((i < iseed * M + M) && (i < B) && (icand + step / 2 < M)) {
180  for (int j = 0; j < M; ++j) { // inside heap
181  if (better(i, j, itrack, 0)) {
182  copy_node(i, j, itrack, 0);
183  heapify(itrack, 0, M);
184  } else {
185  break;
186  }
187  }
188  }
189  }
190  //__syncthreads();
191  }
192 
193  if (icand == 0) {
194  heap_sort(itrack, M);
195  }
196  __syncthreads();
197 #endif
198  }
__device__ void heap_sort(int icand, int heap_size)
Definition: BestCands.h:201
Definition: APVGainStruct.h:7
__device__ void copy_node(int icand_fst, int fst, int icand_snd, int snd)
Definition: BestCands.h:115
__device__ bool better(int icand_fst, int fst, int icand_snd, int snd)
Definition: BestCands.h:101
int iseed
Definition: AMPTWrapper.h:134
void __syncthreads()
Definition: cudaCompat.h:108
__device__ void heapify(int itrack, int idx, int heap_size)
Definition: BestCands.h:123
step
Definition: StallMonitor.cc:98

◆ print_heap()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::print_heap ( const int  tid)

Definition at line 79 of file BestCands.h.

References hltPixelTracks_cff::chi2, and nhits.

79  {
80  for (int cid = 0; cid < M; cid++) {
81  printf(">>>>> tid %d rowIdx %d hitIdx %d nhits %d chi2 %f\n",
82  tid,
83  cid,
84  hitIdx[cid][tid],
85  nhits[cid][tid],
86  chi2[cid][tid]);
87  }
88  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

◆ reset()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::reset ( int  itrack)

Definition at line 55 of file BestCands.h.

References hltPixelTracks_cff::chi2, CandsGPU::chi2_sentinel, CandsGPU::hitIdx_sentinel, dqmiolumiharvest::j, nhits, CandsGPU::nhits_sentinel, and CandsGPU::trkIdx_sentinel.

55  {
56  for (auto j = 0; j < M; ++j) {
57  trkIdx[j][itrack] = trkIdx_sentinel;
58  hitIdx[j][itrack] = hitIdx_sentinel;
59  nhits[j][itrack] = nhits_sentinel;
60  chi2[j][itrack] = chi2_sentinel;
61  }
62  }
constexpr int nhits_sentinel
Definition: BestCands.h:13
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
constexpr int hitIdx_sentinel
Definition: BestCands.h:12
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
constexpr float chi2_sentinel
Definition: BestCands.h:14
constexpr int trkIdx_sentinel
Definition: BestCands.h:11
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

◆ right()

template<int M, int B>
__device__ int CandsGPU::BestCands< M, B >::right ( int  idx)

Definition at line 96 of file BestCands.h.

References heavyIonCSV_trainingSettings::idx.

96  {
97  return ++idx << 1;
98  }

◆ swap_nodes()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::swap_nodes ( int  icand_fst,
int  fst,
int  icand_snd,
int  snd 
)

Definition at line 107 of file BestCands.h.

References hltPixelTracks_cff::chi2, nhits, and CandsGPU::swap_values().

107  {
108  swap_values(trkIdx[fst][icand_fst], trkIdx[snd][icand_snd]);
109  swap_values(hitIdx[fst][icand_fst], hitIdx[snd][icand_snd]);
110  swap_values(nhits[fst][icand_fst], nhits[snd][icand_snd]);
111  swap_values(chi2[fst][icand_fst], chi2[snd][icand_snd]);
112  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
__device__ void swap_values(T &a, T &b)
Definition: BestCands.h:17
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

◆ update()

template<int M, int B>
__device__ void CandsGPU::BestCands< M, B >::update ( int  itrack,
int  cand_trIdx,
int  cand_hitIdx,
int  cand_nhits,
float  cand_chi2 
)

Definition at line 65 of file BestCands.h.

References hltPixelTracks_cff::chi2, and nhits.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

65  {
66  if (cand_nhits < nhits[0][itrack])
67  return;
68  if (cand_chi2 > chi2[0][itrack])
69  return;
70  trkIdx[0][itrack] = cand_trIdx;
71  hitIdx[0][itrack] = cand_hitIdx;
72  nhits[0][itrack] = cand_nhits;
73  chi2[0][itrack] = cand_chi2;
74 
75  heapify(itrack, 0, M);
76  }
float chi2[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:29
int nhits[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:28
__device__ void heapify(int itrack, int idx, int heap_size)
Definition: BestCands.h:123
int trkIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:26
int hitIdx[MaxCandsPerSeed][BlockSize]
Definition: BestCands.h:27

Member Data Documentation

◆ chi2

template<int MaxCandsPerSeed, int BlockSize>
float CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::chi2[MaxCandsPerSeed][BlockSize]

Definition at line 29 of file BestCands.h.

◆ hitIdx

template<int MaxCandsPerSeed, int BlockSize>
int CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::hitIdx[MaxCandsPerSeed][BlockSize]

Definition at line 27 of file BestCands.h.

Referenced by ntupleDataFormat._RecoHitAdaptor::_hits().

◆ nhits

template<int MaxCandsPerSeed, int BlockSize>
int CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::nhits[MaxCandsPerSeed][BlockSize]

◆ trkIdx

template<int MaxCandsPerSeed, int BlockSize>
int CandsGPU::BestCands< MaxCandsPerSeed, BlockSize >::trkIdx[MaxCandsPerSeed][BlockSize]

Definition at line 26 of file BestCands.h.