Skip to content

Commit 8cbe916

Browse files
author
AdrianoDee
committed
Phase II Patatrack Pixel Local Reco
1 parent 4d5c91a commit 8cbe916

27 files changed

+902
-385
lines changed

CUDADataFormats/SiPixelCluster/interface/gpuClusteringConstants.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace gpuClustering {
1111
#else
1212
// optimized for real data PU 50
1313
// tested on MC events with 55-75 pileup events
14-
constexpr uint32_t maxHitsInIter() { return 160; }
14+
constexpr uint32_t maxHitsInIter() { return 160; } //TODO better tuning for PU 140-200
1515
#endif
1616
constexpr uint32_t maxHitsInModule() { return 1024; }
1717

18-
constexpr uint16_t maxNumModules = 2000;
18+
constexpr uint32_t maxNumDigis = 3*256*1024; // @PU=200 µ=530k σ=50k this is >4σ away
19+
constexpr uint16_t maxNumModules = 4000;
20+
1921
constexpr int32_t maxNumClustersPerModules = maxHitsInModule();
2022
constexpr uint16_t invalidModuleId = std::numeric_limits<uint16_t>::max() - 1;
2123
constexpr int invalidClusterId = -9999;

CUDADataFormats/TrackingRecHit/interface/TrackingRecHit2DHeterogeneous.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "CUDADataFormats/TrackingRecHit/interface/TrackingRecHit2DSOAView.h"
55
#include "CUDADataFormats/Common/interface/HeterogeneousSoA.h"
6+
#include "RecoLocalTracker/SiPixelRecHits/interface/pixelCPEforGPU.h"
67

78
template <typename Traits>
89
class TrackingRecHit2DHeterogeneous {
@@ -16,6 +17,7 @@ class TrackingRecHit2DHeterogeneous {
1617

1718
explicit TrackingRecHit2DHeterogeneous(
1819
uint32_t nHits,
20+
bool isUpgrade,
1921
int32_t offsetBPIX2,
2022
pixelCPEforGPU::ParamsOnGPU const* cpeParams,
2123
uint32_t const* hitsModuleStart,
@@ -33,6 +35,7 @@ class TrackingRecHit2DHeterogeneous {
3335
TrackingRecHit2DSOAView const* view() const { return m_view.get(); }
3436

3537
auto nHits() const { return m_nHits; }
38+
auto nMaxModules() const { return m_nMaxModules; }
3639
auto offsetBPIX2() const { return m_offsetBPIX2; }
3740

3841
auto hitsModuleStart() const { return m_hitsModuleStart; }
@@ -62,10 +65,12 @@ class TrackingRecHit2DHeterogeneous {
6265
unique_ptr<TrackingRecHit2DSOAView> m_view; //!
6366

6467
uint32_t m_nHits;
68+
bool m_isUpgrade;
6569
int32_t m_offsetBPIX2;
6670

6771
uint32_t const* m_hitsModuleStart; // needed for legacy, this is on GPU!
6872

73+
uint32_t m_nMaxModules;
6974
// needed as kernel params...
7075
PhiBinner* m_phiBinner;
7176
PhiBinner::index_type* m_phiBinnerStorage;
@@ -83,15 +88,18 @@ using TrackingRecHit2DHost = TrackingRecHit2DHeterogeneous<cms::cudacompat::Host
8388
template <typename Traits>
8489
TrackingRecHit2DHeterogeneous<Traits>::TrackingRecHit2DHeterogeneous(
8590
uint32_t nHits,
91+
bool isUpgrade,
8692
int32_t offsetBPIX2,
8793
pixelCPEforGPU::ParamsOnGPU const* cpeParams,
8894
uint32_t const* hitsModuleStart,
8995
cudaStream_t stream,
9096
TrackingRecHit2DHeterogeneous<cms::cudacompat::GPUTraits> const* input)
91-
: m_nHits(nHits), m_offsetBPIX2(offsetBPIX2), m_hitsModuleStart(hitsModuleStart) {
97+
: m_nHits(nHits), m_isUpgrade(isUpgrade), m_offsetBPIX2(offsetBPIX2), m_hitsModuleStart(hitsModuleStart) {
9298
auto view = Traits::template make_host_unique<TrackingRecHit2DSOAView>(stream);
9399

100+
m_nMaxModules = m_isUpgrade ? phase2PixelTopology::numberOfModules : phase1PixelTopology::numberOfModules;
94101
view->m_nHits = nHits;
102+
view->m_nMaxModules = m_nMaxModules;
95103
m_view = Traits::template make_unique<TrackingRecHit2DSOAView>(stream); // leave it on host and pass it by value?
96104
m_AverageGeometryStore = Traits::template make_unique<TrackingRecHit2DSOAView::AverageGeometry>(stream);
97105
view->m_averageGeometry = m_AverageGeometryStore.get();
@@ -120,8 +128,9 @@ TrackingRecHit2DHeterogeneous<Traits>::TrackingRecHit2DHeterogeneous(
120128
copyFromGPU(input, stream);
121129
} else {
122130
assert(input == nullptr);
131+
auto nL = m_isUpgrade ? phase2PixelTopology::numberOfLayers : phase1PixelTopology::numberOfLayers;
123132
m_store16 = Traits::template make_unique<uint16_t[]>(nHits * n16, stream);
124-
m_store32 = Traits::template make_unique<float[]>(nHits * n32 + phase1PixelTopology::numberOfLayers + 1, stream);
133+
m_store32 = Traits::template make_unique<float[]>(nHits * n32 + nL + 1, stream);
125134
m_PhiBinnerStore = Traits::template make_unique<TrackingRecHit2DSOAView::PhiBinner>(stream);
126135
}
127136

CUDADataFormats/TrackingRecHit/interface/TrackingRecHit2DSOAView.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "CUDADataFormats/SiPixelCluster/interface/gpuClusteringConstants.h"
77
#include "HeterogeneousCore/CUDAUtilities/interface/HistoContainer.h"
88
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h"
9-
#include "Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h"
9+
#include "Geometry/TrackerGeometryBuilder/interface/pixelTopology.h"
1010
#include "CUDADataFormats/TrackingRecHit/interface/SiPixelHitStatus.h"
1111

1212
namespace pixelCPEforGPU {
@@ -20,15 +20,17 @@ class TrackingRecHit2DSOAView {
2020

2121
using hindex_type = uint32_t; // if above is <=2^32
2222

23-
using PhiBinner = cms::cuda::HistoContainer<int16_t, 128, -1, 8 * sizeof(int16_t), hindex_type, 10>;
23+
using PhiBinner =
24+
cms::cuda::HistoContainer<int16_t, 256, -1, 8 * sizeof(int16_t), hindex_type, 28>; //28 for phase2 geometry
2425

25-
using AverageGeometry = phase1PixelTopology::AverageGeometry;
26+
using AverageGeometry = pixelTopology::AverageGeometry;
2627

2728
template <typename>
2829
friend class TrackingRecHit2DHeterogeneous;
2930
friend class TrackingRecHit2DReduced;
3031

3132
__device__ __forceinline__ uint32_t nHits() const { return m_nHits; }
33+
__device__ __forceinline__ uint32_t nMaxModules() const { return m_nMaxModules; }
3234

3335
__device__ __forceinline__ float& xLocal(int i) { return m_xl[i]; }
3436
__device__ __forceinline__ float xLocal(int i) const { return __ldg(m_xl + i); }
@@ -114,6 +116,7 @@ class TrackingRecHit2DSOAView {
114116
PhiBinner::index_type* m_phiBinnerStorage;
115117

116118
uint32_t m_nHits;
119+
uint32_t m_nMaxModules;
117120
};
118121

119122
#endif // CUDADataFormats_TrackingRecHit_interface_TrackingRecHit2DSOAView_h

CUDADataFormats/TrackingRecHit/src/TrackingRecHit2DHeterogeneous.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ cms::cuda::host::unique_ptr<float[]> TrackingRecHit2DGPU::localCoordToHostAsync(
1313

1414
template <>
1515
cms::cuda::host::unique_ptr<uint32_t[]> TrackingRecHit2DGPU::hitsModuleStartToHostAsync(cudaStream_t stream) const {
16-
auto ret = cms::cuda::make_host_unique<uint32_t[]>(gpuClustering::maxNumModules + 1, stream);
16+
auto ret = cms::cuda::make_host_unique<uint32_t[]>(nMaxModules() + 1, stream);
1717
cudaCheck(cudaMemcpyAsync(
18-
ret.get(), m_hitsModuleStart, sizeof(uint32_t) * (gpuClustering::maxNumModules + 1), cudaMemcpyDefault, stream));
18+
ret.get(), m_hitsModuleStart, sizeof(uint32_t) * (nMaxModules() + 1), cudaMemcpyDefault, stream));
1919
return ret;
2020
}
2121

CUDADataFormats/TrackingRecHit/test/TrackingRecHit2DCUDA_t.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ int main() {
1616
cudaCheck(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
1717

1818
auto nHits = 200;
19+
auto nModules = 2000;
1920
// inner scope to deallocate memory before destroying the stream
2021
{
21-
TrackingRecHit2DGPU tkhit(nHits, 0, nullptr, nullptr, stream);
22+
TrackingRecHit2DGPU tkhit(nHits, nModules, 0, nullptr, nullptr, stream);
2223

2324
testTrackingRecHit2D::runKernels(tkhit.view());
2425

25-
TrackingRecHit2DHost tkhitH(nHits, 0, nullptr, nullptr, stream, &tkhit);
26+
TrackingRecHit2DHost tkhitH(nHits, nModules, 0, nullptr, nullptr, stream, &tkhit);
2627
cudaStreamSynchronize(stream);
2728
assert(tkhitH.view());
2829
assert(tkhitH.view()->nHits() == unsigned(nHits));
30+
assert(tkhitH.view()->nMaxModules() == unsigned(nModules));
2931
}
3032

3133
cudaCheck(cudaStreamDestroy(stream));

CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLWorker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
4646
#include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyMap.h"
4747
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
48-
#include "Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h"
48+
#include "Geometry/TrackerGeometryBuilder/interface/pixelTopology.h"
4949
#include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
5050
#include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
5151
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"

Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h renamed to Geometry/TrackerGeometryBuilder/interface/pixelTopology.h

Lines changed: 109 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
#ifndef Geometry_TrackerGeometryBuilder_phase1PixelTopology_h
2-
#define Geometry_TrackerGeometryBuilder_phase1PixelTopology_h
1+
#ifndef Geometry_TrackerGeometryBuilder_pixelTopology_h
2+
#define Geometry_TrackerGeometryBuilder_pixelTopology_h
33

44
#include <cstdint>
55
#include <array>
66

7+
namespace pixelTopology {
8+
template <class Function, std::size_t... Indices>
9+
constexpr auto map_to_array_helper(Function f, std::index_sequence<Indices...>)
10+
-> std::array<typename std::result_of<Function(std::size_t)>::type, sizeof...(Indices)> {
11+
return {{f(Indices)...}};
12+
}
13+
14+
template <int N, class Function>
15+
constexpr auto map_to_array(Function f) -> std::array<typename std::result_of<Function(std::size_t)>::type, N> {
16+
return map_to_array_helper(f, std::make_index_sequence<N>{});
17+
}
18+
19+
static constexpr auto maxNumberOfLadders = 160;
20+
constexpr uint32_t maxLayers = 28;
21+
22+
struct AverageGeometry {
23+
//
24+
float ladderZ[maxNumberOfLadders];
25+
float ladderX[maxNumberOfLadders];
26+
float ladderY[maxNumberOfLadders];
27+
float ladderR[maxNumberOfLadders];
28+
float ladderMinZ[maxNumberOfLadders];
29+
float ladderMaxZ[maxNumberOfLadders];
30+
float endCapZ[2]; // just for pos and neg Layer1
31+
};
32+
33+
constexpr inline uint16_t localY(uint16_t py, uint16_t n) {
34+
auto roc = py / n;
35+
auto shift = 2 * roc;
36+
auto yInRoc = py - n * roc;
37+
if (yInRoc > 0)
38+
shift += 1;
39+
return py + shift;
40+
}
41+
42+
} // namespace pixelTopology
43+
744
namespace phase1PixelTopology {
845

46+
constexpr uint16_t numberOfModulesInBarrel = 1184;
47+
constexpr uint16_t numberOfModulesInLadder = 8;
48+
constexpr uint16_t numberOfLaddersInBarrel = numberOfModulesInBarrel / numberOfModulesInLadder;
49+
950
constexpr uint16_t numRowsInRoc = 80;
1051
constexpr uint16_t numColsInRoc = 52;
1152
constexpr uint16_t lastRowInRoc = numRowsInRoc - 1;
@@ -54,21 +95,7 @@ namespace phase1PixelTopology {
5495
"E-3" // negative endcap
5596
};
5697

57-
constexpr uint32_t numberOfModulesInBarrel = 1184;
58-
constexpr uint32_t numberOfLaddersInBarrel = numberOfModulesInBarrel / 8;
59-
60-
template <class Function, std::size_t... Indices>
61-
constexpr auto map_to_array_helper(Function f, std::index_sequence<Indices...>)
62-
-> std::array<typename std::result_of<Function(std::size_t)>::type, sizeof...(Indices)> {
63-
return {{f(Indices)...}};
64-
}
65-
66-
template <int N, class Function>
67-
constexpr auto map_to_array(Function f) -> std::array<typename std::result_of<Function(std::size_t)>::type, N> {
68-
return map_to_array_helper(f, std::make_index_sequence<N>{});
69-
}
70-
71-
constexpr uint32_t findMaxModuleStride() {
98+
constexpr uint16_t findMaxModuleStride() {
7299
bool go = true;
73100
int n = 2;
74101
while (go) {
@@ -85,7 +112,7 @@ namespace phase1PixelTopology {
85112
return n / 2;
86113
}
87114

88-
constexpr uint32_t maxModuleStride = findMaxModuleStride();
115+
constexpr uint16_t maxModuleStride = findMaxModuleStride();
89116

90117
constexpr uint8_t findLayer(uint32_t detId, uint8_t sl = 0) {
91118
for (uint8_t i = sl; i < std::size(layerStart); ++i)
@@ -107,7 +134,7 @@ namespace phase1PixelTopology {
107134
__device__
108135
#endif
109136
constexpr std::array<uint8_t, layerIndexSize>
110-
layer = map_to_array<layerIndexSize>(findLayerFromCompact);
137+
layer = pixelTopology::map_to_array<layerIndexSize>(findLayerFromCompact);
111138

112139
constexpr uint8_t getLayer(uint32_t detId) {
113140
return phase1PixelTopology::layer[detId / phase1PixelTopology::maxModuleStride];
@@ -117,7 +144,7 @@ namespace phase1PixelTopology {
117144
bool res = true;
118145
for (auto i = 0U; i < numberOfModules; ++i) {
119146
auto j = i / maxModuleStride;
120-
res &= (layer[j] < 10);
147+
res &= (layer[j] < numberOfLayers);
121148
res &= (i >= layerStart[layer[j]]);
122149
res &= (i < layerStart[layer[j] + 1]);
123150
}
@@ -172,18 +199,67 @@ namespace phase1PixelTopology {
172199
return py + shift;
173200
}
174201

175-
//FIXME move it elsewhere?
176-
struct AverageGeometry {
177-
static constexpr auto numberOfLaddersInBarrel = phase1PixelTopology::numberOfLaddersInBarrel;
178-
float ladderZ[numberOfLaddersInBarrel];
179-
float ladderX[numberOfLaddersInBarrel];
180-
float ladderY[numberOfLaddersInBarrel];
181-
float ladderR[numberOfLaddersInBarrel];
182-
float ladderMinZ[numberOfLaddersInBarrel];
183-
float ladderMaxZ[numberOfLaddersInBarrel];
184-
float endCapZ[2]; // just for pos and neg Layer1
185-
};
186-
187202
} // namespace phase1PixelTopology
188203

189-
#endif // Geometry_TrackerGeometryBuilder_phase1PixelTopology_h
204+
namespace phase2PixelTopology {
205+
206+
constexpr uint32_t numberOfModulesInBarrel = 756;
207+
constexpr uint32_t numberOfModulesInLadder = 9;
208+
constexpr uint32_t numberOfLaddersInBarrel = numberOfModulesInBarrel / numberOfModulesInLadder;
209+
210+
constexpr uint32_t numberOfModules = 3892;
211+
constexpr uint8_t numberOfLayers = 28;
212+
213+
constexpr uint32_t layerStart[numberOfLayers + 1] = {
214+
0, 108, 324, 504, //Barrel
215+
756, 864, 972, 1080, 1188, 1296, 1404, 1512, 1620, 1796, 1972, 2148, //Fp
216+
2324, 2432, 2540, 2648, 2756, 2864, 2972, 3080, 3188, 3364, 3540, 3716, //Np
217+
numberOfModules};
218+
219+
constexpr uint16_t findMaxModuleStride() {
220+
bool go = true;
221+
int n = 2;
222+
while (go) {
223+
for (uint8_t i = 1; i < numberOfLayers + 1; ++i) {
224+
if (layerStart[i] % n != 0) {
225+
go = false;
226+
break;
227+
}
228+
}
229+
if (!go)
230+
break;
231+
n *= 2;
232+
}
233+
return n / 2;
234+
}
235+
236+
constexpr uint16_t maxModuleStride = findMaxModuleStride();
237+
238+
constexpr uint8_t findLayerFromCompact(uint32_t detId) {
239+
detId *= maxModuleStride;
240+
for (uint8_t i = 0; i < numberOfLayers + 1; ++i)
241+
if (detId < layerStart[i + 1])
242+
return i;
243+
return numberOfLayers + 1;
244+
}
245+
246+
constexpr uint16_t layerIndexSize = numberOfModules / maxModuleStride;
247+
constexpr std::array<uint8_t, layerIndexSize> layer =
248+
pixelTopology::map_to_array<layerIndexSize>(findLayerFromCompact);
249+
250+
constexpr bool validateLayerIndex() {
251+
bool res = true;
252+
for (auto i = 0U; i < numberOfModules; ++i) {
253+
auto j = i / maxModuleStride;
254+
res &= (layer[j] < numberOfLayers);
255+
res &= (i >= layerStart[layer[j]]);
256+
res &= (i < layerStart[layer[j] + 1]);
257+
}
258+
return res;
259+
}
260+
261+
static_assert(validateLayerIndex(), "phase2 layer from detIndex algo is buggy");
262+
263+
} // namespace phase2PixelTopology
264+
265+
#endif // Geometry_TrackerGeometryBuilder_pixelTopology_h

Geometry/TrackerGeometryBuilder/test/phase1PixelTopology_t.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <iostream>
33
#include <tuple>
44

5-
#include "Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h"
5+
#include "Geometry/TrackerGeometryBuilder/interface/pixelTopology.h"
66

77
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
88
#include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h"

RecoLocalTracker/SiPixelClusterizer/plugins/SiPixelClusterThresholds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ struct SiPixelClusterThresholds {
1010
};
1111

1212
constexpr SiPixelClusterThresholds kSiPixelClusterThresholdsDefaultPhase1{.layer1 = 2000, .otherLayers = 4000};
13+
constexpr SiPixelClusterThresholds kSiPixelClusterThresholdsDefaultPhase2{.layer1 = 4000, .otherLayers = 4000};
1314

1415
#endif // RecoLocalTracker_SiPixelClusterizer_plugins_SiPixelClusterThresholds_h

0 commit comments

Comments
 (0)