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

Alpaka Pixel: Reading layerStart at Runtime and Variable thePitch* #45421

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace pixelClustering {
constexpr uint16_t clusterThresholdPhase2OtherLayers = 4000;

constexpr uint32_t maxNumDigis = 3 * 256 * 1024; // @PU=200 µ=530k σ=50k this is >4σ away
constexpr uint16_t maxNumModules = 4000;
constexpr uint16_t maxNumModules = 5000; // This is an upperlimit taking into account D110 has 4000 modules

constexpr int32_t maxNumClustersPerModules = maxHitsInModule();
constexpr uint16_t invalidModuleId = std::numeric_limits<uint16_t>::max() - 1;
Expand Down
6 changes: 3 additions & 3 deletions Geometry/CommonTopologies/interface/SimplePixelTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace phase2PixelTopology {

constexpr uint32_t numberOfLayers = 28;
constexpr int nPairs = 23 + 6 + 14 + 8 + 4; // include far forward layer pairs
constexpr uint16_t numberOfModules = 3892;
constexpr uint16_t numberOfModules = 4000;

constexpr uint32_t maxNumClustersPerModules = 1024;

Expand Down Expand Up @@ -378,7 +378,7 @@ namespace pixelTopology {
static constexpr int maxDYsize = 10;
static constexpr int maxDYPred = 20;

static constexpr uint16_t numberOfModules = 3892;
static constexpr uint16_t numberOfModules = phase2PixelTopology::numberOfModules;

// 1000 bins < 1024 bins (10 bits) must be:
// - < 32*32 (warpSize*warpSize for block prefix scan for CUDA)
Expand Down Expand Up @@ -475,7 +475,7 @@ namespace pixelTopology {
static constexpr int maxDYsize = 20;
static constexpr int maxDYPred = 20;

static constexpr uint16_t numberOfModules = 1856;
static constexpr uint16_t numberOfModules = phase1PixelTopology::numberOfModules;

static constexpr uint16_t numRowsInRoc = 80;
static constexpr uint16_t numColsInRoc = 52;
Expand Down
14 changes: 7 additions & 7 deletions RecoLocalTracker/SiPixelRecHits/interface/pixelCPEforDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ namespace pixelCPEforDevice {
struct CommonParams {
float theThicknessB;
float theThicknessE;
float thePitchX;
float thePitchY;

uint16_t maxModuleStride;
uint8_t numberOfLaddersInBarrel;
Expand All @@ -77,6 +75,8 @@ namespace pixelCPEforDevice {

float shiftX;
float shiftY;
float thePitchX;
float thePitchY;
float chargeWidthX;
float chargeWidthY;
uint16_t pixmx; // max pix charge
Expand Down Expand Up @@ -239,10 +239,10 @@ namespace pixelCPEforDevice {
// Use an explicit FMA instruction instead of simply (position * pitch + shift) to make sure that
// different compiler optimizations do not produce different code on different architectures.
float xPos = std::fmaf(0.5f * ((float)mx - (float)detParams.nRows) - TrackerTraits::bigPixXCorrection,
comParams.thePitchX,
detParams.thePitchX,
detParams.shiftX);
float yPos = std::fmaf(0.5f * ((float)my - (float)detParams.nCols) - TrackerTraits::bigPixYCorrection,
comParams.thePitchY,
detParams.thePitchY,
detParams.shiftY);

float cotalpha = 0, cotbeta = 0;
Expand All @@ -259,7 +259,7 @@ namespace pixelCPEforDevice {
detParams.chargeWidthX, // lorentz shift in cm
thickness,
cotalpha,
comParams.thePitchX,
detParams.thePitchX,
TrackerTraits::isBigPixX(cp.minRow[ic]),
TrackerTraits::isBigPixX(cp.maxRow[ic]));

Expand All @@ -271,7 +271,7 @@ namespace pixelCPEforDevice {
detParams.chargeWidthY, // lorentz shift in cm
thickness,
cotbeta,
comParams.thePitchY,
detParams.thePitchY,
TrackerTraits::isBigPixY(cp.minCol[ic]),
TrackerTraits::isBigPixY(cp.maxCol[ic]));

Expand Down Expand Up @@ -374,7 +374,7 @@ namespace pixelCPEforDevice {
cp.status[ic].isOneY = isOneY;
cp.status[ic].isBigY = (isOneY & isBigY) | isEdgeY;

auto xoff = -float(TrackerTraits::xOffset) * comParams.thePitchX;
auto xoff = -float(TrackerTraits::xOffset) * detParams.thePitchX;
int low_value = 0;
int high_value = kNumErrorBins - 1;
int bin_value = float(kNumErrorBins) * (cp.xpos[ic] + xoff) / (2 * xoff);
Expand Down
41 changes: 22 additions & 19 deletions RecoLocalTracker/SiPixelRecHits/src/PixelCPEFastParamsHost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {

buffer_->commonParams().theThicknessB = m_DetParams.front().theThickness;
buffer_->commonParams().theThicknessE = m_DetParams.back().theThickness;
buffer_->commonParams().thePitchX = m_DetParams[0].thePitchX;
buffer_->commonParams().thePitchY = m_DetParams[0].thePitchY;

buffer_->commonParams().numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;

LogDebug("PixelCPEFastParamsHost") << "pitch & thickness " << buffer_->commonParams().thePitchX << ' '
<< buffer_->commonParams().thePitchY << " "
<< buffer_->commonParams().theThicknessB << ' '
LogDebug("PixelCPEFastParamsHost") << "thickness " << buffer_->commonParams().theThicknessB << ' '
<< buffer_->commonParams().theThicknessE;

// zero average geometry
memset(&buffer_->averageGeometry(), 0, sizeof(pixelTopology::AverageGeometryT<TrackerTraits>));
// zero layer geometry
memset(&buffer_->layerGeometry(), 0, sizeof(pixelCPEforDevice::LayerGeometryT<TrackerTraits>));

uint32_t nLayers = 0;
uint32_t oldLayer = 0;
uint32_t oldLadder = 0;
float rl = 0;
Expand All @@ -64,6 +62,7 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
int nl = 0;

assert(m_DetParams.size() <= TrackerTraits::numberOfModules);

for (auto i = 0U; i < m_DetParams.size(); ++i) {
auto& p = m_DetParams[i];
auto& g = buffer_->detParams(i);
Expand All @@ -76,8 +75,6 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
g.numPixsInModule = g.nRows * g.nCols;

assert(p.theDet->index() == int(i));
assert(buffer_->commonParams().thePitchY == p.thePitchY);
assert(buffer_->commonParams().thePitchX == p.thePitchX);

g.isBarrel = GeomDetEnumerators::isBarrel(p.thePart);
g.isPosZ = p.theDet->surface().position().z() > 0;
Expand All @@ -94,6 +91,10 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
<< g.layer << " starting at " << g.rawId << '\n'
<< "old layer had " << nl << " ladders";
nl = 0;

assert(nLayers <= TrackerTraits::numberOfLayers);
buffer_->layerGeometry().layerStart[nLayers] = i;
++nLayers;
}
if (oldLadder != ladder) {
oldLadder = ladder;
Expand All @@ -119,6 +120,9 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
g.y0 = p.theOrigin.y();
g.z0 = p.theOrigin.z();

g.thePitchX = p.thePitchX;
g.thePitchY = p.thePitchY;

auto vv = p.theDet->surface().position();
auto rr = pixelCPEforDevice::Rotation(p.theDet->surface().rotation());
g.frame = pixelCPEforDevice::Frame(vv.x(), vv.y(), vv.z(), rr);
Expand All @@ -144,7 +148,7 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
auto toMicron = [&](float x) { return std::min(511, int(x * 1.e4f + 0.5f)); };

// average angle
auto gvx = p.theOrigin.x() + 40.f * buffer_->commonParams().thePitchX;
auto gvx = p.theOrigin.x() + 40.f * p.thePitchX;
auto gvy = p.theOrigin.y();
auto gvz = 1.f / p.theOrigin.z();
//--- Note that the normalization is not required as only the ratio used
Expand Down Expand Up @@ -177,7 +181,7 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
// moduleOffsetX is the definition of TrackerTraits::xOffset,
// needs to be calculated because for Phase2 the modules are not uniform
float moduleOffsetX = -(0.5f * float(g.nRows) + TrackerTraits::bigPixXCorrection);
auto const xoff = moduleOffsetX * buffer_->commonParams().thePitchX;
auto const xoff = moduleOffsetX * g.thePitchX;

for (int ix = 0; ix < pixelCPEforDevice::kNumErrorBins; ++ix) {
auto x = xoff * (1.f - (0.5f + float(ix)) / 8.f);
Expand All @@ -197,11 +201,11 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
// sample yerr as function of position
// moduleOffsetY is the definition of TrackerTraits::yOffset (removed)
float moduleOffsetY = 0.5f * float(g.nCols) + TrackerTraits::bigPixYCorrection;
auto const yoff = -moduleOffsetY * buffer_->commonParams().thePitchY;
auto const yoff = -moduleOffsetY * p.thePitchY;

for (int ix = 0; ix < pixelCPEforDevice::kNumErrorBins; ++ix) {
auto y = yoff * (1.f - (0.5f + float(ix)) / 8.f);
auto gvx = p.theOrigin.x() + 40.f * buffer_->commonParams().thePitchY;
auto gvx = p.theOrigin.x() + 40.f * p.thePitchY;
auto gvy = p.theOrigin.y() - y;
auto gvz = 1.f / p.theOrigin.z();
cp.cotbeta = gvy * gvz;
Expand Down Expand Up @@ -267,8 +271,8 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
ys += 1.f; // first bin 0 is for size 9 (and size is in fixed point 2^3)
if (pixelCPEforDevice::kNumErrorBins - 1 == iy)
ys += 8.f; // last bin for "overflow"
// cp.cotalpha = ys*(buffer_->commonParams().thePitchX/(8.f*thickness)); // use this to print sampling in "x" (and comment the line below)
cp.cotbeta = std::copysign(ys * (buffer_->commonParams().thePitchY / (8.f * thickness)), aveCB);
// cp.cotalpha = ys*(g.thePitchX/(8.f*thickness)); // use this to print sampling in "x" (and comment the line below)
cp.cotbeta = std::copysign(ys * (g.thePitchY / (8.f * thickness)), aveCB);
errorFromTemplates(p, cp, 20000.f);
g.sigmay[iy] = toMicron(cp.sigmay);
LogDebug("PixelCPEFastParamsHost") << "sigmax/sigmay " << i << ' ' << (ys + 4.f) / 8.f << ' ' << cp.cotalpha
Expand All @@ -277,6 +281,9 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
}
} // loop over det

// store last module
buffer_->layerGeometry().layerStart[nLayers] = m_DetParams.size();

constexpr int numberOfModulesInLadder = TrackerTraits::numberOfModulesInLadder;
constexpr int numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;
constexpr int numberOfModulesInBarrel = TrackerTraits::numberOfModulesInBarrel;
Expand Down Expand Up @@ -334,11 +341,7 @@ void PixelCPEFastParamsHost<TrackerTraits>::fillParamsForDevice() {
LogDebug("PixelCPEFastParamsHost") << aveGeom.endCapZ[0] << ' ' << aveGeom.endCapZ[1];
#endif // EDM_ML_DEBUG

// fill Layer and ladders geometry
memset(&buffer_->layerGeometry(), 0, sizeof(pixelCPEforDevice::LayerGeometryT<TrackerTraits>));
memcpy(buffer_->layerGeometry().layerStart,
TrackerTraits::layerStart,
sizeof(pixelCPEforDevice::LayerGeometryT<TrackerTraits>::layerStart));
// fill ladders geometry
memcpy(buffer_->layerGeometry().layer,
pixelTopology::layer<TrackerTraits>.data(),
pixelTopology::layer<TrackerTraits>.size());
Expand Down