Skip to content

Commit

Permalink
Code formats
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoDee committed Nov 29, 2023
1 parent 4c921b3 commit bb4318e
Show file tree
Hide file tree
Showing 40 changed files with 404 additions and 422 deletions.
12 changes: 7 additions & 5 deletions CalibTracker/Records/interface/SiPixelMappingSoARecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#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 "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>> {};
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
Expand Up @@ -48,8 +48,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

std::unique_ptr<SiPixelGainCalibrationForHLTHost> SiPixelGainCalibrationForHLTSoAESProducer::produce(
const SiPixelGainCalibrationForHLTSoARcd& iRecord) {

auto const& gains= iRecord.get(gainsToken_);
auto const& gains = iRecord.get(gainsToken_);
auto const& geom = iRecord.get(geometryToken_);

auto product = std::make_unique<SiPixelGainCalibrationForHLTHost>(gains.data().size(), cms::alpakatools::host());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace ALPAKA_ACCELERATOR_NAMESPACE {

struct SiPixelMappingUtilities {
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC ALPAKA_FN_INLINE static bool hasQuality(
const SiPixelMappingSoAConstView& view) {
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC ALPAKA_FN_INLINE static bool hasQuality(const SiPixelMappingSoAConstView& view) {
return view.hasQuality();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
// simplified representation of the beamspot data, in device global memory
using BeamSpotDeviceProduct = PortableProduct<BeamSpotPOD>;

}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif // DataFormats_BeamSpot_interface_alpaka_BeamSpotDeviceProduct_h
6 changes: 2 additions & 4 deletions DataFormats/Portable/interface/PortableDeviceProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class PortableDeviceProduct {

PortableDeviceProduct(TDev const& device)
// allocate global device memory
: buffer_{cms::alpakatools::make_device_buffer<Product>(device)}
{
: buffer_{cms::alpakatools::make_device_buffer<Product>(device)} {
assert(reinterpret_cast<uintptr_t>(buffer_->data()) % alignof(Product) == 0);
}

template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
PortableDeviceProduct(TQueue const& queue)
// allocate global device memory with queue-ordered semantic
: buffer_{cms::alpakatools::make_device_buffer<Product>(queue)}
{
: buffer_{cms::alpakatools::make_device_buffer<Product>(queue)} {
assert(reinterpret_cast<uintptr_t>(buffer_->data()) % alignof(Product) == 0);
}

Expand Down
12 changes: 4 additions & 8 deletions DataFormats/Portable/interface/PortableHostProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ class PortableHostProduct {

PortableHostProduct(alpaka_common::DevHost const& host)
// allocate pageable host memory
: buffer_{cms::alpakatools::make_host_buffer<Product>()},
product_{buffer_->data()}
{
: buffer_{cms::alpakatools::make_host_buffer<Product>()}, product_{buffer_->data()} {
assert(reinterpret_cast<uintptr_t>(product_) % alignof(Product) == 0);
}

template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
PortableHostProduct(TQueue const& queue)
// allocate pinned host memory associated to the given work queue, accessible by the queue's device
: buffer_{cms::alpakatools::make_host_buffer<Product>(queue)},
product_{buffer_->data()}
{
: buffer_{cms::alpakatools::make_host_buffer<Product>(queue)}, product_{buffer_->data()} {
assert(reinterpret_cast<uintptr_t>(product_) % alignof(Product) == 0);
}

Expand Down Expand Up @@ -78,7 +74,7 @@ class PortableHostProduct {
}
std::cerr << "struct content at " << newObj->product_ << std::endl;
if (newObj->product_) {
std::cerr << "id: " << newObj->product_->id << std::endl;
std::cerr << "id: " << newObj->product_->id << std::endl;
}
newObj->~PortableHostProduct();
// use the global "host" object returned by cms::alpakatools::host()
Expand All @@ -91,7 +87,7 @@ class PortableHostProduct {
}
std::cerr << "struct content at " << newObj->product_ << std::endl;
if (newObj->product_) {
std::cerr << "id: " << newObj->product_->id << std::endl;
std::cerr << "id: " << newObj->product_->id << std::endl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/TrackSoA/interface/TrackDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace pixelTrack {
auto ret = static_cast<Quality>(qp);
if (ret == pixelTrack::Quality::notQuality)
throw std::invalid_argument(name + "is not a pixelTrack::Quality!");

return ret;
}

Expand Down
8 changes: 4 additions & 4 deletions DataFormats/TrackSoA/interface/TrackLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ using TrackSoAView = typename TrackSoA<TrackerTraits>::template TrackSoAHeteroge
template <typename TrackerTraits>
using TrackSoAConstView = typename TrackSoA<TrackerTraits>::template TrackSoAHeterogeneousLayout<>::ConstView;

// State at the Beam spot
// phi,tip,1/pt,cotan(theta),zip
// State at the Beam spot
// phi,tip,1/pt,cotan(theta),zip
// template <typename TrackerTraits>
// ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float charge(const TrackSoAConstView<TrackerTraits>& tracks, int32_t i) {
// float v = tracks[i].state()(2);
// return float((0.0f < v) - (v < 0.0f));
// }
// }

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ struct TrackingRecHitAlpakaSoA {
};

template <typename TrackerTraits>
using TrackingRecHitAlpakaLayout =
typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>;
using TrackingRecHitAlpakaLayout = typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>;
template <typename TrackerTraits>
using TrackingRecHitAlpakaSoAView =
typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>::View;
using TrackingRecHitAlpakaSoAView = typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>::View;
template <typename TrackerTraits>
using TrackingRecHitAlpakaSoAConstView =
typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>::ConstView;
using TrackingRecHitAlpakaSoAConstView = typename TrackingRecHitAlpakaSoA<TrackerTraits>::template Layout<>::ConstView;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace cms::alpakatools {
template <typename TrackerTraits>
struct CopyToHost<ALPAKA_ACCELERATOR_NAMESPACE::TrackingRecHitAlpakaCollection<TrackerTraits>> {
template <typename TQueue>
static auto copyAsync(TQueue& queue,
ALPAKA_ACCELERATOR_NAMESPACE::TrackingRecHitAlpakaCollection<TrackerTraits> const& deviceData) {
static auto copyAsync(
TQueue& queue, ALPAKA_ACCELERATOR_NAMESPACE::TrackingRecHitAlpakaCollection<TrackerTraits> const& deviceData) {
TrackingRecHitHost<TrackerTraits> hostData(deviceData.view().metadata().size(), queue);
alpaka::memcpy(queue, hostData.buffer(), deviceData.buffer());
return hostData;
Expand Down
4 changes: 2 additions & 2 deletions RecoLocalTracker/Records/interface/PixelCPEFastParamsRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "FWCore/Utilities/interface/mplVector.h"

class PixelCPEFastParamsRecord
: public edm::eventsetup::DependentRecordImplementation<PixelCPEFastParamsRecord,
edm::mpl::Vector<TrackerDigiGeometryRecord,
: public edm::eventsetup::DependentRecordImplementation<PixelCPEFastParamsRecord,
edm::mpl::Vector<TrackerDigiGeometryRecord,
IdealMagneticFieldRecord,
SiPixelLorentzAngleRcd,
SiPixelGenErrorDBObjectRcd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ void SiPixelDigisClustersFromSoAT<TrackerTraits>::produce(edm::StreamID,
spc.abort();
};

#ifdef GPU_DEBUG
std::cout << "Dumping all digis. nDigis = "<< nDigis << std::endl;
#endif
#ifdef GPU_DEBUG
std::cout << "Dumping all digis. nDigis = " << nDigis << std::endl;
#endif

for (uint32_t i = 0; i < nDigis; i++) {
// check for uninitialized digis
Expand All @@ -165,9 +165,9 @@ void SiPixelDigisClustersFromSoAT<TrackerTraits>::produce(edm::StreamID,
assert(digis.rawIdArr(i) > 109999);
#endif
if (detId != digis.rawIdArr(i)) {
#ifdef GPU_DEBUG
std::cout << ">> Closed module --"<< detId << "; nclus = " << nclus <<std::endl;
#endif
#ifdef GPU_DEBUG
std::cout << ">> Closed module --" << detId << "; nclus = " << nclus << std::endl;
#endif
// new module
fillClusters(detId);
#ifdef EDM_ML_DEBUG
Expand All @@ -186,15 +186,10 @@ void SiPixelDigisClustersFromSoAT<TrackerTraits>::produce(edm::StreamID,
}
PixelDigi dig(digis.pdigi(i));

#ifdef GPU_DEBUG
std::cout << i << ";"
<< digis.rawIdArr(i) << ";"
<< digis.clus(i) << ";"
<< digis.pdigi(i) << ";"
<< digis.adc(i) << ";"
<< dig.row() << ";"
<< dig.column() << std::endl;
#endif
#ifdef GPU_DEBUG
std::cout << i << ";" << digis.rawIdArr(i) << ";" << digis.clus(i) << ";" << digis.pdigi(i) << ";" << digis.adc(i)
<< ";" << dig.row() << ";" << dig.column() << std::endl;
#endif

if (storeDigis_)
(*detDigis).data.emplace_back(dig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,19 @@ void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::produce(edm::StreamID,
// this is set in RawToDigi_kernel in SiPixelRawToClusterGPUKernel.cu
if (digisView[i].rawIdArr() == 0)
continue;

// check for noisy/dead pixels (electrons set to 0)
if (digisView[i].adc() == 0)
continue;

detId = digisView[i].rawIdArr();
if (storeDigis_) {

detDigis = &outputDigis->find_or_insert(detId);

if ((*detDigis).empty())
(*detDigis).data.reserve(64); // avoid the first relocations
}

break;
}

Expand All @@ -127,17 +126,19 @@ void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::produce(edm::StreamID,
auto const& acluster = aclusters[ic];
// in any case we cannot go out of sync with gpu...
if (acluster.charge < clusterThreshold)
edm::LogWarning("SiPixelDigisClustersFromSoAAlpaka") << "cluster below charge Threshold "
<< "Layer/DetId/clusId " << layer << '/' << detId << '/' << ic
<< " size/charge " << acluster.isize << '/' << acluster.charge << "\n";
edm::LogWarning("SiPixelDigisClustersFromSoAAlpaka")
<< "cluster below charge Threshold "
<< "Layer/DetId/clusId " << layer << '/' << detId << '/' << ic << " size/charge " << acluster.isize << '/'
<< acluster.charge << "\n";
// sort by row (x)
spc.emplace_back(acluster.isize, acluster.adc, acluster.x, acluster.y, acluster.xmin, acluster.ymin, ic);
aclusters[ic].clear();
#ifdef EDM_ML_DEBUG
++totClustersFilled;
const auto& cluster{spc.back()};
// LogDebug("SiPixelDigisClustersFromSoAAlpaka")
std::cout << "putting in this cluster " << ic << " " << cluster.charge() << " " << cluster.pixelADC().size() << "\n";
std::cout << "putting in this cluster " << ic << " " << cluster.charge() << " " << cluster.pixelADC().size()
<< "\n";
#endif
std::push_heap(spc.begin(), spc.end(), [](SiPixelCluster const& cl1, SiPixelCluster const& cl2) {
return cl1.minPixelRow() < cl2.minPixelRow();
Expand All @@ -152,22 +153,15 @@ void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::produce(edm::StreamID,
spc.abort();
};


#ifdef GPU_DEBUG
std::cout << "Dumping all digis. nDigis = "<< nDigis << std::endl;
#endif
#ifdef GPU_DEBUG
std::cout << "Dumping all digis. nDigis = " << nDigis << std::endl;
#endif
for (uint32_t i = 0; i < nDigis; i++) {

#ifdef GPU_DEBUG
#ifdef GPU_DEBUG
PixelDigi dig2{digisView[i].pdigi()};
std::cout << i << ";"
<< digisView[i].rawIdArr() << ";"
<< digisView[i].clus() << ";"
<< digisView[i].pdigi() << ";"
<< digisView[i].adc() << ";"
<< dig2.row() << ";"
<< dig2.column() << std::endl;
#endif
std::cout << i << ";" << digisView[i].rawIdArr() << ";" << digisView[i].clus() << ";" << digisView[i].pdigi() << ";"
<< digisView[i].adc() << ";" << dig2.row() << ";" << dig2.column() << std::endl;
#endif

// check for uninitialized digis
if (digisView[i].rawIdArr() == 0)
Expand All @@ -183,9 +177,9 @@ void SiPixelDigisClustersFromSoAAlpaka<TrackerTraits>::produce(edm::StreamID,
assert(digisView[i].rawIdArr() > 109999);
#endif
if (detId != digisView[i].rawIdArr()) {
#ifdef GPU_DEBUG
std::cout << ">> Closed module --"<< detId << "; nclus = " << nclus <<std::endl;
#endif
#ifdef GPU_DEBUG
std::cout << ">> Closed module --" << detId << "; nclus = " << nclus << std::endl;
#endif
// new module
fillClusters(detId);
#ifdef EDM_ML_DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ namespace pixelgpudetails {
clusters_d.setNClusters(nModules_Clusters_h[1], nModules_Clusters_h[2]);

std::cout << "SiPixelClusterizerCUDA results:" << std::endl
<< " > no. of digis: " << nDigis << std::endl
<< " > no. of active modules: " << nModules_Clusters_h[0] << std::endl
<< " > no. of clusters: " << nModules_Clusters_h[1] << std::endl
<< " > bpix2 offset: " << nModules_Clusters_h[2] << std::endl;
<< " > no. of digis: " << nDigis << std::endl
<< " > no. of active modules: " << nModules_Clusters_h[0] << std::endl
<< " > no. of clusters: " << nModules_Clusters_h[1] << std::endl
<< " > bpix2 offset: " << nModules_Clusters_h[2] << std::endl;

// need to explicitly deallocate while the associated CUDA
// stream is still alive
//
Expand Down
30 changes: 18 additions & 12 deletions RecoLocalTracker/SiPixelClusterizer/plugins/alpaka/CalibPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace calibPixel {
cms::alpakatools::for_each_element_in_grid_strided(acc, numElements, [&](uint32_t i) {
auto dvgi = view[i];
if (dvgi.moduleId() != InvId) {

bool isDeadColumn = false, isNoisyColumn = false;
int row = dvgi.xx();
int col = dvgi.yy();
Expand All @@ -61,18 +60,26 @@ namespace calibPixel {
printf("bad pixel at %d in %d\n", i, dvgi.moduleId());
} else {
float vcal = dvgi.adc() * gain - pedestal * gain;

float conversionFactor = dvgi.moduleId() < 96 ? VCaltoElectronGain_L1 : VCaltoElectronGain;
float offset = dvgi.moduleId() < 96 ? VCaltoElectronOffset_L1 : VCaltoElectronOffset;
#ifdef GPU_DEBUG
#ifdef GPU_DEBUG
auto old_adc = dvgi.adc();
#endif
#endif
dvgi.adc() = std::max(100, int(vcal * conversionFactor + offset));
#ifdef GPU_DEBUG
#ifdef GPU_DEBUG
if (threadIdxGlobal == 0)
printf("module %d pixel %d -> old_adc = %d; vcal = %.2f; conversionFactor = %.2f; offset = %.2f; new_adc = %d \n",
dvgi.moduleId(), i, old_adc,vcal,conversionFactor,offset,dvgi.adc());
#endif
printf(
"module %d pixel %d -> old_adc = %d; vcal = %.2f; conversionFactor = %.2f; offset = %.2f; new_adc = "
"%d \n",
dvgi.moduleId(),
i,
old_adc,
vcal,
conversionFactor,
offset,
dvgi.adc());
#endif
}
}
});
Expand All @@ -84,18 +91,17 @@ namespace calibPixel {
SiPixelClusterThresholds clusterThresholds,
SiPixelDigisSoAv2View view,
SiPixelClustersSoAView clus_view,
int numElements
) const {
int numElements) const {
const float ElectronPerADCGain = clusterThresholds.electronPerADCGain;
const int8_t Phase2ReadoutMode = clusterThresholds.phase2ReadoutMode;
const uint16_t Phase2DigiBaseline = clusterThresholds.phase2DigiBaseline;
const uint8_t Phase2KinkADC = clusterThresholds.phase2KinkADC;

const uint32_t threadIdxGlobal(alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u]);
// zero for next kernels...
if (0 == threadIdxGlobal)
clus_view[0].clusModuleStart() = clus_view[0].moduleStart() = 0;

cms::alpakatools::for_each_element_in_grid_strided(
acc, phase2PixelTopology::numberOfModules, [&](uint32_t i) { clus_view[i].clusInModule() = 0; });
cms::alpakatools::for_each_element_in_grid_strided(acc, numElements, [&](uint32_t i) {
Expand Down
Loading

0 comments on commit bb4318e

Please sign in to comment.