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

Add support to multi layout portable collections (any number) #40285

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

ericcano
Copy link
Contributor

PR description:

The design is recursive, but ROOT seems not to serialize variadic templates, so we have a 5 elements design. This number is arbitrary and can be changed with relatively little work.

The order of the PortableDeviceCollection template parameters is changed from device at the end to device at the begining to accomodate the pseudo variadic templation.

A test validates the colleciton with two layouts.

The layout and view can be accessed by index or type, on the condition the type is present only once in the collection.

The default index is set to 0 to minimize the need for chages in the single layout case. Empty template parameters square bracket ("<>") are needed in some cases.

PR validation:

The PR is validated with the pre-existing /HeterogeneousCore/AlpakaTest/test/testHeterogeneousCoreAlpakaTestWriteRead.sh which has been extended to add a two-layouts example.

The rest of CMSSW needs to be reviewed to detect where the PortableCollections are used to validate if syntactic adaptations are needed (mostly adding <> to functions that became templated, if needed. For this reason, this PR is a draft.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40285/33338

  • This PR adds an extra 28KB to repository

@cmsbuild
Copy link
Contributor

cmsbuild commented Dec 12, 2022

A new Pull Request was created by @ericcano (Eric Cano) for master.

It involves the following packages:

  • DataFormats/Portable (heterogeneous)
  • DataFormats/PortableTestObjects (heterogeneous)
  • HeterogeneousCore/AlpakaTest (heterogeneous)

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

cms-bot commands are listed here

Comment on lines 8 to 9
f(std::integral_constant<decltype(Start), Start>());
constexpr_for<Start + Inc, End, Inc>(f);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just wondering if these should be

Suggested change
f(std::integral_constant<decltype(Start), Start>());
constexpr_for<Start + Inc, End, Inc>(f);
std::forward<F>(f)(std::integral_constant<decltype(Start), Start>());
constexpr_for<Start + Inc, End, Inc>(std::move(f));

to support rvalue f ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would use std::size_t explicitly instead of auto, and give a default value of Inc = 1

}
}

template <std::size_t idx, typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change idx to Idx ?

Suggested change
template <std::size_t idx, typename T>
template <std::size_t Idx, typename T>

template <std::size_t idx, typename T>
struct CollectionLeaf {
CollectionLeaf() = default;
CollectionLeaf(std::byte* buffer, int32_t elements) : layout_(buffer, elements), view_(layout_) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would wither change this to

Suggested change
CollectionLeaf(std::byte* buffer, int32_t elements) : layout_(buffer, elements), view_(layout_) {}
CollectionLeaf(std::byte* buffer, int32_t size) : layout_(buffer, size), view_(layout_) {}

or use elements instead of sizes in the next one

CollectionLeaf() = default;
CollectionLeaf(std::byte* buffer, int32_t elements) : layout_(buffer, elements), view_(layout_) {}
template <std::size_t N>
CollectionLeaf(std::byte* buffer, std::array<int32_t, N> sizes) : layout_(buffer, sizes[idx]), view_(layout_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be better to pass the array as a const reference ?

Suggested change
CollectionLeaf(std::byte* buffer, std::array<int32_t, N> sizes) : layout_(buffer, sizes[idx]), view_(layout_) {
CollectionLeaf(std::byte* buffer, std::array<int32_t, N> const& sizes) : layout_(buffer, sizes[idx]), view_(layout_) {


template <typename T0, typename T1, typename T2, typename T3, typename T4>
struct CollectionTypeResolver {
template <std::size_t idx, class = void>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
template <std::size_t idx, class = void>
template <std::size_t idx, typename = void>

for consistency

Comment on lines 57 to 69
template <typename T0, typename T1, typename T2, typename T3, typename T4>
struct CollectionTypeResolver {
template <std::size_t idx, class = void>
struct Resolver {
static_assert(idx != 0);
using type = typename CollectionTypeResolver<T1, T2, T3, T4, void>::template Resolver<idx - 1>::type;
};

template <std::size_t idx>
struct Resolver<idx, std::enable_if_t<idx == 0>> {
using type = T0;
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

could this all be replaced by std::tuple_element<Idx, std::tuple<T0, T1, T2, T3, T4>> ?

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40285/33391

  • This PR adds an extra 32KB to repository

@cmsbuild
Copy link
Contributor

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

@fwyzard
Copy link
Contributor

fwyzard commented Dec 14, 2022

please test

@fwyzard
Copy link
Contributor

fwyzard commented Dec 14, 2022

I'm working on some more suggestions, but let's see if these work first.

@cmsbuild
Copy link
Contributor

-1

Failed Tests: ClangBuild
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-72ad56/29617/summary.html
COMMIT: 55468ef
CMSSW: CMSSW_13_0_X_2022-12-14-1100/el8_amd64_gcc11
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/40285/29617/install.sh to create a dev area with all the needed externals and cmssw changes.

Clang Build

I found compilation warning while trying to compile with clang. Command used:

USER_CUDA_FLAGS='--expt-relaxed-constexpr' USER_CXXFLAGS='-Wno-register -fsyntax-only' scram build -k -j 32 COMPILER='llvm compile'

See details on the summary page.

Comment on lines 216 to 299
std::array<int32_t, members_> sizes;
constexpr_for<0, members_>(
[&sizes, &impl](auto i) { sizes[i] = static_cast<Leaf<i> const&>(impl).layout_.metadata().size(); });
new (newObj) PortableHostCollection(sizes, cms::alpakatools::host());
constexpr_for<0, members_>([&sizes, &newObj, &impl](auto i) {
static_cast<Leaf<i>&>(newObj->impl_).layout_.ROOTReadStreamer(static_cast<Leaf<i> const&>(impl).layout_);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

@ericcano sizes does not seem to be used here; do we need it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it is not needed for the second constexpr_for loop on line 220.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2024

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

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2024

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40285/38743

  • This PR adds an extra 36KB to repository

@fwyzard
Copy link
Contributor

fwyzard commented Feb 7, 2024

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2024

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-72ad56/37270/summary.html
COMMIT: b4ed3a8
CMSSW: CMSSW_14_1_X_2024-02-06-2300/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/40285/37270/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

@fwyzard
Copy link
Contributor

fwyzard commented Feb 12, 2024

With these changes, the root file produced by cmsRun HeterogeneousCore/AlpakaTest/test/writer.py has

$ edmDumpEventContent --forceColumns test.root 
Type                                                                                                                                                      Module                 Label       Process    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PortableHostCollection<portabletest::TestSoALayout<128,false> >                                                                                           "testProducer"         ""          "Writer"   
PortableHostCollection<portabletest::TestSoALayout<128,false> >                                                                                           "testProducerSerial"   ""          "Writer"   
PortableHostMultiCollection<portabletest::TestSoALayout<128,false>,portabletest::TestSoALayout2<128,false> >                                              "testProducer"         ""          "Writer"   
PortableHostMultiCollection<portabletest::TestSoALayout<128,false>,portabletest::TestSoALayout2<128,false> >                                              "testProducerSerial"   ""          "Writer"   
PortableHostMultiCollection<portabletest::TestSoALayout<128,false>,portabletest::TestSoALayout2<128,false>,portabletest::TestSoALayout3<128,false> >      "testProducer"         ""          "Writer"   
PortableHostMultiCollection<portabletest::TestSoALayout<128,false>,portabletest::TestSoALayout2<128,false>,portabletest::TestSoALayout3<128,false> >      "testProducerSerial"   ""          "Writer"   
PortableHostObject<portabletest::TestStruct>                                                                                                              "testProducer"         ""          "Writer"   
PortableHostObject<portabletest::TestStruct>                                                                                                              "testProducerSerial"   ""          "Writer"   
edm::TriggerResults                                                                                                                                       "TriggerResults"       ""          "Writer"   
unsigned short                                                                                                                                            "testProducer"         "backend"   "Writer"   
unsigned short                                                                                                                                            "testProducerSerial"   "backend"   "Writer"   

@fwyzard
Copy link
Contributor

fwyzard commented Feb 12, 2024

+heterogeneous

@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. @rappoccio, @sextonkennedy, @antoniovilela (and backports should be raised in the release meeting by the corresponding L2)

@antoniovilela
Copy link
Contributor

+1

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.

6 participants