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

Porting Pixel Tracks to Alpaka [Not to Merge] #41117

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4c921b3
Rebase
AdrianoDee Nov 29, 2023
bb4318e
Code formats
AdrianoDee Oct 19, 2023
a8dfc70
Fixing tests
AdrianoDee Oct 20, 2023
92bbcc4
Code formats
AdrianoDee Oct 20, 2023
5a92c57
Ports prefixScan, OneToManyAssoc and HistoContainer from CUDAUtilities.
ericcano Oct 19, 2023
77e89f1
[WIP] rescoping in classes by use case.
ericcano Oct 19, 2023
75bdb85
[WIP] Updates unit tests to use use case classes for OnetoManyAssoc v…
ericcano Oct 20, 2023
5be634d
[WIP] Replaces __attributes__ with alpaka macros.
ericcano Oct 20, 2023
5b5a4c1
[WIP] Replaces macro conditional compilation with if constexpr.
ericcano Oct 20, 2023
9d8ed34
[WIP] Move smallest element at the end of the class layout.
ericcano Oct 20, 2023
2161601
[WIP] Removes redundant \'inline\'
ericcano Oct 20, 2023
cb4caf4
[WIP]: remove unused variables.
ericcano Oct 20, 2023
450ad5e
[WIP] Removed unnecessary includes
ericcano Oct 20, 2023
509e4cd
[WIP] Removed anonmous name space for sign conversions.
ericcano Oct 24, 2023
d065a94
[WIP] Adds reminder to simplify when moving to C++20.
ericcano Oct 24, 2023
acc9ca1
[WIP] Adds require to make unit tests fails without GPU.
ericcano Oct 25, 2023
6f9f42a
[WIP] Code format and cleanup.
ericcano Oct 25, 2023
f740a95
[WIP] Adds sanity checks and descriptions of associations (to be cont…
ericcano Nov 1, 2023
5ae08eb
[WIP] Adapts Pixel code to new interface.
ericcano Nov 1, 2023
53316c4
[WIP] Returning module compilation to non-Alpaka: OneToMany should wo…
ericcano Nov 2, 2023
c50a58f
[WIP] Relaxes templates that fails to compile in no-device compilatio…
ericcano Nov 2, 2023
cfbf6f1
[WIP] Moves body of constructor out of header to prevent compiling ke…
ericcano Nov 2, 2023
2826902
[WIP] Code format.
ericcano Nov 2, 2023
9213301
[WIP] Further moves member functions from OneToManyAssocBase to subcl…
ericcano Nov 3, 2023
7611f3f
Clean up and fixing tests for headers
AdrianoDee Oct 30, 2023
d86eb99
Restore histo initialization
AdrianoDee Nov 15, 2023
1744629
Code formats
AdrianoDee Nov 15, 2023
ac63b7b
Code Formats
AdrianoDee Nov 16, 2023
f524bfd
Address first comments on 43295
AdrianoDee Nov 16, 2023
15d6f21
Address first set of comments on 41285
AdrianoDee Nov 16, 2023
9facf5e
Code formats
AdrianoDee Nov 16, 2023
5adcc40
Updates
AdrianoDee Nov 20, 2023
194576a
Code formats
AdrianoDee Nov 21, 2023
22bcf97
Updating customizeHLTforPatatrack with latest modules
AdrianoDee Nov 23, 2023
d83a814
Realing with PR 43295
AdrianoDee Nov 23, 2023
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
@@ -0,0 +1,14 @@
#ifndef CalibTracker_Records_SiPixelGainCalibrationForHLTSoARcd_h
#define CalibTracker_Records_SiPixelGainCalibrationForHLTSoARcd_h

#include "CondFormats/DataRecord/interface/SiPixelGainCalibrationForHLTRcd.h"
#include "FWCore/Framework/interface/DependentRecordImplementation.h"
#include "FWCore/Framework/interface/EventSetupRecordImplementation.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"

class SiPixelGainCalibrationForHLTSoARcd
: public edm::eventsetup::DependentRecordImplementation<
SiPixelGainCalibrationForHLTSoARcd,
edm::mpl::Vector<SiPixelGainCalibrationForHLTRcd, TrackerDigiGeometryRecord>> {};

#endif // CalibTracker_Records_SiPixelGainCalibrationForHLTSoARcd_h
19 changes: 19 additions & 0 deletions CalibTracker/Records/interface/SiPixelMappingSoARecord.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef CalibTracker_Records_interface_SiPixelMappingSoARecord_h
#define CalibTracker_Records_interface_SiPixelMappingSoARecord_h

#include "FWCore/Framework/interface/EventSetupRecordImplementation.h"
#include "FWCore/Framework/interface/DependentRecordImplementation.h"
#include "CondFormats/DataRecord/interface/SiPixelGainCalibrationForHLTRcd.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "RecoTracker/Record/interface/CkfComponentsRecord.h"
#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
#include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"

class SiPixelMappingSoARecord
: public edm::eventsetup::DependentRecordImplementation<SiPixelMappingSoARecord,
edm::mpl::Vector<SiPixelGainCalibrationForHLTRcd,
SiPixelQualityRcd,
SiPixelFedCablingMapRcd,
TrackerDigiGeometryRecord>> {};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "CalibTracker/Records/interface/SiPixelGainCalibrationForHLTSoARcd.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"
#include "FWCore/Utilities/interface/typelookup.h"

EVENTSETUP_RECORD_REG(SiPixelGainCalibrationForHLTSoARcd);
5 changes: 5 additions & 0 deletions CalibTracker/Records/src/SiPixelMappingSoARcd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "CalibTracker/Records/interface/SiPixelMappingSoARecord.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"
#include "FWCore/Utilities/interface/typelookup.h"

EVENTSETUP_RECORD_REG(SiPixelMappingSoARecord);
9 changes: 8 additions & 1 deletion CalibTracker/SiPixelESProducers/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<use name="cuda"/>
<use name="CalibTracker/Records"/>
<use name="CalibTracker/SiPixelESProducers"/>
<use name="CalibTracker/StandaloneTrackerTopology"/>
Expand All @@ -11,6 +10,14 @@
<use name="Geometry/TrackerGeometryBuilder"/>
<use name="MagneticField/Engine"/>
<use name="RecoTracker/Record"/>

<library file="*.cc" name="CalibTrackerSiPixelESProducersPlugins">
<use name="cuda"/>
<flags EDM_PLUGIN="1"/>
</library>

<library file="alpaka/*.cc" name="CalibTrackerSiPixelESProducersPluginsPortable">
<use name="alpaka"/>
<flags ALPAKA_BACKENDS="1"/>
<flags EDM_PLUGIN="1"/>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
#include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
#include "CalibTracker/Records/interface/SiPixelMappingSoARecord.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
#include "DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelMappingHost.h"
#include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelMappingDevice.h"
#include "FWCore/Framework/interface/ESTransientHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"

#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"

#include "RecoTracker/Record/interface/CkfComponentsRecord.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

using namespace cms::alpakatools;

class SiPixelCablingSoAESProducer : public ESProducer {
public:
SiPixelCablingSoAESProducer(edm::ParameterSet const& iConfig)
: ESProducer(iConfig), useQuality_(iConfig.getParameter<bool>("UseQualityInfo")) {
auto cc = setWhatProduced(this);
cablingMapToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<std::string>("CablingMapLabel")});
if (useQuality_) {
qualityToken_ = cc.consumes();
}
geometryToken_ = cc.consumes();
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label");
desc.add<bool>("UseQualityInfo", false);
descriptions.addWithDefaultLabel(desc);
}

std::optional<SiPixelMappingHost> produce(const SiPixelMappingSoARecord& iRecord) {
auto cablingMap = iRecord.getTransientHandle(cablingMapToken_);
const SiPixelQuality* quality = nullptr;
if (useQuality_) {
auto qualityInfo = iRecord.getTransientHandle(qualityToken_);
quality = qualityInfo.product();
}

auto geom = iRecord.getTransientHandle(geometryToken_);
SiPixelMappingHost product(pixelgpudetails::MAX_SIZE, cms::alpakatools::host());
std::vector<unsigned int> const& fedIds = cablingMap->fedIds();
std::unique_ptr<SiPixelFedCablingTree> const& cabling = cablingMap->cablingTree();

unsigned int startFed = fedIds.front();
unsigned int endFed = fedIds.back();

sipixelobjects::CablingPathToDetUnit path;
int index = 1;

auto mapView = product.view();

mapView.hasQuality() = useQuality_;
for (unsigned int fed = startFed; fed <= endFed; fed++) {
for (unsigned int link = 1; link <= pixelgpudetails::MAX_LINK; link++) {
for (unsigned int roc = 1; roc <= pixelgpudetails::MAX_ROC; roc++) {
path = {fed, link, roc};
const sipixelobjects::PixelROC* pixelRoc = cabling->findItem(path);
mapView[index].fed() = fed;
mapView[index].link() = link;
mapView[index].roc() = roc;
if (pixelRoc != nullptr) {
mapView[index].rawId() = pixelRoc->rawId();
mapView[index].rocInDet() = pixelRoc->idInDetUnit();
mapView[index].modToUnpDefault() = false;
if (quality != nullptr)
mapView[index].badRocs() = quality->IsRocBad(pixelRoc->rawId(), pixelRoc->idInDetUnit());
else
mapView[index].badRocs() = false;
} else { // store some dummy number
mapView[index].rawId() = pixelClustering::invalidModuleId;
mapView[index].rocInDet() = pixelClustering::invalidModuleId;
mapView[index].badRocs() = true;
mapView[index].modToUnpDefault() = true;
}
index++;
}
}
} // end of FED loop
// Given FedId, Link and idinLnk; use the following formula
// to get the rawId and idinDU
// index = (FedID-1200) * MAX_LINK* MAX_ROC + (Link-1)* MAX_ROC + idinLnk;
// where, MAX_LINK = 48, MAX_ROC = 8
// FedID varies between 1200 to 1338 (In total 108 FED's)
// Link varies between 1 to 48
// idinLnk varies between 1 to 8

auto trackerGeom = iRecord.getTransientHandle(geometryToken_);

for (int i = 1; i < index; i++) {
if (mapView[i].rawId() == pixelClustering::invalidModuleId) {
mapView[i].moduleId() = pixelClustering::invalidModuleId;
} else {
auto gdet = trackerGeom->idToDetUnit(mapView[i].rawId());
if (!gdet) {
LogDebug("SiPixelCablingSoAESProducer") << " Not found: " << mapView[i].rawId() << std::endl;
continue;
}
mapView[i].moduleId() = gdet->index();
}
LogDebug("SiPixelCablingSoAESProducer")
<< "----------------------------------------------------------------------------" << std::endl;
LogDebug("SiPixelCablingSoAESProducer") << i << std::setw(20) << mapView[i].fed() << std::setw(20)
<< mapView[i].link() << std::setw(20) << mapView[i].roc() << std::endl;
LogDebug("SiPixelCablingSoAESProducer")
<< i << std::setw(20) << mapView[i].rawId() << std::setw(20) << mapView[i].rocInDet() << std::setw(20)
<< mapView[i].moduleId() << std::endl;
LogDebug("SiPixelCablingSoAESProducer")
<< i << std::setw(20) << mapView[i].badRocs() << std::setw(20) << std::endl;
LogDebug("SiPixelCablingSoAESProducer")
<< "----------------------------------------------------------------------------" << std::endl;
}

mapView.size() = index - 1;

return product;
}

private:
edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> cablingMapToken_;
edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd> qualityToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geometryToken_;
const bool useQuality_;
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(SiPixelCablingSoAESProducer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLTHost.h"
#include "CalibTracker/Records/interface/SiPixelGainCalibrationForHLTSoARcd.h"
#include "CondFormats/DataRecord/interface/SiPixelGainCalibrationForHLTRcd.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLT.h"
#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"

#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <memory>

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class SiPixelGainCalibrationForHLTSoAESProducer : public ESProducer {
public:
explicit SiPixelGainCalibrationForHLTSoAESProducer(const edm::ParameterSet& iConfig);
std::unique_ptr<SiPixelGainCalibrationForHLTHost> produce(const SiPixelGainCalibrationForHLTSoARcd& iRecord);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::ESGetToken<SiPixelGainCalibrationForHLT, SiPixelGainCalibrationForHLTRcd> gainsToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geometryToken_;
};

SiPixelGainCalibrationForHLTSoAESProducer::SiPixelGainCalibrationForHLTSoAESProducer(const edm::ParameterSet& iConfig)
: ESProducer(iConfig) {
auto cc = setWhatProduced(this);
gainsToken_ = cc.consumes();
geometryToken_ = cc.consumes();
}

void SiPixelGainCalibrationForHLTSoAESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
descriptions.addWithDefaultLabel(desc);
}

std::unique_ptr<SiPixelGainCalibrationForHLTHost> SiPixelGainCalibrationForHLTSoAESProducer::produce(
const SiPixelGainCalibrationForHLTSoARcd& iRecord) {
auto const& gains = iRecord.get(gainsToken_);
auto const& geom = iRecord.get(geometryToken_);

auto product = std::make_unique<SiPixelGainCalibrationForHLTHost>(gains.data().size(), cms::alpakatools::host());

// bizzarre logic (looking for fist strip-det) don't ask
auto const& dus = geom.detUnits();
unsigned int n_detectors = dus.size();
for (unsigned int i = 1; i < 7; ++i) {
const auto offset = geom.offsetDU(GeomDetEnumerators::tkDetEnum[i]);
if (offset != dus.size() && dus[offset]->type().isTrackerStrip()) {
if (n_detectors > offset)
n_detectors = offset;
}
}

LogDebug("SiPixelGainCalibrationForHLTSoA")
<< "caching calibs for " << n_detectors << " pixel detectors of size " << gains.data().size() << '\n'
<< "sizes " << sizeof(char) << ' ' << sizeof(uint8_t) << ' ' << sizeof(siPixelGainsSoA::DecodingStructure);

for (size_t i = 0; i < gains.data().size(); i = i + 2) {
product->view().v_pedestals()[i / 2].gain = gains.data()[i];
product->view().v_pedestals()[i / 2].ped = gains.data()[i + 1];
}

//std::copy here
// do not read back from the (possibly write-combined) memory buffer
auto minPed = gains.getPedLow();
auto maxPed = gains.getPedHigh();
auto minGain = gains.getGainLow();
auto maxGain = gains.getGainHigh();
auto nBinsToUseForEncoding = 253;

// we will simplify later (not everything is needed....)
product->view().minPed() = minPed;
product->view().maxPed() = maxPed;
product->view().minGain() = minGain;
product->view().maxGain() = maxGain;

product->view().numberOfRowsAveragedOver() = 80;
product->view().nBinsToUseForEncoding() = nBinsToUseForEncoding;
product->view().deadFlag() = 255;
product->view().noisyFlag() = 254;

product->view().pedPrecision() = static_cast<float>(maxPed - minPed) / nBinsToUseForEncoding;
product->view().gainPrecision() = static_cast<float>(maxGain - minGain) / nBinsToUseForEncoding;

LogDebug("SiPixelGainCalibrationForHLTSoA")
<< "precisions g " << product->view().pedPrecision() << ' ' << product->view().gainPrecision();

// fill the index map
auto const& ind = gains.getIndexes();
LogDebug("SiPixelGainCalibrationForHLTSoA") << ind.size() << " " << n_detectors;

for (auto i = 0U; i < n_detectors; ++i) {
auto p = std::lower_bound(
ind.begin(), ind.end(), dus[i]->geographicalId().rawId(), SiPixelGainCalibrationForHLT::StrictWeakOrdering());
assert(p != ind.end() && p->detid == dus[i]->geographicalId());
assert(p->iend <= gains.data().size());
assert(p->iend >= p->ibegin);
assert(0 == p->ibegin % 2);
assert(0 == p->iend % 2);
assert(p->ibegin != p->iend);
assert(p->ncols > 0);

product->view().modStarts()[i] = p->ibegin;
product->view().modEnds()[i] = p->iend;
product->view().modCols()[i] = p->ncols;

if (ind[i].detid != dus[i]->geographicalId())
LogDebug("SiPixelGainCalibrationForHLTSoA") << ind[i].detid << "!=" << dus[i]->geographicalId();
}

return product;
}

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(SiPixelGainCalibrationForHLTSoAESProducer);
4 changes: 4 additions & 0 deletions CondFormats/SiPixelObjects/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<use name="alpaka"/>
<use name="DataFormats/DetId"/>
<use name="DataFormats/SiPixelDetId"/>
<use name="CalibFormats/SiPixelObjects"/>
Expand All @@ -12,6 +13,9 @@
<use name="FWCore/MessageLogger"/>
<use name="Geometry/CommonDetUnit"/>
<use name="Geometry/CommonTopologies"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<use name="HeterogeneousCore/AlpakaCore"/>
<flags ALPAKA_BACKENDS="1"/>
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
<flags ALPAKA_BACKENDS="1"/>
<flags ALPAKA_BACKENDS="cuda rocm"/>

Copy link
Contributor

Choose a reason for hiding this comment

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

@smuzaffar would it be possible to implement support for something like

<flags ALPAKA_BACKENDS="!serial"/>

?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, I will look in to it

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe !serial would not work if we enable the TBB backend.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to remind on the previous discussion on this topic #40792 (comment) (and an issue cms-sw/cmssw-config#93)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I keep forgetting about that.
OK, let's keep it like this for now.

<export>
<lib name="1"/>
</export>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CondFormats_SiPixelObjects_SiPixelGainCalibrationForHLTHost_h
#define CondFormats_SiPixelObjects_SiPixelGainCalibrationForHLTHost_h

#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLTLayout.h"

using SiPixelGainCalibrationForHLTHost = PortableHostCollection<SiPixelGainCalibrationForHLTSoA>;

#endif // CondFormats_SiPixelObjects_SiPixelGainCalibrationForHLTHost_h
Loading