Skip to content

Commit

Permalink
Code checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoDee committed Apr 3, 2023
1 parent 77c2aa9 commit 99f9438
Show file tree
Hide file tree
Showing 28 changed files with 199 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ class SiPixelGainCalibrationForHLTSoARcd
edm::mpl::Vector<SiPixelGainCalibrationForHLTRcd, TrackerDigiGeometryRecord>> {};

#endif // CalibTracker_Records_SiPixelGainCalibrationForHLTSoARcd_h

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC ALPAKA_FN_INLINE static cms::alpakatools::device_buffer<Device, unsigned char[]>
getModToUnpRegionalAsync(std::set<unsigned int> const& modules,
const SiPixelFedCablingTree* cabling,
std::vector<unsigned int> const& fedIds,
std::vector<unsigned int> const& fedIds,
Queue& queue) {
auto modToUnpDevice = cms::alpakatools::make_device_buffer<unsigned char[]>(queue, pixelgpudetails::MAX_SIZE);
auto modToUnpHost = cms::alpakatools::make_host_buffer<unsigned char[]>(queue, pixelgpudetails::MAX_SIZE);
Expand Down Expand Up @@ -52,4 +52,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
}
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
#endif //CalibTracker_SiPixelESProducers_alpaka_SiPixelMappingUtilities_h
#endif //CalibTracker_SiPixelESProducers_alpaka_SiPixelMappingUtilities_h
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,38 @@
#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLTLayout.h"


struct SiPixelGainUtilities {

ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC ALPAKA_FN_INLINE static std::pair<float, float> getPedAndGain(
const SiPixelGainCalibrationForHLTSoAConstView& view,
uint32_t moduleInd,
int col,
int row,
bool& isDeadColumn,
bool& isNoisyColumn) {
auto range = view.rangeAndCols()[moduleInd].first;
auto nCols = view.rangeAndCols()[moduleInd].second;
// determine what averaged data block we are in (there should be 1 or 2 of these depending on if plaquette is 1 by X or 2 by X
unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
unsigned int lengthOfAveragedDataInEachColumn = 2; // we always only have two values per column averaged block
unsigned int numberOfDataBlocksToSkip = row / view.numberOfRowsAveragedOver();

auto offset =
range.first + col * lengthOfColumnData + lengthOfAveragedDataInEachColumn * numberOfDataBlocksToSkip;

assert(offset < range.second);
assert(offset < 3088384);
assert(0 == offset % 2);

auto lp = view.v_pedestals();
auto s = lp[offset / 2];

isDeadColumn = (s.ped & 0xFF) == view.deadFlag();
isNoisyColumn = (s.ped & 0xFF) == view.noisyFlag();

float decodePed = float(s.gain & 0xFF) * view.gainPrecision() + view.minGain();
float decodeGain = float(s.ped & 0xFF) * view.pedPrecision() + view.minPed();

return std::make_pair(decodePed, decodeGain);
};
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC ALPAKA_FN_INLINE static std::pair<float, float> getPedAndGain(
const SiPixelGainCalibrationForHLTSoAConstView& view,
uint32_t moduleInd,
int col,
int row,
bool& isDeadColumn,
bool& isNoisyColumn) {
auto range = view.rangeAndCols()[moduleInd].first;
auto nCols = view.rangeAndCols()[moduleInd].second;
// determine what averaged data block we are in (there should be 1 or 2 of these depending on if plaquette is 1 by X or 2 by X
unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
unsigned int lengthOfAveragedDataInEachColumn = 2; // we always only have two values per column averaged block
unsigned int numberOfDataBlocksToSkip = row / view.numberOfRowsAveragedOver();

auto offset = range.first + col * lengthOfColumnData + lengthOfAveragedDataInEachColumn * numberOfDataBlocksToSkip;

assert(offset < range.second);
assert(offset < 3088384);
assert(0 == offset % 2);

auto lp = view.v_pedestals();
auto s = lp[offset / 2];

isDeadColumn = (s.ped & 0xFF) == view.deadFlag();
isNoisyColumn = (s.ped & 0xFF) == view.noisyFlag();

float decodePed = float(s.gain & 0xFF) * view.gainPrecision() + view.minGain();
float decodeGain = float(s.ped & 0xFF) * view.pedPrecision() + view.minPed();

return std::make_pair(decodePed, decodeGain);
};
};

#endif //CondFormats_SiPixelObjects_alpaka_SiPixelGainUtilities_h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void SiPixelCompareRecHitsSoAAlpaka<T>::analyze(const edm::Event& iEvent, const
//
template <typename T>
void SiPixelCompareRecHitsSoAAlpaka<T>::bookHistograms(DQMStore::IBooker& iBook,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
iBook.cd();
iBook.setCurrentFolder(topFolderName_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ void SiPixelCompareVertexSoAAlpaka::analyze(const edm::Event& iEvent, const edm:
// -- Book Histograms
//
void SiPixelCompareVertexSoAAlpaka::bookHistograms(DQMStore::IBooker& ibooker,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
ibooker.cd();
ibooker.setCurrentFolder(topFolderName_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ void SiPixelMonitorRecHitsSoAAlpaka<T>::analyze(const edm::Event& iEvent, const
//
template <typename T>
void SiPixelMonitorRecHitsSoAAlpaka<T>::bookHistograms(DQMStore::IBooker& iBook,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
iBook.cd();
iBook.setCurrentFolder(topFolderName_);

Expand Down
11 changes: 5 additions & 6 deletions DQM/SiPixelHeterogeneous/plugins/SiPixelMonitorTrackSoAAlpaka.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "DQMServices/Core/interface/DQMStore.h"
#include "DataFormats/Track/interface/TrackSoAHost.h"


template <typename T>
class SiPixelMonitorTrackSoAAlpaka : public DQMEDAnalyzer {
public:
Expand Down Expand Up @@ -90,7 +89,7 @@ void SiPixelMonitorTrackSoAAlpaka<T>::analyze(const edm::Event& iEvent, const ed
int32_t nLooseAndAboveTracks = 0;

for (int32_t it = 0; it < maxTracks; ++it) {
auto nHits = tsoa.view().detIndices().size(it);
auto nHits = tsoa.view().detIndices().size(it);
auto nLayers = tsoa.view()[it].nLayers();
if (nHits == 0)
break; // this is a guard
Expand All @@ -107,9 +106,9 @@ void SiPixelMonitorTrackSoAAlpaka<T>::analyze(const edm::Event& iEvent, const ed
continue;

// fill parameters only for quality >= loose

float chi2 = tsoa.view()[it].chi2();
float phi = tsoa.view()[it].state()(0); //TODO: put these numbers in enum
float phi = tsoa.view()[it].state()(0); //TODO: put these numbers in enum
float zip = tsoa.view()[it].state()(4);
float eta = tsoa.view()[it].eta();
float tip = tsoa.view()[it].state()(1);
Expand Down Expand Up @@ -139,8 +138,8 @@ void SiPixelMonitorTrackSoAAlpaka<T>::analyze(const edm::Event& iEvent, const ed
//
template <typename T>
void SiPixelMonitorTrackSoAAlpaka<T>::bookHistograms(DQMStore::IBooker& iBook,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
iBook.cd();
iBook.setCurrentFolder(topFolderName_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ void SiPixelMonitorVertexSoAAlpaka::analyze(const edm::Event& iEvent, const edm:
// -- Book Histograms
//
void SiPixelMonitorVertexSoAAlpaka::bookHistograms(DQMStore::IBooker& ibooker,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
//std::string top_folder = ""//
ibooker.cd();
ibooker.setCurrentFolder(topFolderName_);
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/TrackingRecHitSoA/test/alpaka/Hits_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

int main() {
/* const auto host = cms::alpakatools::host();
/* const auto host = cms::alpakatools::host();
const auto device = cms::alpakatools::devices<Platform>()[0];
Queue queue(device);
Expand Down
1 change: 0 additions & 1 deletion DataFormats/Vertex/interface/ZVertexDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ namespace zVertex {
} // namespace zVertex

#endif

8 changes: 4 additions & 4 deletions Geometry/CommonTopologies/interface/SimplePixelTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ namespace pixelTopology {
using hindex_type = uint32_t; // FIXME from siPixelRecHitsHeterogeneousProduct
using tindex_type = uint32_t; // for tuples
using cindex_type = uint32_t; // for cells
static constexpr uint32_t maxNumberOfHits = 256 * 1024;

static constexpr uint32_t maxNumberOfHits = 256 * 1024;
static constexpr uint32_t maxCellNeighbors = 64;
static constexpr uint32_t maxCellTracks = 302;
static constexpr uint32_t maxHitsOnTrack = 15;
Expand Down Expand Up @@ -382,8 +382,8 @@ namespace pixelTopology {
using hindex_type = uint32_t; // FIXME from siPixelRecHitsHeterogeneousProduct
using tindex_type = uint16_t; // for tuples
using cindex_type = uint32_t; // for cells
static constexpr uint32_t maxNumberOfHits = 48 * 1024;

static constexpr uint32_t maxNumberOfHits = 48 * 1024;
static constexpr uint32_t maxCellNeighbors = 36;
static constexpr uint32_t maxCellTracks = 48;
static constexpr uint32_t maxHitsOnTrack = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::fillDescriptions(edm::Con

template <typename TrackerTraits>
void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::produce(edm::StreamID,
edm::Event& iEvent,
const edm::EventSetup& iSetup) const {
edm::Event& iEvent,
const edm::EventSetup& iSetup) const {
const auto& digis = iEvent.get(digiGetToken_);
const uint32_t nDigis = digis.size();
const auto& ttopo = iSetup.getData(topoToken_);
Expand Down
88 changes: 44 additions & 44 deletions RecoLocalTracker/SiPixelClusterizer/plugins/alpaka/CalibPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <type_traits>
#include <alpaka/alpaka.hpp>


#include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLTLayout.h"
#include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelGainCalibrationForHLTDevice.h"
#include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelGainCalibrationForHLTUtilities.h"
Expand All @@ -23,7 +22,8 @@
namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace calibPixel {
using namespace cms::alpakatools;
constexpr uint16_t InvId = std::numeric_limits<uint16_t>::max();; // must be > MaxNumModules
constexpr uint16_t InvId = std::numeric_limits<uint16_t>::max();
; // must be > MaxNumModules

// valid for run2
constexpr float VCaltoElectronGain = 47; // L2-4: 47 +- 4.7
Expand All @@ -39,52 +39,52 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

struct calibDigis {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(const TAcc& acc, bool isRun2,
ALPAKA_FN_ACC void operator()(const TAcc& acc,
bool isRun2,
SiPixelDigisLayoutSoAView& view,
SiPixelClustersLayoutSoAView& clus_view,
const SiPixelGainCalibrationForHLTSoAConstView& gains,
int numElements
) const {
const uint32_t threadIdxGlobal(alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u]);

// zero for next kernels...
if (threadIdxGlobal == 0) {
clus_view[0].clusModuleStart() = clus_view[0].moduleStart();
}

// cms::alpakatools::for_each_element_in_grid_strided(
// acc, phase1PixelTopology::numberOfModules, [&](uint32_t i) { clus_view[i].clusInModule() = 0; });

// cms::alpakatools::for_each_element_in_grid_strided(acc, numElements, [&](uint32_t i) {
// auto dvgi = view[i];
// if (dvgi.moduleId() != InvId) {
// float conversionFactor =
// (isRun2) ? (dvgi.moduleId() < 96 ? VCaltoElectronGain_L1 : VCaltoElectronGain) : 1.f;
// float offset = (isRun2) ? (dvgi.moduleId() < 96 ? VCaltoElectronOffset_L1 : VCaltoElectronOffset) : 0;

// bool isDeadColumn = false, isNoisyColumn = false;

// int row = dvgi.xx();
// int col = dvgi.yy();

// auto ret =
// SiPixelGainUtilities::getPedAndGain(gains, dvgi.moduleId(), col, row, isDeadColumn, isNoisyColumn);

// float pedestal = ret.first;
// float gain = ret.second;
// // float pedestal = 0; float gain = 1.;
// if (isDeadColumn | isNoisyColumn) {
// dvgi.moduleId() = InvId;
// dvgi.adc() = 0;
// printf("bad pixel at %d in %d\n", i, dvgi.moduleId());
// } else {
// float vcal = dvgi.adc() * gain - pedestal * gain;
// dvgi.adc() = std::max(100, int(vcal * conversionFactor + offset));
// }
// }
// });
int numElements) const {
const uint32_t threadIdxGlobal(alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u]);

// zero for next kernels...
if (threadIdxGlobal == 0) {
clus_view[0].clusModuleStart() = clus_view[0].moduleStart();
}
};

// cms::alpakatools::for_each_element_in_grid_strided(
// acc, phase1PixelTopology::numberOfModules, [&](uint32_t i) { clus_view[i].clusInModule() = 0; });

// cms::alpakatools::for_each_element_in_grid_strided(acc, numElements, [&](uint32_t i) {
// auto dvgi = view[i];
// if (dvgi.moduleId() != InvId) {
// float conversionFactor =
// (isRun2) ? (dvgi.moduleId() < 96 ? VCaltoElectronGain_L1 : VCaltoElectronGain) : 1.f;
// float offset = (isRun2) ? (dvgi.moduleId() < 96 ? VCaltoElectronOffset_L1 : VCaltoElectronOffset) : 0;

// bool isDeadColumn = false, isNoisyColumn = false;

// int row = dvgi.xx();
// int col = dvgi.yy();

// auto ret =
// SiPixelGainUtilities::getPedAndGain(gains, dvgi.moduleId(), col, row, isDeadColumn, isNoisyColumn);

// float pedestal = ret.first;
// float gain = ret.second;
// // float pedestal = 0; float gain = 1.;
// if (isDeadColumn | isNoisyColumn) {
// dvgi.moduleId() = InvId;
// dvgi.adc() = 0;
// printf("bad pixel at %d in %d\n", i, dvgi.moduleId());
// } else {
// float vcal = dvgi.adc() * gain - pedestal * gain;
// dvgi.adc() = std::max(100, int(vcal * conversionFactor + offset));
// }
// }
// });
}
};

// struct calibDigisPhase2 {
// template <typename TAcc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace pixelClustering {
const TAcc& acc,
SiPixelDigisLayoutSoAView digi_view,
SiPixelClustersLayoutSoAView clus_view,
SiPixelClusterThresholds clusterThresholds, // charge cut on cluster in electrons (for layer 1 and for other layers)
SiPixelClusterThresholds
clusterThresholds, // charge cut on cluster in electrons (for layer 1 and for other layers)
const uint32_t numElements) const {
constexpr int startBPIX2 = TrackerTraits::layerStart[1];
[[maybe_unused]] constexpr int nMaxModules = TrackerTraits::numberOfModules;
Expand All @@ -43,10 +44,10 @@ namespace pixelClustering {
const uint32_t threadIdxLocal(alpaka::getIdx<alpaka::Block, alpaka::Threads>(acc)[0u]);
if (threadIdxLocal == 0 && nclus > maxNumClustersPerModules)
printf("Warning too many clusters in module %d in block %d: %d > %d\n",
thisModuleId,
blockIdx,
nclus,
maxNumClustersPerModules);
thisModuleId,
blockIdx,
nclus,
maxNumClustersPerModules);

// Stride = block size.
const uint32_t blockDimension(alpaka::getWorkDiv<alpaka::Block, alpaka::Elems>(acc)[0u]);
Expand Down Expand Up @@ -150,4 +151,4 @@ namespace pixelClustering {

} // namespace pixelClustering

#endif //
#endif //
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

template <typename TrackerTraits>
struct countModules {
template <typename TAcc>
template <typename TAcc>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
SiPixelDigisLayoutSoAView digi_view,
SiPixelClustersLayoutSoAView clus_view,
Expand Down Expand Up @@ -114,11 +114,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
template <typename TrackerTraits>
struct findClus {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(
const TAcc& acc,
SiPixelDigisLayoutSoAView digi_view,
SiPixelClustersLayoutSoAView clus_view,
const unsigned int numElements) const {
ALPAKA_FN_ACC void operator()(const TAcc& acc,
SiPixelDigisLayoutSoAView digi_view,
SiPixelClustersLayoutSoAView clus_view,
const unsigned int numElements) const {
const uint32_t blockIdx(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc)[0u]);
if (blockIdx >= clus_view[0].moduleStart())
return;
Expand Down
Loading

0 comments on commit 99f9438

Please sign in to comment.