CMS 3D CMS Logo

List of all members | Public Member Functions
ALPAKA_ACCELERATOR_NAMESPACE::TopoClusterContraction Class Reference

Public Member Functions

template<typename TAcc , typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator() (const TAcc &acc, const reco::PFRecHitHostCollection::ConstView pfRecHits, reco::PFClusteringVarsDeviceCollection::View pfClusteringVars, reco::PFClusterDeviceCollection::View clusterView, uint32_t *__restrict__ nSeeds) const
 

Detailed Description

Definition at line 1195 of file PFClusterSoAProducerKernel.dev.cc.

Member Function Documentation

◆ operator()()

template<typename TAcc , typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void ALPAKA_ACCELERATOR_NAMESPACE::TopoClusterContraction::operator() ( const TAcc &  acc,
const reco::PFRecHitHostCollection::ConstView  pfRecHits,
reco::PFClusteringVarsDeviceCollection::View  pfClusteringVars,
reco::PFClusterDeviceCollection::View  clusterView,
uint32_t *__restrict__  nSeeds 
) const
inline

Definition at line 1198 of file PFClusterSoAProducerKernel.dev.cc.

References cms::cudacompat::atomicAdd(), dqmdumpme::k, hltrates_dqm_sourceclient-live_cfg::offset, cms::alpakatools::once_per_block(), and HLT_2024v13_cff::pfRecHits.

1202  {
1203  const int nRH = pfRecHits.size();
1204  int& totalSeedOffset = alpaka::declareSharedVar<int, __COUNTER__>(acc);
1205  int& totalSeedFracOffset = alpaka::declareSharedVar<int, __COUNTER__>(acc);
1206 
1207  // rhCount, topoRHCount, topoSeedCount initialized earlier
1208  if (once_per_block(acc)) {
1209  pfClusteringVars.nTopos() = 0;
1210  pfClusteringVars.nRHFracs() = 0;
1211  totalSeedOffset = 0;
1212  totalSeedFracOffset = 0;
1213  pfClusteringVars.pcrhFracSize() = 0;
1214  }
1215 
1216  alpaka::syncBlockThreads(acc); // all threads call sync
1217 
1218  // Now determine the number of seeds and rechits in each topo cluster [topoRHCount, topoSeedCount]
1219  // Also get the list of topoIds (smallest rhIdx of each topo cluser)
1220  for (int rhIdx = alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]; rhIdx < nRH;
1221  rhIdx += alpaka::getWorkDiv<alpaka::Block, alpaka::Threads>(acc)[0u]) {
1222  pfClusteringVars[rhIdx].rhIdxToSeedIdx() = -1;
1223  int topoId = pfClusteringVars[rhIdx].pfrh_topoId();
1224  if (topoId > -1) {
1225  // Valid topo cluster
1226  alpaka::atomicAdd(acc, &pfClusteringVars[topoId].topoRHCount(), 1);
1227  // Valid topoId not counted yet
1228  if (topoId == rhIdx) { // For every topo cluster, there is one rechit that meets this condition.
1229  int topoIdx = alpaka::atomicAdd(acc, &pfClusteringVars.nTopos(), 1);
1230  pfClusteringVars[topoIdx].topoIds() =
1231  topoId; // topoId: the smallest index of rechits that belong to a topo cluster.
1232  }
1233  // This is a cluster seed
1234  if (pfClusteringVars[rhIdx].pfrh_isSeed()) { // # of seeds in this topo cluster
1235  alpaka::atomicAdd(acc, &pfClusteringVars[topoId].topoSeedCount(), 1);
1236  }
1237  }
1238  }
1239 
1240  alpaka::syncBlockThreads(acc); // all threads call sync
1241 
1242  // Determine offsets for topo ID seed array [topoSeedOffsets]
1243  for (int topoId = alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]; topoId < nRH;
1244  topoId += alpaka::getWorkDiv<alpaka::Block, alpaka::Threads>(acc)[0u]) {
1245  if (pfClusteringVars[topoId].topoSeedCount() > 0) {
1246  // This is a valid topo ID
1247  int offset = alpaka::atomicAdd(acc, &totalSeedOffset, pfClusteringVars[topoId].topoSeedCount());
1248  pfClusteringVars[topoId].topoSeedOffsets() = offset;
1249  }
1250  }
1251  alpaka::syncBlockThreads(acc); // all threads call sync
1252 
1253  // Fill arrays of rechit indicies for each seed [topoSeedList] and rhIdx->seedIdx conversion for each seed [rhIdxToSeedIdx]
1254  // Also fill seedRHIdx, topoId, depth
1255  for (int rhIdx = alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]; rhIdx < nRH;
1256  rhIdx += alpaka::getWorkDiv<alpaka::Block, alpaka::Threads>(acc)[0u]) {
1257  int topoId = pfClusteringVars[rhIdx].pfrh_topoId();
1258  if (pfClusteringVars[rhIdx].pfrh_isSeed()) {
1259  // Valid topo cluster and this rhIdx corresponds to a seed
1260  int k = alpaka::atomicAdd(acc, &pfClusteringVars[topoId].rhCount(), 1);
1261  int seedIdx = pfClusteringVars[topoId].topoSeedOffsets() + k;
1262  if ((unsigned int)seedIdx >= *nSeeds)
1263  printf("Warning(contraction) %8d > %8d should not happen, check topoId: %d has %d rh\n",
1264  seedIdx,
1265  *nSeeds,
1266  topoId,
1267  k);
1268  pfClusteringVars[seedIdx].topoSeedList() = rhIdx;
1269  pfClusteringVars[rhIdx].rhIdxToSeedIdx() = seedIdx;
1270  clusterView[seedIdx].topoId() = topoId;
1271  clusterView[seedIdx].seedRHIdx() = rhIdx;
1272  clusterView[seedIdx].depth() = pfRecHits[rhIdx].depth();
1273  }
1274  }
1275 
1276  alpaka::syncBlockThreads(acc); // all threads call sync
1277 
1278  // Determine seed offsets for rechit fraction array
1279  for (int rhIdx = alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]; rhIdx < nRH;
1280  rhIdx += alpaka::getWorkDiv<alpaka::Block, alpaka::Threads>(acc)[0u]) {
1281  pfClusteringVars[rhIdx].rhCount() = 1; // Reset this counter array
1282 
1283  int topoId = pfClusteringVars[rhIdx].pfrh_topoId();
1284  if (pfClusteringVars[rhIdx].pfrh_isSeed() && topoId > -1) {
1285  // Allot the total number of rechits for this topo cluster for rh fractions
1286  int offset = alpaka::atomicAdd(acc, &totalSeedFracOffset, pfClusteringVars[topoId].topoRHCount());
1287 
1288  // Add offset for this PF cluster seed
1289  pfClusteringVars[rhIdx].seedFracOffsets() = offset;
1290 
1291  // Store recHitFraction offset & size information for each seed
1292  clusterView[pfClusteringVars[rhIdx].rhIdxToSeedIdx()].rhfracOffset() =
1293  pfClusteringVars[rhIdx].seedFracOffsets();
1294  clusterView[pfClusteringVars[rhIdx].rhIdxToSeedIdx()].rhfracSize() =
1295  pfClusteringVars[topoId].topoRHCount() - pfClusteringVars[topoId].topoSeedCount() + 1;
1296  }
1297  }
1298 
1299  alpaka::syncBlockThreads(acc); // all threads call sync
1300 
1301  if (once_per_block(acc)) {
1302  pfClusteringVars.pcrhFracSize() = totalSeedFracOffset;
1303  pfClusteringVars.nRHFracs() = totalSeedFracOffset;
1304  clusterView.nRHFracs() = totalSeedFracOffset;
1305  clusterView.nSeeds() = *nSeeds;
1306  clusterView.nTopos() = pfClusteringVars.nTopos();
1307 
1308  if (pfClusteringVars.pcrhFracSize() > 200000) // Warning in case the fraction is too large
1309  printf("At the end of topoClusterContraction, found large *pcrhFracSize = %d\n",
1310  pfClusteringVars.pcrhFracSize());
1311  }
1312  }
ALPAKA_FN_ACC constexpr bool once_per_block(TAcc const &acc)
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61