CMS 3D CMS Logo

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

Public Member Functions

template<typename TAcc , typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator() (TAcc const &acc, const unsigned int numer_of_clusters, float thresholdW0, float positionDeltaRho2, const HGCalSoARecHitsDeviceCollection::ConstView input_rechits_soa, const HGCalSoARecHitsExtraDeviceCollection::ConstView input_clusters_soa, HGCalSoAClustersDeviceCollection::View outputs, HGCalSoAClustersExtraDeviceCollection::View outputs_service) const
 

Detailed Description

Definition at line 39 of file HGCalLayerClustersSoAAlgoWrapper.dev.cc.

Member Function Documentation

◆ operator()()

template<typename TAcc , typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void ALPAKA_ACCELERATOR_NAMESPACE::HGCalLayerClustersSoAAlgoKernelPositionByHits::operator() ( TAcc const &  acc,
const unsigned int  numer_of_clusters,
float  thresholdW0,
float  positionDeltaRho2,
const HGCalSoARecHitsDeviceCollection::ConstView  input_rechits_soa,
const HGCalSoARecHitsExtraDeviceCollection::ConstView  input_clusters_soa,
HGCalSoAClustersDeviceCollection::View  outputs,
HGCalSoAClustersExtraDeviceCollection::View  outputs_service 
) const
inline

Definition at line 42 of file HGCalLayerClustersSoAAlgoWrapper.dev.cc.

References cms::cudacompat::atomicAdd(), f, hgcal::constants::kInvalidCluster, kInvalidIndex, fileCollector::seed, cms::alpakatools::uniform_elements(), and mps_merge::weight.

49  {
50  // make a strided loop over the kernel grid, covering up to "size" elements
51  for (int32_t hit_index : uniform_elements(acc, input_rechits_soa.metadata().size())) {
52  const int cluster_index = input_clusters_soa[hit_index].clusterIndex();
53 
54  // Bail out if you are not part of any cluster
55  if (cluster_index == kInvalidCluster) {
56  continue;
57  }
58 
59  alpaka::atomicAdd(acc, &outputs_service[cluster_index].total_weight(), input_rechits_soa[hit_index].weight());
60  // Read the current seed index, and the associated energy.
61  int clusterSeed = outputs_service[cluster_index].maxEnergyIndex();
62  float clusterEnergy = (clusterSeed == kInvalidIndex) ? 0.f : input_rechits_soa[clusterSeed].weight();
63 
64  while (input_rechits_soa[hit_index].weight() > clusterEnergy) {
65  // If output_service[cluster_index].maxEnergyIndex() did not change,
66  // store the new value and exit the loop. Otherwise return the value
67  // that has been updated, and decide again if the maximum needs to be
68  // updated.
69  int seed = alpaka::atomicCas(acc, &outputs_service[cluster_index].maxEnergyIndex(), clusterSeed, hit_index);
70  if (seed == hit_index) {
71  // atomicCas has stored the new value.
72  break;
73  } else {
74  // Update the seed index and re-read the associated energy.
75  clusterSeed = seed;
76  clusterEnergy = (clusterSeed == kInvalidIndex) ? 0.f : input_rechits_soa[clusterSeed].weight();
77  }
78  } // CAS
79  } // uniform_elements
80  } // operator()
ALPAKA_FN_ACC auto uniform_elements(TAcc const &acc, TArgs... args)
Definition: workdivision.h:311
constexpr auto kInvalidIndex
double f[11][100]
static constexpr int kInvalidCluster
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61