Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Riley authored and Dan Riley committed Jul 21, 2021
1 parent 9ca69c8 commit 1290aff
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 209 deletions.
3 changes: 3 additions & 0 deletions CalibFormats/SiStripObjects/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<use name="DataFormats/SiStripCommon"/>
<use name="CondFormats/SiStripObjects"/>
<use name="DataFormats/TrackerCommon"/>
<use name="HeterogeneousCore/CUDACore"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="cuda"/>
<export>
<lib name="1"/>
</export>
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#ifndef CalibFormats_SiStripObjects_SiStripClusterizerConditionsGPU_h
#define CalibFormats_SiStripObjects_SiStripClusterizerConditionsGPU_h

#include "HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h"
#include "HeterogeneousCore/CUDACore/interface/ESProduct.h"
#include "CUDADataFormats/SiStripCluster/interface/GPUtypes.h"

class DetToFed {
public:
DetToFed(stripgpu::detId_t detid, stripgpu::APVPair_t ipair, stripgpu::fedId_t fedid, stripgpu::fedCh_t fedch)
: detid_(detid), ipair_(ipair), fedid_(fedid), fedch_(fedch) {}
stripgpu::detId_t detID() const { return detid_; }
stripgpu::APVPair_t pair() const { return ipair_; }
stripgpu::fedId_t fedID() const { return fedid_; }
stripgpu::fedCh_t fedCh() const { return fedch_; }

private:
stripgpu::detId_t detid_;
stripgpu::APVPair_t ipair_;
stripgpu::fedId_t fedid_;
stripgpu::fedCh_t fedch_;
};
using DetToFeds = std::vector<DetToFed>;

class SiStripQuality;
class SiStripGain;
class SiStripNoises;

namespace stripgpu {
static constexpr int kStripsPerChannel = 256;
static constexpr int kFedFirst = 50;
static constexpr int kFedLast = 489;
static constexpr int kFedCount = kFedLast - kFedFirst + 1;
static constexpr int kChannelCount = 96;
static constexpr int kApvCount = 2 * kChannelCount;
static constexpr int kStripsPerFed = kChannelCount * kStripsPerChannel;

__host__ __device__ inline fedId_t fedIndex(fedId_t fed) { return fed - kFedFirst; }
__host__ __device__ inline stripId_t stripIndex(fedCh_t channel, stripId_t strip) {
return channel * kStripsPerChannel + (strip % kStripsPerChannel);
}
__host__ __device__ inline stripId_t apvIndex(fedCh_t channel, stripId_t strip) {
return channel * kStripsPerChannel + (strip % kStripsPerChannel) / 128;
}
} // namespace stripgpu


class SiStripClusterizerConditionsGPU {
public:
struct Data {
static constexpr std::uint16_t badBit = 1 << 15;

__host__ __device__ void setStrip(stripgpu::fedId_t fed,
stripgpu::fedCh_t channel,
stripgpu::stripId_t strip,
std::uint16_t noise,
float gain,
bool bad) {
gain_[stripgpu::fedIndex(fed)][stripgpu::apvIndex(channel, strip)] = gain;
noise_[stripgpu::fedIndex(fed)][stripgpu::stripIndex(channel, strip)] = noise;
if (bad) {
noise_[stripgpu::fedIndex(fed)][stripgpu::stripIndex(channel, strip)] |= badBit;
}
}

__host__ __device__ void setInvThickness(stripgpu::fedId_t fed, stripgpu::fedCh_t channel, float invthick) {
invthick_[stripgpu::fedIndex(fed)][channel] = invthick;
}

__host__ __device__ stripgpu::detId_t detID(stripgpu::fedId_t fed, stripgpu::fedCh_t channel) const {
return detID_[stripgpu::fedIndex(fed)][channel];
}

__host__ __device__ stripgpu::APVPair_t iPair(stripgpu::fedId_t fed, stripgpu::fedCh_t channel) const {
return iPair_[stripgpu::fedIndex(fed)][channel];
}

__host__ __device__ float invthick(stripgpu::fedId_t fed, stripgpu::fedCh_t channel) const {
return invthick_[stripgpu::fedIndex(fed)][channel];
}

__host__ __device__ float noise(stripgpu::fedId_t fed, stripgpu::fedCh_t channel, stripgpu::stripId_t strip) const {
return 0.1 * (noise_[stripgpu::fedIndex(fed)][stripgpu::stripIndex(channel, strip)] & !badBit);
}

__host__ __device__ float gain(stripgpu::fedId_t fed, stripgpu::fedCh_t channel, stripgpu::stripId_t strip) const {
return gain_[stripgpu::fedIndex(fed)][stripgpu::apvIndex(channel, strip)];
}

__host__ __device__ bool bad(stripgpu::fedId_t fed, stripgpu::fedCh_t channel, stripgpu::stripId_t strip) const {
return badBit == (noise_[stripgpu::fedIndex(fed)][stripgpu::stripIndex(channel, strip)] & badBit);
}

alignas(128) float gain_[stripgpu::kFedCount][stripgpu::kApvCount];
alignas(128) float invthick_[stripgpu::kFedCount][stripgpu::kChannelCount];
alignas(128) std::uint16_t noise_[stripgpu::kFedCount][stripgpu::kStripsPerFed];
alignas(128) stripgpu::detId_t detID_[stripgpu::kFedCount][stripgpu::kChannelCount];
alignas(128) stripgpu::APVPair_t iPair_[stripgpu::kFedCount][stripgpu::kChannelCount];
};

SiStripClusterizerConditionsGPU(const SiStripQuality& quality, const SiStripGain* gains, const SiStripNoises& noises);
~SiStripClusterizerConditionsGPU();

// Function to return the actual payload on the memory of the current device
Data const* getGPUProductAsync(cudaStream_t stream) const;

const DetToFeds& detToFeds() const { return detToFeds_; }

private:
// Holds the data in pinned CPU memory
Data* conditions_ = nullptr;

// Helper struct to hold all information that has to be allocated and
// deallocated per device
struct GPUData {
// Destructor should free all member pointers
~GPUData();
Data* conditionsDevice = nullptr;
};

// Helper that takes care of complexity of transferring the data to
// multiple devices
cms::cuda::ESProduct<GPUData> gpuData_;
DetToFeds detToFeds_;
};

#endif
3 changes: 3 additions & 0 deletions CalibFormats/SiStripObjects/src/EventSetup_Registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ TYPELOOKUP_DATA_REG(SiStripQuality);

#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h"
TYPELOOKUP_DATA_REG(SiStripClusterizerConditions);

#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h"
TYPELOOKUP_DATA_REG(SiStripClusterizerConditionsGPU);
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"

#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
#include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
#include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
#include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h"

#include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h"

#include "SiStripConditionsGPUWrapper.h"

SiStripConditionsGPUWrapper::SiStripConditionsGPUWrapper(const SiStripQuality& quality,
SiStripClusterizerConditionsGPU::SiStripClusterizerConditionsGPU(const SiStripQuality& quality,
const SiStripGain* gains,
const SiStripNoises& noises) {
cudaCheck(cudaMallocHost(&conditions_, sizeof(SiStripConditionsGPU)));
cudaCheck(cudaMallocHost(&conditions_, sizeof(Data)));
detToFeds_.clear();

// connected: map<DetID, std::vector<int>>
Expand Down Expand Up @@ -63,21 +64,21 @@ SiStripConditionsGPUWrapper::SiStripConditionsGPUWrapper(const SiStripQuality& q
});
}

SiStripConditionsGPUWrapper::~SiStripConditionsGPUWrapper() {
SiStripClusterizerConditionsGPU::~SiStripClusterizerConditionsGPU() {
if (nullptr != conditions_) {
cudaCheck(cudaFreeHost(conditions_));
}
}

SiStripConditionsGPU const* SiStripConditionsGPUWrapper::getGPUProductAsync(cudaStream_t stream) const {
SiStripClusterizerConditionsGPU::Data const* SiStripClusterizerConditionsGPU::getGPUProductAsync(cudaStream_t stream) const {
auto const& data = gpuData_.dataForCurrentDeviceAsync(stream, [this](GPUData& data, cudaStream_t stream) {
// Allocate the payload object on the device memory.
cudaCheck(cudaMalloc(&data.conditionsDevice, sizeof(SiStripConditionsGPU)));
cudaCheck(cudaMalloc(&data.conditionsDevice, sizeof(Data)));
cudaCheck(
cudaMemcpyAsync(data.conditionsDevice, conditions_, sizeof(SiStripConditionsGPU), cudaMemcpyDefault, stream));
cudaMemcpyAsync(data.conditionsDevice, conditions_, sizeof(Data), cudaMemcpyDefault, stream));
});
// Returns the payload object on the memory of the current device
return data.conditionsDevice;
}

SiStripConditionsGPUWrapper::GPUData::~GPUData() { cudaCheck(cudaFree(conditionsDevice)); }
SiStripClusterizerConditionsGPU::GPUData::~GPUData() { cudaCheck(cudaFree(conditionsDevice)); }
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef RecoLocalTracker_Records_SiStripClusterizerGPUConditionsRcd_h
#define RecoLocalTracker_Records_SiStripClusterizerGPUConditionsRcd_h
#ifndef RecoLocalTracker_Records_SiStripClusterizerConditionsGPURcd_h
#define RecoLocalTracker_Records_SiStripClusterizerConditionsGPURcd_h
#include "FWCore/Framework/interface/DependentRecordImplementation.h"
#include "FWCore/Utilities/interface/mplVector.h"

#include "CalibTracker/Records/interface/SiStripDependentRecords.h"

class SiStripClusterizerGPUConditionsRcd : public edm::eventsetup::DependentRecordImplementation<
SiStripClusterizerGPUConditionsRcd,
class SiStripClusterizerConditionsGPURcd : public edm::eventsetup::DependentRecordImplementation<
SiStripClusterizerConditionsGPURcd,
edm::mpl::Vector<SiStripGainRcd, SiStripNoisesRcd, SiStripQualityRcd>> {
};

#endif // RecoLocalTracker_Records_SiStripClusterizerGPUConditionsRcd_h
#endif // RecoLocalTracker_Records_SiStripClusterizerConditionsGPURcd_h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "RecoLocalTracker/Records/interface/SiStripClusterizerConditionsGPURcd.h"

#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"
EVENTSETUP_RECORD_REG(SiStripClusterizerConditionsGPURcd);

This file was deleted.

1 change: 1 addition & 0 deletions RecoLocalTracker/SiStripClusterizer/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="RecoLocalTracker/SiStripClusterizer"/>
<use name="RecoLocalTracker/SiStripZeroSuppression"/>
<use name="HeterogeneousCore/CUDACore"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="CUDADataFormats/SiStripCluster"/>
<use name="cuda"/>
<flags EDM_PLUGIN="1"/>
Expand Down
1 change: 0 additions & 1 deletion RecoLocalTracker/SiStripClusterizer/plugins/ChanLocsGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
#include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"
#include "CUDADataFormats/SiStripCluster/interface/GPUtypes.h"
//#include "SiStripConditionsGPU.h"

class ChannelLocsGPU;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
/*
*/
#include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithmFactory.h"
#include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingFactory.h"
#include "RecoLocalTracker/Records/interface/SiStripClusterizerConditionsRcd.h"
#include "RecoLocalTracker/Records/interface/SiStripClusterizerConditionsGPURcd.h"

#include "RecoLocalTracker/SiStripClusterizer/plugins/SiStripRawToClusterGPUKernel.h"
#include "RecoLocalTracker/Records/interface/SiStripClusterizerGPUConditionsRcd.h"
#include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingAlgorithms.h"

#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"

#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"

#include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h"
#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h"

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -29,7 +24,6 @@
#include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"

#include "SiStripConditionsGPUWrapper.h"
#include "ChanLocsGPU.h"

//#include <sstream>
Expand Down Expand Up @@ -79,7 +73,7 @@ class SiStripClusterizerFromRawGPU final : public edm::stream::EDProducer<edm::E
inputToken_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("ProductLabel"));
outputToken_ = produces<cms::cuda::Product<SiStripClustersCUDA>>();

conditionsToken_ = esConsumes<SiStripConditionsGPUWrapper, SiStripClusterizerGPUConditionsRcd>(
conditionsToken_ = esConsumes<SiStripClusterizerConditionsGPU, SiStripClusterizerConditionsGPURcd>(
edm::ESInputTag{"", conf.getParameter<std::string>("ConditionsLabel")});
CPUconditionsToken_ = esConsumes<SiStripClusterizerConditions, SiStripClusterizerConditionsRcd>(
edm::ESInputTag{"", conf.getParameter<std::string>("ConditionsLabel")});
Expand Down Expand Up @@ -138,8 +132,8 @@ class SiStripClusterizerFromRawGPU final : public edm::stream::EDProducer<edm::E
edm::EDGetTokenT<FEDRawDataCollection> inputToken_;
edm::EDPutTokenT<cms::cuda::Product<SiStripClustersCUDA>> outputToken_;

edm::ESGetToken<SiStripConditionsGPUWrapper, SiStripClusterizerGPUConditionsRcd> conditionsToken_;
edm::ESGetToken<SiStripClusterizerConditions, SiStripClusterizerConditionsRcd> CPUconditionsToken_;
edm::ESGetToken<SiStripClusterizerConditionsGPU, SiStripClusterizerConditionsGPURcd> conditionsToken_;
};

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**\class SiStripClusterizerGPUConditionsESProducer
/**\class SiStripClusterizerConditionsGPUESProducer
*
* Create a GPU cache object for fast access to conditions needed by the SiStrip clusterizer
*
Expand All @@ -12,30 +12,29 @@
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "RecoLocalTracker/Records/interface/SiStripClusterizerGPUConditionsRcd.h"
#include "RecoLocalTracker/Records/interface/SiStripClusterizerConditionsGPURcd.h"

#include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
#include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
#include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h"

#include "SiStripConditionsGPUWrapper.h"

class SiStripClusterizerGPUConditionsESProducer : public edm::ESProducer {
class SiStripClusterizerConditionsGPUESProducer : public edm::ESProducer {
public:
SiStripClusterizerGPUConditionsESProducer(const edm::ParameterSet&);
~SiStripClusterizerGPUConditionsESProducer() override {}
SiStripClusterizerConditionsGPUESProducer(const edm::ParameterSet&);
~SiStripClusterizerConditionsGPUESProducer() override {}

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

using ReturnType = std::unique_ptr<SiStripConditionsGPUWrapper>;
ReturnType produce(const SiStripClusterizerGPUConditionsRcd&);
using ReturnType = std::unique_ptr<SiStripClusterizerConditionsGPU>;
ReturnType produce(const SiStripClusterizerConditionsGPURcd&);

private:
edm::ESGetToken<SiStripGain, SiStripGainRcd> m_gainToken;
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> m_noisesToken;
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> m_qualityToken;
};

SiStripClusterizerGPUConditionsESProducer::SiStripClusterizerGPUConditionsESProducer(const edm::ParameterSet& iConfig) {
SiStripClusterizerConditionsGPUESProducer::SiStripClusterizerConditionsGPUESProducer(const edm::ParameterSet& iConfig) {
auto cc = setWhatProduced(this, iConfig.getParameter<std::string>("Label"));

m_gainToken = cc.consumesFrom<SiStripGain, SiStripGainRcd>();
Expand All @@ -44,20 +43,20 @@ SiStripClusterizerGPUConditionsESProducer::SiStripClusterizerGPUConditionsESProd
edm::ESInputTag{"", iConfig.getParameter<std::string>("QualityLabel")});
}

void SiStripClusterizerGPUConditionsESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
void SiStripClusterizerConditionsGPUESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("QualityLabel", "");
desc.add<std::string>("Label", "");
descriptions.add("SiStripClusterizerGPUConditionsESProducer", desc);
descriptions.add("SiStripClusterizerConditionsGPUESProducer", desc);
}

SiStripClusterizerGPUConditionsESProducer::ReturnType SiStripClusterizerGPUConditionsESProducer::produce(
const SiStripClusterizerGPUConditionsRcd& iRecord) {
SiStripClusterizerConditionsGPUESProducer::ReturnType SiStripClusterizerConditionsGPUESProducer::produce(
const SiStripClusterizerConditionsGPURcd& iRecord) {
auto gainsH = iRecord.getTransientHandle(m_gainToken);
const auto& noises = iRecord.get(m_noisesToken);
const auto& quality = iRecord.get(m_qualityToken);

return std::make_unique<SiStripConditionsGPUWrapper>(quality, gainsH.product(), noises);
return std::make_unique<SiStripClusterizerConditionsGPU>(quality, gainsH.product(), noises);
}

DEFINE_FWK_EVENTSETUP_MODULE(SiStripClusterizerGPUConditionsESProducer);
DEFINE_FWK_EVENTSETUP_MODULE(SiStripClusterizerConditionsGPUESProducer);
Loading

0 comments on commit 1290aff

Please sign in to comment.