Skip to content

Commit 2aed8d0

Browse files
ericcanofwyzard
authored andcommitted
Split ZVertexSoA in a PortableMultiCollection
Split ZVertexSoA in two layouts, and wrap them in a multi-layout collection. Remove versioning info from class description for dictionaries. Port comments from the CUDA version.
1 parent 3914bc8 commit 2aed8d0

22 files changed

+229
-127
lines changed

DQM/SiPixelHeterogeneous/plugins/SiPixelCompareVertices.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void SiPixelCompareVertices::analyzeSeparate(U tokenRef, V tokenTar, const edm::
112112
auto yc = y0 + dydz * zc;
113113
zc += z0;
114114

115-
auto ndofRef = vsoaRef.view()[sic].ndof();
115+
auto ndofRef = vsoaRef.template view<reco::ZVertexTracksSoA>()[sic].ndof();
116116
auto chi2Ref = vsoaRef.view()[sic].chi2();
117117

118118
const int32_t notFound = -1;
@@ -138,7 +138,7 @@ void SiPixelCompareVertices::analyzeSeparate(U tokenRef, V tokenTar, const edm::
138138
auto xg = x0 + dxdz * zg;
139139
auto yg = y0 + dydz * zg;
140140
zg += z0;
141-
auto ndofTar = vsoaTar.view()[closestVtxidx].ndof();
141+
auto ndofTar = vsoaTar.template view<reco::ZVertexTracksSoA>()[closestVtxidx].ndof();
142142
auto chi2Tar = vsoaTar.view()[closestVtxidx].chi2();
143143

144144
hx_->Fill(xc - x0, xg - x0);

DQM/SiPixelHeterogeneous/plugins/SiPixelMonitorVertexSoAAlpaka.cc

+9-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ void SiPixelMonitorVertexSoAAlpaka::analyze(const edm::Event& iEvent, const edm:
6767
}
6868

6969
auto const& vsoa = *vsoaHandle;
70-
int nVertices = vsoa.view().nvFinal();
70+
auto vtx_view = vsoa.view<reco::ZVertexSoA>();
71+
auto trk_view = vsoa.view<reco::ZVertexTracksSoA>();
72+
int nVertices = vtx_view.nvFinal();
7173
auto bsHandle = iEvent.getHandle(tokenBeamSpot_);
7274
float x0 = 0., y0 = 0., z0 = 0., dxdz = 0., dydz = 0.;
7375
if (!bsHandle.isValid()) {
@@ -82,19 +84,19 @@ void SiPixelMonitorVertexSoAAlpaka::analyze(const edm::Event& iEvent, const edm:
8284
}
8385

8486
for (int iv = 0; iv < nVertices; iv++) {
85-
auto si = vsoa.view()[iv].sortInd();
86-
auto z = vsoa.view()[si].zv();
87+
auto si = vtx_view[iv].sortInd();
88+
auto z = vtx_view[si].zv();
8789
auto x = x0 + dxdz * z;
8890
auto y = y0 + dydz * z;
8991

9092
z += z0;
9193
hx->Fill(x);
9294
hy->Fill(y);
9395
hz->Fill(z);
94-
auto ndof = vsoa.view()[si].ndof();
95-
hchi2->Fill(vsoa.view()[si].chi2());
96-
hchi2oNdof->Fill(vsoa.view()[si].chi2() / ndof);
97-
hptv2->Fill(vsoa.view()[si].ptv2());
96+
auto ndof = trk_view[si].ndof();
97+
hchi2->Fill(vtx_view[si].chi2());
98+
hchi2oNdof->Fill(vtx_view[si].chi2() / ndof);
99+
hptv2->Fill(vtx_view[si].ptv2());
98100
hntrks->Fill(ndof + 1);
99101
}
100102
hnVertex->Fill(nVertices);

DataFormats/VertexSoA/interface/ZVertexDevice.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
1010
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
1111

12-
template <int32_t S, typename TDev>
13-
class ZVertexDeviceSoA : public PortableDeviceCollection<reco::ZVertexLayout<>, TDev> {
12+
template <int32_t NVTX, int32_t NTRK, typename TDev>
13+
class ZVertexDeviceSoA : public PortableDeviceMultiCollection<TDev, reco::ZVertexSoA, reco::ZVertexTracksSoA> {
1414
public:
1515
ZVertexDeviceSoA() = default; // necessary for ROOT dictionaries
1616

17-
// Constructor which specifies the SoA size
17+
// Constructor which specifies the queue
1818
template <typename TQueue>
19-
explicit ZVertexDeviceSoA(TQueue queue) : PortableDeviceCollection<reco::ZVertexLayout<>, TDev>(S, queue) {}
19+
explicit ZVertexDeviceSoA(TQueue queue)
20+
: PortableDeviceMultiCollection<TDev, reco::ZVertexSoA, reco::ZVertexTracksSoA>({{NVTX, NTRK}}, queue) {}
2021
};
2122

22-
using namespace ::zVertex;
2323
template <typename TDev>
24-
using ZVertexDevice = ZVertexDeviceSoA<MAXTRACKS, TDev>;
24+
using ZVertexDevice = ZVertexDeviceSoA<zVertex::MAXVTX, zVertex::MAXTRACKS, TDev>;
2525

2626
#endif // DataFormats_VertexSoA_interface_ZVertexDevice_h

DataFormats/VertexSoA/interface/ZVertexHost.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@
1010
#include "DataFormats/VertexSoA/interface/ZVertexDefinitions.h"
1111
#include "DataFormats/Portable/interface/PortableHostCollection.h"
1212

13-
template <int32_t S>
14-
class ZVertexHostSoA : public PortableHostCollection<reco::ZVertexSoA> {
13+
// This alias is needed to call the SET_PORTABLEHOSTMULTICOLLECTION_READ_RULES macro without commas.
14+
using ZVertexHostSoABase = PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>;
15+
16+
template <int32_t NVTX, int32_t NTRK>
17+
class ZVertexHostSoA : public ZVertexHostSoABase {
1518
public:
1619
ZVertexHostSoA() = default;
1720

1821
// Constructor which specifies the queue
1922
template <typename TQueue>
20-
explicit ZVertexHostSoA(TQueue queue) : PortableHostCollection<reco::ZVertexSoA>(S, queue) {}
23+
explicit ZVertexHostSoA(TQueue queue)
24+
: PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>({{NVTX, NTRK}}, queue) {}
2125

2226
// Constructor which specifies the DevHost
23-
explicit ZVertexHostSoA(alpaka_common::DevHost const& host) : PortableHostCollection<reco::ZVertexSoA>(S, host) {}
27+
explicit ZVertexHostSoA(alpaka_common::DevHost const& host)
28+
: PortableHostCollection2<reco::ZVertexSoA, reco::ZVertexTracksSoA>({{NVTX, NTRK}}, host) {}
2429
};
2530

26-
//using namespace ::zVertex;
27-
using ZVertexHost = ZVertexHostSoA<zVertex::MAXTRACKS>;
31+
using ZVertexHost = ZVertexHostSoA<zVertex::MAXVTX, zVertex::MAXTRACKS>;
2832

2933
#endif // DataFormats_VertexSoA_ZVertexHost_H

DataFormats/VertexSoA/interface/ZVertexSoA.h

+17-8
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010
namespace reco {
1111

1212
GENERATE_SOA_LAYOUT(ZVertexLayout,
13-
SOA_COLUMN(int16_t, idv),
14-
SOA_COLUMN(float, zv),
15-
SOA_COLUMN(float, wv),
16-
SOA_COLUMN(float, chi2),
17-
SOA_COLUMN(float, ptv2),
18-
SOA_COLUMN(int32_t, ndof),
19-
SOA_COLUMN(uint16_t, sortInd),
20-
SOA_SCALAR(uint32_t, nvFinal))
13+
SOA_COLUMN(float, zv), // output z-posistion of found vertices
14+
SOA_COLUMN(float, wv), // output weight (1/error^2) on the above
15+
SOA_COLUMN(float, chi2), // vertices chi2
16+
SOA_COLUMN(float, ptv2), // vertices pt^2
17+
SOA_COLUMN(uint16_t, sortInd), // sorted index (by pt2) ascending
18+
SOA_SCALAR(uint32_t, nvFinal)) // the number of vertices
19+
20+
GENERATE_SOA_LAYOUT(ZVertexTracksLayout,
21+
SOA_COLUMN(int16_t, idv), // vertex index for each associated (original) track
22+
// (-1 == not associate)
23+
SOA_COLUMN(int32_t, ndof)) // vertices number of dof
24+
// FIXME: reused as workspace for the number of nearest neighbours
2125

2226
// Common types for both Host and Device code
2327
using ZVertexSoA = ZVertexLayout<>;
2428
using ZVertexSoAView = ZVertexSoA::View;
2529
using ZVertexSoAConstView = ZVertexSoA::ConstView;
2630

31+
// Common types for both Host and Device code
32+
using ZVertexTracksSoA = ZVertexTracksLayout<>;
33+
using ZVertexTracksSoAView = ZVertexTracksSoA::View;
34+
using ZVertexTracksSoAConstView = ZVertexTracksSoA::ConstView;
35+
2736
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE void init(ZVertexSoAView &vertices) { vertices.nvFinal() = 0; }
2837

2938
} // namespace reco

DataFormats/VertexSoA/src/classes.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h"
2-
#include "DataFormats/VertexSoA/interface/ZVertexSoA.h"
2+
#include "DataFormats/VertexSoA/interface/ZVertexHost.h"
33

4-
SET_PORTABLEHOSTCOLLECTION_READ_RULES(PortableHostCollection<reco::ZVertexSoA>);
4+
SET_PORTABLEHOSTMULTICOLLECTION_READ_RULES(ZVertexHostSoABase);
+16-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
<lcgdict>
2-
<class name="reco::ZVertexSoA"/>
3-
<class name="PortableHostCollection<reco::ZVertexSoA>"/>
4-
<class name="ZVertexHost" ClassVersion="3">
5-
<version ClassVersion="3" checksum="1989784241"/>
6-
</class>
2+
<!-- SoA classes -->
3+
<!-- FIXME using the ZVertexSoA and ZVertexTracksSoA type aliases here and below does not work -->
4+
<class name="reco::ZVertexLayout<128, false>"/>
5+
<class name="reco::ZVertexTracksLayout<128, false>"/>
6+
7+
<!-- Recursive templates (with no data) ensuring we have one CollectionLeaf<index, type> for each layout in the collection -->
8+
<class name="portablecollection::CollectionImpl<0, reco::ZVertexLayout<128, false>, reco::ZVertexTracksLayout<128, false>>"/>
9+
<class name="portablecollection::CollectionImpl<1, reco::ZVertexTracksLayout<128, false>>"/>
10+
11+
<!-- Recursive templates implementing the association of indices and layouts, and containing the data -->
12+
<class name="portablecollection::CollectionLeaf<0, reco::ZVertexLayout<128, false>>"/>
13+
<class name="portablecollection::CollectionLeaf<1, reco::ZVertexTracksLayout<128, false>>"/>
14+
15+
<!-- Collection declaration for dictionary -->
16+
<class name="ZVertexHostSoABase"/>
17+
<class name="ZVertexHost"/>
718
<class name="edm::Wrapper<ZVertexHost>" splitLevel="0"/>
819
</lcgdict>

DataFormats/VertexSoA/test/alpaka/ZVertexSoA_test.cc

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int main() {
4949
// Instantiate vertices on device. PortableCollection allocates
5050
// SoA on device automatically.
5151
ZVertexSoACollection zvertex_d(queue);
52-
testZVertexSoAT::runKernels(zvertex_d.view(), queue);
52+
testZVertexSoAT::runKernels(zvertex_d.view(), zvertex_d.view<reco::ZVertexTracksSoA>(), queue);
5353

5454
// Instantate vertices on host. This is where the data will be
5555
// copied to from device.
@@ -68,11 +68,13 @@ int main() {
6868
<< "sortInd\t"
6969
<< "nvFinal\n";
7070

71+
auto vtx_v = zvertex_h.view<reco::ZVertexSoA>();
72+
auto trk_v = zvertex_h.view<reco::ZVertexTracksSoA>();
7173
for (int i = 0; i < 10; ++i) {
72-
std::cout << (int)zvertex_h.view()[i].idv() << '\t' << zvertex_h.view()[i].zv() << '\t'
73-
<< zvertex_h.view()[i].wv() << '\t' << zvertex_h.view()[i].chi2() << '\t'
74-
<< zvertex_h.view()[i].ptv2() << '\t' << (int)zvertex_h.view()[i].ndof() << '\t'
75-
<< (int)zvertex_h.view()[i].sortInd() << '\t' << (int)zvertex_h.view().nvFinal() << '\n';
74+
auto vi = vtx_v[i];
75+
auto ti = trk_v[i];
76+
std::cout << (int)ti.idv() << "\t" << vi.zv() << "\t" << vi.wv() << "\t" << vi.chi2() << "\t" << vi.ptv2()
77+
<< "\t" << (int)ti.ndof() << "\t" << vi.sortInd() << "\t" << (int)vtx_v.nvFinal() << std::endl;
7678
}
7779
}
7880
}

DataFormats/VertexSoA/test/alpaka/ZVertexSoA_test.dev.cc

+22-14
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,57 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::testZVertexSoAT {
1111
class TestFillKernel {
1212
public:
1313
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
14-
ALPAKA_FN_ACC void operator()(TAcc const& acc, reco::ZVertexSoAView zvertex_view) const {
14+
ALPAKA_FN_ACC void operator()(TAcc const& acc,
15+
reco::ZVertexSoAView zvertex_view,
16+
reco::ZVertexTracksSoAView ztracks_view) const {
1517
if (cms::alpakatools::once_per_grid(acc)) {
1618
zvertex_view.nvFinal() = 420;
1719
}
1820

1921
for (int32_t j : cms::alpakatools::uniform_elements(acc, zvertex_view.metadata().size())) {
20-
zvertex_view[j].idv() = (int16_t)j;
2122
zvertex_view[j].zv() = (float)j;
2223
zvertex_view[j].wv() = (float)j;
2324
zvertex_view[j].chi2() = (float)j;
2425
zvertex_view[j].ptv2() = (float)j;
25-
zvertex_view[j].ndof() = (int32_t)j;
2626
zvertex_view[j].sortInd() = (uint16_t)j;
2727
}
28+
for (int32_t j : cms::alpakatools::uniform_elements(acc, ztracks_view.metadata().size())) {
29+
ztracks_view[j].idv() = (int16_t)j;
30+
ztracks_view[j].ndof() = (int32_t)j;
31+
}
2832
}
2933
};
3034

3135
class TestVerifyKernel {
3236
public:
3337
template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
34-
ALPAKA_FN_ACC void operator()(TAcc const& acc, reco::ZVertexSoAView zvertex_view) const {
38+
ALPAKA_FN_ACC void operator()(TAcc const& acc,
39+
reco::ZVertexSoAView zvertex_view,
40+
reco::ZVertexTracksSoAView ztracks_view) const {
3541
if (cms::alpakatools::once_per_grid(acc)) {
3642
ALPAKA_ASSERT_ACC(zvertex_view.nvFinal() == 420);
3743
}
3844

3945
for (int32_t j : cms::alpakatools::uniform_elements(acc, zvertex_view.nvFinal())) {
40-
ALPAKA_ASSERT_ACC(zvertex_view[j].idv() == j);
41-
ALPAKA_ASSERT_ACC(zvertex_view[j].zv() - (float)j < 0.0001);
42-
ALPAKA_ASSERT_ACC(zvertex_view[j].wv() - (float)j < 0.0001);
43-
ALPAKA_ASSERT_ACC(zvertex_view[j].chi2() - (float)j < 0.0001);
44-
ALPAKA_ASSERT_ACC(zvertex_view[j].ptv2() - (float)j < 0.0001);
45-
ALPAKA_ASSERT_ACC(zvertex_view[j].ndof() == j);
46-
ALPAKA_ASSERT_ACC(zvertex_view[j].sortInd() == uint32_t(j));
46+
ALPAKA_ASSERT(zvertex_view[j].zv() - (float)j < 0.0001);
47+
ALPAKA_ASSERT(zvertex_view[j].wv() - (float)j < 0.0001);
48+
ALPAKA_ASSERT(zvertex_view[j].chi2() - (float)j < 0.0001);
49+
ALPAKA_ASSERT(zvertex_view[j].ptv2() - (float)j < 0.0001);
50+
ALPAKA_ASSERT(zvertex_view[j].sortInd() == uint32_t(j));
51+
}
52+
for (int32_t j : cms::alpakatools::uniform_elements(acc, ztracks_view.metadata().size())) {
53+
ALPAKA_ASSERT(ztracks_view[j].idv() == j);
54+
ALPAKA_ASSERT(ztracks_view[j].ndof() == j);
4755
}
4856
}
4957
};
5058

51-
void runKernels(reco::ZVertexSoAView zvertex_view, Queue& queue) {
59+
void runKernels(reco::ZVertexSoAView zvertex_view, reco::ZVertexTracksSoAView ztracks_view, Queue& queue) {
5260
uint32_t items = 64;
5361
uint32_t groups = cms::alpakatools::divide_up_by(zvertex_view.metadata().size(), items);
5462
auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(groups, items);
55-
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, zvertex_view);
56-
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, zvertex_view);
63+
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, zvertex_view, ztracks_view);
64+
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, zvertex_view, ztracks_view);
5765
}
5866

5967
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testZVertexSoAT

DataFormats/VertexSoA/test/alpaka/ZVertexSoA_test.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ALPAKA_ACCELERATOR_NAMESPACE::testZVertexSoAT {
88

9-
void runKernels(reco::ZVertexSoAView zvertex_view, Queue& queue);
9+
void runKernels(reco::ZVertexSoAView zvertex_view, reco::ZVertexTracksSoAView ztracks_view, Queue& queue);
1010

1111
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testZVertexSoAT
1212

RecoTauTag/HLTProducers/src/L2TauTagNNProducerAlpaka.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void L2TauNNProducerAlpaka::selectGoodTracksAndVertices(const ZVertexHost& patav
595595
if (nHits == 0) {
596596
break;
597597
}
598-
int vtx_ass_to_track = patavtx_soa.view()[trk_idx].idv();
598+
int vtx_ass_to_track = patavtx_soa.view<reco::ZVertexTracksSoA>()[trk_idx].idv();
599599
if (vtx_ass_to_track >= 0 && vtx_ass_to_track < nv) {
600600
auto patatrackPt = patatracks_tsoa.view()[trk_idx].pt();
601601
++nTrkAssociated[vtx_ass_to_track];
@@ -692,7 +692,7 @@ void L2TauNNProducerAlpaka::fillPatatracks(tensorflow::Tensor& cellGridMatrix,
692692
continue;
693693
const int patatrackNdof = 2 * std::min(6, nHits) - 5;
694694

695-
const int vtx_idx_assTrk = patavtx_soa.view()[it].idv();
695+
const int vtx_idx_assTrk = patavtx_soa.view<reco::ZVertexTracksSoA>()[it].idv();
696696
if (reco::deltaR2(patatrackEta, patatrackPhi, tauEta, tauPhi) < dR2_max) {
697697
std::tie(deta, dphi, eta_idx, phi_idx) =
698698
getEtaPhiIndices(patatrackEta, patatrackPhi, allTaus[tau_idx]->polarP4());

RecoTracker/PixelTrackFitting/plugins/PixelTrackDumpAlpaka.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void PixelTrackDumpAlpakaT<TrackerTraits>::analyze(edm::StreamID streamID,
5959
assert(tracks.view().nTracks());
6060

6161
auto const& vertices = iEvent.get(tokenSoAVertex_);
62-
assert(vertices.view().idv());
62+
assert(vertices.view<reco::ZVertexTracksSoA>().idv());
6363
assert(vertices.view().zv());
6464
assert(vertices.view().wv());
6565
assert(vertices.view().chi2());
6666
assert(vertices.view().ptv2());
67-
assert(vertices.view().ndof());
67+
assert(vertices.view<reco::ZVertexTracksSoA>().ndof());
6868
assert(vertices.view().sortInd());
6969
assert(vertices.view().nvFinal());
7070
}

RecoTracker/PixelVertexFinding/plugins/PixelVertexProducerFromSoAAlpaka.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void PixelVertexProducerFromSoAAlpaka::produce(edm::StreamID streamID,
103103
err(2, 2) *= 2.; // artifically inflate error
104104
//Copy also the tracks (no intention to be efficient....)
105105
for (auto k = 0U; k < indToEdm.size(); ++k) {
106-
if (soa.view()[k].idv() == int16_t(i))
106+
if (soa.view<reco::ZVertexTracksSoA>()[k].idv() == int16_t(i))
107107
itrk.push_back(k);
108108
}
109109
auto nt = itrk.size();
@@ -117,7 +117,8 @@ void PixelVertexProducerFromSoAAlpaka::produce(edm::StreamID streamID,
117117
itrk.clear();
118118
continue;
119119
} // remove outliers
120-
(*vertexes).emplace_back(reco::Vertex::Point(x, y, z), err, soa.view()[i].chi2(), soa.view()[i].ndof(), nt);
120+
(*vertexes).emplace_back(
121+
reco::Vertex::Point(x, y, z), err, soa.view()[i].chi2(), soa.view<reco::ZVertexTracksSoA>()[i].ndof(), nt);
121122
auto &v = (*vertexes).back();
122123
v.reserve(itrk.size());
123124
for (auto it : itrk) {

0 commit comments

Comments
 (0)