Skip to content

Alpaka Multi-depth particle flow clusterizer #48248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

alexstrel
Copy link

PR description:

This PR introduces an Alpaka-based implementation of the multi-depth particle flow clustering algorithm, which makes extensive use of warp-level operations. Due to the inherently non-local nature of the algorithm, we implemented custom masked warp intrinsics currently not available in the Alpaka library. Additionally, we utilized the extended ECL-CC (connected component detection) graph algorithm to support this use case. This extension involves reorganizing SoA data objects into a CSR (Compressed Sparse Row) format during both pre-processing and post-processing stages to enable efficient graph traversal.

PR validation:

The implementation expects input data to be provided in device-resident SoA format.

@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 4, 2025

cms-bot internal usage

@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 4, 2025

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45055

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@jfernan2
Copy link
Contributor

jfernan2 commented Jun 5, 2025

assign heterogeneous

Copy link
Contributor

@makortel makortel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From first look

Comment on lines 21 to 22
//SOA_COLUMN(int, adjacencyList),//for multi-depth clusterizer
//SOA_COLUMN(int, nDegree),//for multi-depth clusterizer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented-out lines still needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts, fixed with 953a8ae

Comment on lines 12 to 14
//SOA_COLUMN(int, seedRHIdx),
//SOA_COLUMN(int, rhfracSize),
//SOA_COLUMN(int, rhfracOffset),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented0out lines still needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artifacts, fixed with 953a8ae

Comment on lines 21 to 24
//SOA_COLUMN(int, mdpf_component), //list of component contents (always start with component root id)
//SOA_COLUMN(int, mdpf_componentIndex),
//SOA_COLUMN(int, mdpf_componentEnergy),
//SOA_SCALAR(int, mdpf_nTopos),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented-out lines still needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle the contents of this file look generic, and would be better placed in HeterogeneousCore/AlpakaInterface/interface. On the other hand, given that the AMD implementation is simple (I guess relying on __builtin_amdgcn_wave_barrier() providing stronger synchronization than minimally needed), maybe in the interest of time this place would be good-enough for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although because all files presently added to RecoParticleFlow/PFClusterProducer/interface/alpaka/ are used only in RecoParticleFlow/PFClusterProducer/plugins/alpaka, maybe all those files should be moved to plugins/alpaka directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's too early to move this to HeterogeneousCore/AlpakaInterface/interface, but I agree it makes sense to relocate it to the plugin for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 4f67aa1


#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that all functions are templated over TAcc, they could (ideally should) be placed outside of ALPAKA_ACCELERATOR_NAMESPACE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 4f67aa1

Comment on lines 104 to 105
std::optional<reco::PFRecHitFractionDeviceCollection> outPFRHFractions;
std::optional<reco::PFClusterDeviceCollection> outPFClusters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional could be avoided with

cms_uint32_t const nClusters = event.get(inputPFClustersNum_Token_);
cms_uint32_t const nRH = event.get(inputPFRecHitNum_Token_);
outPFClusters.emplace(nClusters, event.queue());
outPFRHFractions.emplace(nRH, event.queue());
if (nClusters > 0) {
  clusterizer_->apply(event.queue(), outPFClusters, outPFRHFractions, pfClusters, pfRecHitFractions, pfRecHits);
}

enum class ClusterParamKind { DEPTH, ENERGY, ETA, PHI, ETA_RMS2, PHI_RMS2, INVALID_KIND };

class ClusterParam {
protected:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why protected instead of private? Is this class intended to be inherited from? (I didn't quickly see any inheritance)

(same question for all other use of protected)

Comment on lines +262 to +263
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this kernel operate on any number of dimensions? If it is restricted to one (Acc1D that is used now), how about

Suggested change
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
ALPAKA_FN_ACC void operator()(Acc1D const& acc,

(same comment for other kernels)

}

template <ClusterParamKind kind = ClusterParamKind::INVALID_KIND>
inline constexpr auto Get() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of this approach compared to member functions along

  constexpr auto depth() const { return depth_; }

?


enum class ClusterParamKind { DEPTH, ENERGY, ETA, PHI, ETA_RMS2, PHI_RMS2, INVALID_KIND };

class ClusterParam {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many names in this file sound generic enough for me to worry about possible symbol collisions. I'd suggest either more specific names, or a namespace specific to PF.

@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 5, 2025

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45071

  • Found files with invalid states:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterProducer_Alpaka.cc:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizer_Alpaka.cc:

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 5, 2025

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45077

  • Found files with invalid states:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterProducer_Alpaka.cc:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizer_Alpaka.cc:

Code check has found code style and quality issues which could be resolved by applying following patch(s)

…gorithm implementation, removed misleading comments, and renamed class names to avoid potential name collisions.
@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 6, 2025

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45087

ERROR: Build errors found during clang-tidy run.

src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizerHelper.h:15:10: error: 'RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterWarpIntrinsics.h' file not found [clang-diagnostic-error]
   15 | #include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterWarpIntrinsics.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppressed 1152 warnings (1152 in non-user code).
--
gmake: *** [config/SCRAM/GMake/Makefile.coderules:129: code-checks] Error 2
gmake: *** [There are compilation/build errors. Please see the detail log above.] Error 2

@cmsbuild
Copy link
Contributor

cmsbuild commented Jun 6, 2025

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45089

ERROR: Build errors found during clang-tidy run.

      |                                     ^
/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02892/el8_amd64_gcc12/cms/cmssw-patch/CMSSW_15_1_X_2025-06-06-1100/src/DataFormats/Portable/interface/PortableHostCollection.h:25:3: note: 'PortableHostCollection' has been explicitly marked deleted here
--
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:103:21: error: no member named 'emplace' in 'PortableHostCollection<reco::PFClusterSoALayout<>>' [clang-diagnostic-error]
  103 |       outPFClusters.emplace(*nClusters_, event.queue());
      |       ~~~~~~~~~~~~~ ^
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:104:24: error: no member named 'emplace' in 'PortableHostCollection<reco::PFRecHitFractionSoALayout<>>' [clang-diagnostic-error]
  104 |       outPFRHFractions.emplace(nRH_, event.queue());
      |       ~~~~~~~~~~~~~~~~ ^
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:106:42: error: non-const lvalue reference to type 'reco::PFClusterDeviceCollection' (aka 'PortableHostCollection<reco::PFClusterSoALayout<128, false>>') cannot bind to a value of unrelated type 'View' (aka 'ViewTemplateFreeParams<128UL, false, true, true>') [clang-diagnostic-error]
  106 |       clusterizer_->apply(event.queue(), *outPFClusters, *outPFRHFractions, pfClusters, pfRecHitFractions, pfRecHits);
      |                                          ^~~~~~~~~~~~~~
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizer_Alpaka.h:57:49: note: passing argument to parameter 'outPFCluster' here
--
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:108:21: error: no member named 'emplace' in 'PortableHostCollection<reco::PFClusterSoALayout<>>' [clang-diagnostic-error]
  108 |       outPFClusters.emplace(0, event.queue());
      |       ~~~~~~~~~~~~~ ^
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:109:24: error: no member named 'emplace' in 'PortableHostCollection<reco::PFRecHitFractionSoALayout<>>' [clang-diagnostic-error]
  109 |       outPFRHFractions.emplace(0, event.queue());
      |       ~~~~~~~~~~~~~~~~ ^
src/RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterSoAProducer.cc:112:46: warning: std::move of the expression of the trivially-copyable type 'View' (aka 'ViewTemplateFreeParams<128UL, false, true, true>') has no effect [performance-move-const-arg]
--
gmake: *** [config/SCRAM/GMake/Makefile.coderules:129: code-checks] Error 2
gmake: *** [There are compilation/build errors. Please see the detail log above.] Error 2

@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45138

  • Found files with invalid states:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterProducer_Alpaka.cc:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusteringVarsHostCollection.h:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterWarpIntrinsics.h:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterizerHelper.h:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizer_Alpaka.cc:

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-48248/45169

  • Found files with invalid states:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterProducer_Alpaka.cc:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusteringVarsHostCollection.h:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterWarpIntrinsics.h:
    • RecoParticleFlow/PFClusterProducer/interface/alpaka/PFMultiDepthClusterizerHelper.h:
    • RecoParticleFlow/PFClusterProducer/plugins/alpaka/PFMultiDepthClusterizer_Alpaka.cc:

Code check has found code style and quality issues which could be resolved by applying following patch(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants