Skip to content

Commit 4b39a86

Browse files
committed
Add a tutorial about writing heterogeneous code in CMSSW
It contains various modules and data structres: an EDProducer to convert PFJets to a simplified SoA format - a heterogeneous global::EDProducer running on CPU - SoA data structures - automatic data transfers from host to device an EDProducer to apply residual jet corrections on GPU - an asynchronous global::EDProducer running on GPU - a simple 1D kernel an ESProducer for the jet corrections - a new EventSetup record - new “portable” data structures and EventSetup conditions - a heterogeneous ESProducer an EDProducer to find all jet pairs and triplets passing some selection criteria - a stream::SynchronizingEDProducer - new persistent and local SoA data structures - automatic copy of a configuration object to the GPUs - more complex 2D and 3D kernels an EDAnalyzer to print the N-tuplets - a traditional edm::EDAnalyzer running on CPU - automatic data transfers from device to host It also contains a configuration file to run the full job on GPUs or on CPU. Note: these packages are distributed under the GNU GPL v3 license.
1 parent 0f90f19 commit 4b39a86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2979
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<use name="fmt"/>
2+
<use name="rootcore"/>
3+
<use name="DataFormats/Common"/>
4+
<use name="DataFormats/Portable"/>
5+
<use name="DataFormats/SoATemplate"/>
6+
<use name="HeterogeneousCore/AlpakaInterface"/>
7+
<flags ALPAKA_BACKENDS="!serial"/>
8+
<export>
9+
<lib name="1"/>
10+
</export>

DataFormats/HeterogeneousTutorial/COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Description
2+
3+
This package is part of a tutorial about writing heterogeneous code in CMSSW.
4+
It contains various modules and data structres:
5+
6+
an EDProducer to convert PFJets to a simplified SoA format
7+
- a heterogeneous global::EDProducer running on CPU
8+
- SoA data structures
9+
- automatic data transfers from host to device
10+
11+
an EDProducer to apply residual jet corrections on GPU
12+
- an asynchronous global::EDProducer running on GPU
13+
- a simple 1D kernel
14+
15+
an ESProducer for the jet corrections
16+
- a new EventSetup record
17+
- new “portable” data structures and EventSetup conditions
18+
- a heterogeneous ESProducer
19+
20+
an EDProducer to find all jet pairs and triplets passing some selection criteria
21+
- a stream::SynchronizingEDProducer
22+
- new persistent and local SoA data structures
23+
- automatic copy of a configuration object to the GPUs
24+
- more complex 2D and 3D kernels
25+
26+
an EDAnalyzer to print the N-tuplets
27+
- a traditional edm::EDAnalyzer running on CPU
28+
- automatic data transfers from device to host
29+
30+
It also contains a configuration file to run the full job on GPUs or on CPU.
31+
32+
33+
# License
34+
35+
This package is free software: you can redistribute it and/or modify it under the terms of
36+
the GNU General Public License as published by the Free Software Foundation, either
37+
version 3 of the License, or (at your option) any later version.
38+
39+
This module is distributed in the hope that it will be useful, but WITHOUT ANY
40+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
41+
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
42+
43+
You should have received a copy of the GNU General Public License along with this
44+
package. If not, see <https://www.gnu.org/licenses/>.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_JetsHostCollection_h
2+
#define DataFormats_HeterogeneousTutorial_interface_JetsHostCollection_h
3+
4+
#include "DataFormats/HeterogeneousTutorial/interface/JetsSoA.h"
5+
#include "DataFormats/Portable/interface/PortableHostCollection.h"
6+
7+
namespace tutorial {
8+
9+
using JetsHostCollection = PortableHostCollection<JetsSoA>;
10+
11+
} // namespace tutorial
12+
13+
#endif // DataFormats_HeterogeneousTutorial_interface_JetsHostCollection_h
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_JetsSoA_h
2+
#define DataFormats_HeterogeneousTutorial_interface_JetsSoA_h
3+
4+
#include <ostream>
5+
6+
#include "DataFormats/SoATemplate/interface/SoALayout.h"
7+
8+
namespace tutorial {
9+
10+
GENERATE_SOA_LAYOUT(JetsSoALayout,
11+
// columns: one value per element
12+
SOA_COLUMN(float, pt),
13+
SOA_COLUMN(float, eta),
14+
SOA_COLUMN(float, phi),
15+
SOA_COLUMN(float, mass))
16+
17+
using JetsSoA = JetsSoALayout<>;
18+
19+
std::ostream& operator<<(std::ostream& out, JetsSoA::View::const_element const& jet);
20+
21+
} // namespace tutorial
22+
23+
#endif // DataFormats_HeterogeneousTutorial_interface_JetsSoA_h
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_TripletsHostCollection_h
2+
#define DataFormats_HeterogeneousTutorial_interface_TripletsHostCollection_h
3+
4+
#include "DataFormats/HeterogeneousTutorial/interface/TripletsSoA.h"
5+
#include "DataFormats/Portable/interface/PortableHostCollection.h"
6+
7+
namespace tutorial {
8+
9+
using TripletsHostCollection = PortableHostCollection<TripletsSoA>;
10+
11+
} // namespace tutorial
12+
13+
#endif // DataFormats_HeterogeneousTutorial_interface_TripletsHostCollection_h
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_TripletsSoA_h
2+
#define DataFormats_HeterogeneousTutorial_interface_TripletsSoA_h
3+
4+
#include "DataFormats/SoATemplate/interface/SoALayout.h"
5+
6+
namespace tutorial {
7+
8+
constexpr const int kEmpty = -1;
9+
10+
GENERATE_SOA_LAYOUT(TripletsSoALayout,
11+
// scalars: one value per collection
12+
SOA_SCALAR(int, size),
13+
// columns: one value per element
14+
SOA_COLUMN(int, first),
15+
SOA_COLUMN(int, second),
16+
SOA_COLUMN(int, third))
17+
18+
using TripletsSoA = TripletsSoALayout<>;
19+
20+
} // namespace tutorial
21+
22+
#endif // DataFormats_HeterogeneousTutorial_interface_TripletsSoA_h
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_alpaka_JetsDeviceCollection_h
2+
#define DataFormats_HeterogeneousTutorial_interface_alpaka_JetsDeviceCollection_h
3+
4+
#include "DataFormats/HeterogeneousTutorial/interface/JetsHostCollection.h"
5+
#include "DataFormats/HeterogeneousTutorial/interface/JetsSoA.h"
6+
#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
7+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
8+
9+
namespace ALPAKA_ACCELERATOR_NAMESPACE::tutorial {
10+
11+
// Make the names from the top-level tutorial namespace visible for unqualified lookup
12+
// inside the ALPAKA_ACCELERATOR_NAMESPACE::tutorial namespace.
13+
using namespace ::tutorial;
14+
15+
using JetsDeviceCollection = PortableCollection<JetsSoA>;
16+
17+
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::tutorial
18+
19+
// Check that the portable device collection for the host device is the same as the portable host collection.
20+
ASSERT_DEVICE_MATCHES_HOST_COLLECTION(tutorial::JetsDeviceCollection, tutorial::JetsHostCollection);
21+
22+
#endif // DataFormats_HeterogeneousTutorial_interface_alpaka_JetsDeviceCollection_h
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef DataFormats_HeterogeneousTutorial_interface_alpaka_TripletsDeviceCollection_h
2+
#define DataFormats_HeterogeneousTutorial_interface_alpaka_TripletsDeviceCollection_h
3+
4+
#include "DataFormats/HeterogeneousTutorial/interface/TripletsHostCollection.h"
5+
#include "DataFormats/HeterogeneousTutorial/interface/TripletsSoA.h"
6+
#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
7+
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
8+
9+
namespace ALPAKA_ACCELERATOR_NAMESPACE::tutorial {
10+
11+
// Make the names from the top-level tutorial namespace visible for unqualified lookup
12+
// inside the ALPAKA_ACCELERATOR_NAMESPACE::tutorial namespace.
13+
using namespace ::tutorial;
14+
15+
using TripletsDeviceCollection = PortableCollection<TripletsSoA>;
16+
17+
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::tutorial
18+
19+
// Check that the portable device collection for the host device is the same as the portable host collection.
20+
ASSERT_DEVICE_MATCHES_HOST_COLLECTION(tutorial::TripletsDeviceCollection, tutorial::TripletsHostCollection);
21+
22+
#endif // DataFormats_HeterogeneousTutorial_interface_alpaka_TripletsDeviceCollection_h
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <ostream>
2+
3+
#include <fmt/format.h>
4+
5+
#include "DataFormats/HeterogeneousTutorial/interface/JetsSoA.h"
6+
7+
namespace tutorial {
8+
9+
std::ostream& operator<<(std::ostream& out, JetsSoA::View::const_element const& jet) {
10+
out << fmt::format("SoA jet (pt, eta, phi) {:8.3f}, {:6.3f}, {:6.3f}", jet.pt(), jet.eta(), jet.phi());
11+
return out;
12+
}
13+
14+
} // namespace tutorial

0 commit comments

Comments
 (0)