Skip to content
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

Allow Portable{Collection,Object}<T, TDev> to be used also independently of ALPAKA_ACCELERATOR_NAMESPACE #43310

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

makortel
Copy link
Contributor

@makortel makortel commented Nov 16, 2023

PR description:

This PR makes the PortableCollection<T, TDev> and PortableObject<T, TDev> alias templates usable also independently of ALPAKA_ACCELERATOR_NAMESPACE. This ability can be useful e.g. for EventSetup data product classes that themselves are templated over the device type (TDev), and want to use the PortableCollection for SoA storage (e.g. having PortableCollection(s) as data members).

Furthermore, this PR simplifies the definitions of the PortableCollection<T, TDev> and PortableObject<T, TDev> alias templates. The trait-based approach is kept, but the traits are fully defined and specialized in DataFormats/Portable/interface/Portable{Collection,Object}.h. In addition, the specializations of the CopyTo{Host,Device} templates were moved to the headers in interface/ as well.

Old description from the RFC-stage of this PR:

The first commit of this PR makes the PortableCollection<T, TDev> alias template usable also independently of ALPAKA_ACCELERATOR_NAMESPACE. This ability can be useful e.g. for EventSetup data product classes that themselves are templated over the device type (TDev), and want to use the PortableCollection for SoA storage (e.g. having PortableCollection(s) as data members). I have an example crafted, but that is waiting for #43298 to get merged, and therefore I went with a standalone PR just for this ability.

While doing that I felt the way the PortableCollection<T, TDev> is defined was a bit cumbersome.

  • The second commit continues to use the trait-based approach, but the trait is fully defined and specialized in DataFormats/Portable/interface/PortableCollection.h
  • The third commit uses std::conditional_t in the alias template instead of the trait class template

Some further cleanup can be done, depending on the decided approach. (e.g. in case of second or third commit I'd move the specializations of CopyToHost and CopyToDevice class templates to DataFormats/Portable/interface/PortableCollection.h).

Resolves cms-sw/framework-team#720

PR validation:

Added unit test compiles.

@makortel
Copy link
Contributor Author

@fwyzard Any thoughts?

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-43310/37755

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 16, 2023

A new Pull Request was created by @makortel (Matti Kortelainen) for master.

It involves the following packages:

  • DataFormats/Portable (heterogeneous)

@cmsbuild, @fwyzard, @makortel can you please review it and eventually sign? Thanks.
@rovere, @missirol this is something you requested to watch as well.
@rappoccio, @antoniovilela, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@makortel
Copy link
Contributor Author

@cmsbuild, please test

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-1d2156/35903/summary.html
COMMIT: e9e99a8
CMSSW: CMSSW_14_0_X_2023-11-16-2300/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/43310/35903/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially removed 302 lines from the logs
  • Reco comparison results: 136 differences found in the comparisons
  • DQMHistoTests: Total files compared: 50
  • DQMHistoTests: Total histograms compared: 3363070
  • DQMHistoTests: Total failures: 2398
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3360650
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 49 files compared)
  • Checked 214 log files, 167 edm output root files, 50 DQM output files
  • TriggerResults: no differences found

@makortel
Copy link
Contributor Author

Comparison differences are related to #39803

Log differences are related to #43293

@makortel
Copy link
Contributor Author

makortel commented Dec 7, 2023

@fwyzard Any comments?

@fwyzard
Copy link
Contributor

fwyzard commented Dec 11, 2023

Sorry for the delay, the LUMI hackathon and the CMS Week got me distracted :-/

The first commit of this PR makes the PortableCollection<T, TDev> alias template usable also indepndently of ALPAKA_ACCELERATOR_NAMESPACE.

OK.

A couple of questions:

  • is there any reason to change class to struct ?
  • can defining traits::PortableCollectionTrait<T, alpaka::DevCpu> more than once (in DataFormats/Portable/interface/alpaka/PortableCollection.h when compiling for the CPU backend, and now in DataFormats/Portable/interface/PortableHostCollection.h) cause any problems ? Or is it OK to have the same specialisation twice, if they resolve to the same types ?
  • The second commit continues to use the trait-based approach, but the trait is fully defined and specialized in DataFormats/Portable/interface/PortableCollection.h

OK, this cleans it all up anyway :-)

  • The third commit uses std::conditional_t in the alias template instead of the trait class template

I like best the style of the second commit, but I don't have any concrete objections to the third one.

It feels like the second may be easier to extend if there are other special cases in the future - but I guess whatever logic that uses, can also be implemented using std::conditional_t.

So, I like two best, but I'm also OK with three.

@fwyzard
Copy link
Contributor

fwyzard commented Dec 11, 2023

By the way, can you do the same also for PortableObject ?

@makortel
Copy link
Contributor Author

  • is there any reason to change class to struct ?

My personal preference for struct when everything is public (which might be somewhat consistent with Core Guidelines C.2. IIRC the earlier PortableCollectionTrait::CollectionType being private lead to compilation errros.

  • can defining traits::PortableCollectionTrait<T, alpaka::DevCpu> more than once (in DataFormats/Portable/interface/alpaka/PortableCollection.h when compiling for the CPU backend, and now in DataFormats/Portable/interface/PortableHostCollection.h) cause any problems ? Or is it OK to have the same specialisation twice, if they resolve to the same types ?

I'd think two identical specializations would be technically ok in terms of One Definition Rule. Nevertheless, I think having only one definition would be simplest for future maintenance.

I like best the style of the second commit, but I don't have any concrete objections to the third one.

It feels like the second may be easier to extend if there are other special cases in the future - but I guess whatever logic that uses, can also be implemented using std::conditional_t.

I agree the second commit would be easier to extend. Or, even if such extensions could be done with std::conditional_t, maybe with one additional case the code would still be readable, but I'd imagine with third (and onwards) the pattern matching style with the template specializations to be easier to digest.

On the other hand, with just 2 cases the std::conditional_t feels easier to me.

Can you think of a situation where we'd need (or want to have) another special case? (I'm wondering if there is something foreseeable we might want to account already now)

The pattern for selecting between host and device collections repeats at least in the pixel PRs. I'd like some simple-to-use facility for users to use, and std::conditional_t fits the bill. It seems to me if another special case would be needed in the future, the user code for selecting between the host and device collections would have to be addressed anyway. Perhaps at that point we should consider some further abstraction?

By the way, can you do the same also for PortableObject ?

Yes.

@fwyzard
Copy link
Contributor

fwyzard commented Dec 11, 2023

Can you think of a situation where we'd need (or want to have) another special case? (I'm wondering if there is something foreseeable we might want to account already now)

The two possibilities I had in mind are Unified Memory and oneAPI CPU devices (OpenCL-based).

These might need some special casing of the PortableCollections since they would use memory accessible (or just on) the host -- but I haven't given any concrete thoughts about what that would imply.

@makortel
Copy link
Contributor Author

Can you think of a situation where we'd need (or want to have) another special case? (I'm wondering if there is something foreseeable we might want to account already now)

The two possibilities I had in mind are Unified Memory and oneAPI CPU devices (OpenCL-based).

These might need some special casing of the PortableCollections since they would use memory accessible (or just on) the host -- but I haven't given any concrete thoughts about what that would imply.

After thinking a bit more, I'm starting to lean towards the second commit, i.e. keeping the trait-based approach here, to have a little bit more flexibility for the future. I'd still advocate the std::conditional_t for user code for time being.

… templates

Also move the CopyTo{Host,Device} specialisations to interface/ as
they are independent from ALPAKA_ACCELERATOR_NAMESPACE.
@makortel makortel force-pushed the portableCollectionDef branch from e9e99a8 to 1143991 Compare December 22, 2023 18:11
@makortel
Copy link
Contributor Author

This update

  • rebases on top of CMSSW_14_0_0_pre1
  • keeps the trait-based approach
  • moves the specializations of CopyTo{Host,Device} to the headers in interface/, as those specializations do not depend on ALPAKA_ACCELERATOR_NAMESPACE

To me this PR is now complete.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-43310/38291

@cmsbuild
Copy link
Contributor

Pull request #43310 was updated. @fwyzard, @makortel, @cmsbuild can you please check and sign again.

@makortel
Copy link
Contributor Author

@cmsbuild, please test

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-1d2156/36661/summary.html
COMMIT: 1143991
CMSSW: CMSSW_14_0_X_2023-12-22-1100/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/43310/36661/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

@fwyzard
Copy link
Contributor

fwyzard commented Dec 24, 2023

+1

@cmsbuild
Copy link
Contributor

This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @sextonkennedy, @rappoccio, @antoniovilela (and backports should be raised in the release meeting by the corresponding L2)

@rappoccio
Copy link
Contributor

+1

@cmsbuild cmsbuild merged commit 1b67f09 into cms-sw:master Jan 8, 2024
11 checks passed
@makortel makortel deleted the portableCollectionDef branch January 8, 2024 21:47
makortel added a commit to makortel/cmssw that referenced this pull request Feb 15, 2024
… it to be used outside of ALPAKA_ACCELERATOR_NAMESPACE

I.e. repeat cms-sw#43310 on PortableMultiCollection.
makortel added a commit to makortel/cmssw that referenced this pull request Feb 15, 2024
… it to be used outside of ALPAKA_ACCELERATOR_NAMESPACE

I.e. repeat cms-sw#43310 on PortableMultiCollection.
makortel added a commit to makortel/cmssw that referenced this pull request Feb 19, 2024
… it to be used outside of ALPAKA_ACCELERATOR_NAMESPACE

I.e. repeat cms-sw#43310 on PortableMultiCollection.
rbhattacharya04 pushed a commit to rbhattacharya04/cmssw that referenced this pull request Mar 7, 2024
… it to be used outside of ALPAKA_ACCELERATOR_NAMESPACE

I.e. repeat cms-sw#43310 on PortableMultiCollection.
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.

Generalize and simplify PortableCollection<T, TDev> alias template definition
4 participants