From 3618186bb1930168d24f8ec7f7cb09a6983c3cc6 Mon Sep 17 00:00:00 2001 From: Dan Riley Date: Mon, 11 Oct 2021 11:17:35 -0400 Subject: [PATCH] Reorganize SiStripClusterizerConditionsGPU to avoid alignment issues Make maximum strips per cluster cut configurable at runtime for both the GPU and CPU producers Remove GPU option to keep large clusters truncated around the barycenter, as it complicates the code for little apparent benefit. Fix bugs in the application of the cluster threshold and the early cutoff of clusters larger than the limit Squash out all add/delete commits of the same file --- .../interface/SiStripClustersCUDA.h | 16 +- .../SiStripCluster/src/SiStripClustersCUDA.cc | 18 +- .../SiStripClusterizerConditionsGPU.h | 195 ++++++++++-------- .../src/EventSetup_Registration.cc | 2 +- .../src/SiStripClusterizerConditionsGPU.cc | 150 ++++++++------ .../interface/SiStripClustersSOA.h | 2 +- .../interface/SiStripClustersSOABase.h | 8 +- .../SiStripCluster/src/SiStripClustersSOA.cc | 5 +- .../interface/ThreeThresholdAlgorithm.h | 2 + .../plugins/ClustersFromRawProducer.cc | 1 - .../plugins/ClustersFromRawProducerGPU.cc | 4 +- ...StripClusterizerConditionsGPUESProducer.cc | 2 + .../plugins/SiStripClustersFromSOA.cc | 15 +- .../plugins/SiStripClustersSOAtoHost.cc | 3 +- .../plugins/SiStripRawToClusterGPUKernel.cc | 27 ++- .../plugins/SiStripRawToClusterGPUKernel.cu | 144 ++++--------- .../plugins/SiStripRawToClusterGPUKernel.h | 10 +- .../plugins/StripDataView.cuh | 1 - .../python/DefaultClusterizer_cff.py | 1 + .../python/SiStripClusterizerOnDemand_cfi.py | 2 + .../src/StripClusterizerAlgorithmFactory.cc | 1 + .../src/ThreeThresholdAlgorithm.cc | 4 +- 22 files changed, 296 insertions(+), 317 deletions(-) diff --git a/CUDADataFormats/SiStripCluster/interface/SiStripClustersCUDA.h b/CUDADataFormats/SiStripCluster/interface/SiStripClustersCUDA.h index dc426a2d1e44b..19645b679f774 100644 --- a/CUDADataFormats/SiStripCluster/interface/SiStripClustersCUDA.h +++ b/CUDADataFormats/SiStripCluster/interface/SiStripClustersCUDA.h @@ -16,7 +16,7 @@ namespace cms { class SiStripClustersCUDADevice : public SiStripClustersSOABase { public: SiStripClustersCUDADevice() = default; - explicit SiStripClustersCUDADevice(size_t maxClusters, int clustersPerStrip, cudaStream_t stream); + explicit SiStripClustersCUDADevice(uint32_t maxClusters, uint32_t maxStripsPerCluster, cudaStream_t stream); ~SiStripClustersCUDADevice() override = default; SiStripClustersCUDADevice(const SiStripClustersCUDADevice &) = delete; @@ -34,23 +34,25 @@ class SiStripClustersCUDADevice : public SiStripClustersSOABase view_d; // "me" pointer - int nClusters_h; + uint32_t nClustersHost_; + uint32_t maxClusterSizeHost_; }; class SiStripClustersCUDAHost : public SiStripClustersSOABase { public: SiStripClustersCUDAHost() = default; - explicit SiStripClustersCUDAHost(const SiStripClustersCUDADevice &clusters_d, - int clustersPerStrip, - cudaStream_t stream); + explicit SiStripClustersCUDAHost(const SiStripClustersCUDADevice &clusters_d, cudaStream_t stream); ~SiStripClustersCUDAHost() override = default; SiStripClustersCUDAHost(const SiStripClustersCUDAHost &) = delete; diff --git a/CUDADataFormats/SiStripCluster/src/SiStripClustersCUDA.cc b/CUDADataFormats/SiStripCluster/src/SiStripClustersCUDA.cc index ff64229608038..c7a720eeaada4 100644 --- a/CUDADataFormats/SiStripCluster/src/SiStripClustersCUDA.cc +++ b/CUDADataFormats/SiStripCluster/src/SiStripClustersCUDA.cc @@ -1,10 +1,14 @@ #include "CUDADataFormats/SiStripCluster/interface/SiStripClustersCUDA.h" #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h" -SiStripClustersCUDADevice::SiStripClustersCUDADevice(size_t maxClusters, int clustersPerStrip, cudaStream_t stream) { +SiStripClustersCUDADevice::SiStripClustersCUDADevice(uint32_t maxClusters, + uint32_t maxStripsPerCluster, + cudaStream_t stream) { + maxClusterSizeHost_ = maxStripsPerCluster; + clusterIndex_ = cms::cuda::make_device_unique(maxClusters, stream); clusterSize_ = cms::cuda::make_device_unique(maxClusters, stream); - clusterADCs_ = cms::cuda::make_device_unique(maxClusters * clustersPerStrip, stream); + clusterADCs_ = cms::cuda::make_device_unique(maxClusters * maxStripsPerCluster, stream); clusterDetId_ = cms::cuda::make_device_unique(maxClusters, stream); firstStrip_ = cms::cuda::make_device_unique(maxClusters, stream); trueCluster_ = cms::cuda::make_device_unique(maxClusters, stream); @@ -20,18 +24,18 @@ SiStripClustersCUDADevice::SiStripClustersCUDADevice(size_t maxClusters, int clu view->trueCluster_ = trueCluster_.get(); view->barycenter_ = barycenter_.get(); view->charge_ = charge_.get(); + view->maxClusterSize_ = maxStripsPerCluster; view_d = cms::cuda::make_device_unique(stream); cms::cuda::copyAsync(view_d, view, stream); } -SiStripClustersCUDAHost::SiStripClustersCUDAHost(const SiStripClustersCUDADevice& clusters_d, - int clustersPerStrip, - cudaStream_t stream) { +SiStripClustersCUDAHost::SiStripClustersCUDAHost(const SiStripClustersCUDADevice& clusters_d, cudaStream_t stream) { nClusters_ = clusters_d.nClustersHost(); + maxClusterSize_ = clusters_d.maxClusterSizeHost(); clusterIndex_ = cms::cuda::make_host_unique(nClusters_, stream); clusterSize_ = cms::cuda::make_host_unique(nClusters_, stream); - clusterADCs_ = cms::cuda::make_host_unique(nClusters_ * clustersPerStrip, stream); + clusterADCs_ = cms::cuda::make_host_unique(nClusters_ * maxClusterSize_, stream); clusterDetId_ = cms::cuda::make_host_unique(nClusters_, stream); firstStrip_ = cms::cuda::make_host_unique(nClusters_, stream); trueCluster_ = cms::cuda::make_host_unique(nClusters_, stream); @@ -40,7 +44,7 @@ SiStripClustersCUDAHost::SiStripClustersCUDAHost(const SiStripClustersCUDADevice cms::cuda::copyAsync(clusterIndex_, clusters_d.clusterIndex(), nClusters_, stream); cms::cuda::copyAsync(clusterSize_, clusters_d.clusterSize(), nClusters_, stream); - cms::cuda::copyAsync(clusterADCs_, clusters_d.clusterADCs(), nClusters_ * clustersPerStrip, stream); + cms::cuda::copyAsync(clusterADCs_, clusters_d.clusterADCs(), nClusters_ * maxClusterSize_, stream); cms::cuda::copyAsync(clusterDetId_, clusters_d.clusterDetId(), nClusters_, stream); cms::cuda::copyAsync(firstStrip_, clusters_d.firstStrip(), nClusters_, stream); cms::cuda::copyAsync(trueCluster_, clusters_d.trueCluster(), nClusters_, stream); diff --git a/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h b/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h index 0b6bed13fe35a..6505dd054c262 100644 --- a/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h +++ b/CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h @@ -1,10 +1,14 @@ #ifndef CalibFormats_SiStripObjects_SiStripClusterizerConditionsGPU_h #define CalibFormats_SiStripObjects_SiStripClusterizerConditionsGPU_h -#include "HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h" -#include "HeterogeneousCore/CUDACore/interface/ESProduct.h" #include "DataFormats/SiStripCluster/interface/SiStripTypes.h" +#include "HeterogeneousCore/CUDACore/interface/ESProduct.h" +#include "HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h" +#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h" +#include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h" +#include "HeterogeneousCore/CUDAUtilities/interface/HostAllocator.h" + class SiStripQuality; class SiStripGain; class SiStripNoises; @@ -19,108 +23,117 @@ namespace stripgpu { 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 std::uint32_t stripIndex(fedId_t fed, fedCh_t channel, stripId_t strip) { + return fedIndex(fed) * kStripsPerFed + channel * kStripsPerChannel + (strip % kStripsPerChannel); } - __host__ __device__ inline stripId_t apvIndex(fedCh_t channel, stripId_t strip) { - return channel * kStripsPerChannel + (strip % kStripsPerChannel) / 128; + __host__ __device__ inline std::uint32_t apvIndex(fedId_t fed, fedCh_t channel, stripId_t strip) { + return fedIndex(fed) * kApvCount + 2 * channel + (strip % kStripsPerChannel) / 128; + } + __host__ __device__ inline std::uint32_t channelIndex(fedId_t fed, fedCh_t channel) { + return fedIndex(fed) * kChannelCount + channel; } -} // namespace stripgpu -class SiStripClusterizerConditionsGPU { -public: - class DetToFed { + class SiStripClusterizerConditionsGPU { 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; + class DetToFed { + public: + DetToFed(detId_t detid, APVPair_t ipair, fedId_t fedid, fedCh_t fedch) + : detid_(detid), ipair_(ipair), fedid_(fedid), fedch_(fedch) {} + detId_t detID() const { return detid_; } + APVPair_t pair() const { return ipair_; } + fedId_t fedID() const { return fedid_; } + fedCh_t fedCh() const { return fedch_; } + + private: + detId_t detid_; + APVPair_t ipair_; + fedId_t fedid_; + fedCh_t fedch_; + }; + using DetToFeds = std::vector; - 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; + class Data { + public: + struct DeviceView { + __device__ inline detId_t detID(fedId_t fed, fedCh_t channel) const { + return detID_[channelIndex(fed, channel)]; + } + + __device__ inline APVPair_t iPair(fedId_t fed, fedCh_t channel) const { + return iPair_[channelIndex(fed, channel)]; + } + + __device__ inline float invthick(fedId_t fed, fedCh_t channel) const { + return invthick_[channelIndex(fed, channel)]; + } + + __device__ inline float noise(fedId_t fed, fedCh_t channel, stripId_t strip) const { + return 0.1f * (noise_[stripIndex(fed, channel, strip)] & ~badBit); + } + + __device__ inline float gain(fedId_t fed, fedCh_t channel, stripId_t strip) const { + return gain_[apvIndex(fed, channel, strip)]; + } + + __device__ inline bool bad(fedId_t fed, fedCh_t channel, stripId_t strip) const { + return badBit == (noise_[stripIndex(fed, channel, strip)] & badBit); + } + const std::uint16_t* noise_; //[kFedCount*kStripsPerFed]; + const float* invthick_; //[kFedCount*kChannelCount]; + const detId_t* detID_; //[kFedCount*kChannelCount]; + const APVPair_t* iPair_; //[kFedCount*kChannelCount]; + const float* gain_; //[kFedCount*kApvCount]; + }; + + const DeviceView* deviceView() const { return deviceView_.get(); } + + cms::cuda::device::unique_ptr deviceView_; + cms::cuda::host::unique_ptr hostView_; + + cms::cuda::device::unique_ptr noise_; //[kFedCount*kStripsPerFed]; + cms::cuda::device::unique_ptr invthick_; //[kFedCount*kChannelCount]; + cms::cuda::device::unique_ptr detID_; //[kFedCount*kChannelCount]; + cms::cuda::device::unique_ptr iPair_; //[kFedCount*kChannelCount]; + cms::cuda::device::unique_ptr gain_; //[kFedCount*kApvCount]; + }; + + SiStripClusterizerConditionsGPU(const SiStripQuality& quality, + const SiStripGain* gains, + const SiStripNoises& noises); + ~SiStripClusterizerConditionsGPU() = default; + + // 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: + void setStrip(fedId_t fed, fedCh_t channel, stripId_t strip, std::uint16_t noise, float gain, bool bad) { + gain_[apvIndex(fed, channel, strip)] = gain; + noise_[stripIndex(fed, channel, strip)] = noise; if (bad) { - noise_[stripgpu::fedIndex(fed)][stripgpu::stripIndex(channel, strip)] |= badBit; + noise_[stripIndex(fed, 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]; + void setInvThickness(fedId_t fed, fedCh_t channel, float invthick) { + invthick_[channelIndex(fed, channel)] = invthick; } - __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]; + // Holds the data in pinned CPU memory + std::vector> noise_; + std::vector> invthick_; + std::vector> detID_; + std::vector> iPair_; + std::vector> gain_; + + // Helper that takes care of complexity of transferring the data to + // multiple devices + cms::cuda::ESProduct gpuData_; + DetToFeds detToFeds_; }; - - 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_; - DetToFeds detToFeds_; -}; +} // namespace stripgpu #endif diff --git a/CalibFormats/SiStripObjects/src/EventSetup_Registration.cc b/CalibFormats/SiStripObjects/src/EventSetup_Registration.cc index f16361785f310..05530484f14c4 100644 --- a/CalibFormats/SiStripObjects/src/EventSetup_Registration.cc +++ b/CalibFormats/SiStripObjects/src/EventSetup_Registration.cc @@ -25,4 +25,4 @@ TYPELOOKUP_DATA_REG(SiStripQuality); TYPELOOKUP_DATA_REG(SiStripClusterizerConditions); #include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditionsGPU.h" -TYPELOOKUP_DATA_REG(SiStripClusterizerConditionsGPU); +TYPELOOKUP_DATA_REG(stripgpu::SiStripClusterizerConditionsGPU); diff --git a/CalibFormats/SiStripObjects/src/SiStripClusterizerConditionsGPU.cc b/CalibFormats/SiStripObjects/src/SiStripClusterizerConditionsGPU.cc index 29c33a8ed911f..2ca12c5e38579 100644 --- a/CalibFormats/SiStripObjects/src/SiStripClusterizerConditionsGPU.cc +++ b/CalibFormats/SiStripObjects/src/SiStripClusterizerConditionsGPU.cc @@ -1,4 +1,5 @@ #include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h" +#include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h" #include "CondFormats/SiStripObjects/interface/SiStripNoises.h" #include "CalibFormats/SiStripObjects/interface/SiStripGain.h" @@ -8,77 +9,94 @@ #include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h" -SiStripClusterizerConditionsGPU::SiStripClusterizerConditionsGPU(const SiStripQuality& quality, - const SiStripGain* gains, - const SiStripNoises& noises) { - cudaCheck(cudaMallocHost(&conditions_, sizeof(Data))); - detToFeds_.clear(); - - // connected: map> - // map of KEY=detid DATA=vector of apvs, maximum 6 APVs per detector module : - const auto& connected = quality.cabling()->connected(); - // detCabling: map - // map of KEY=detid DATA=vector - const auto& detCabling = quality.cabling()->getDetCabling(); - - for (const auto& conn : connected) { - const auto det = conn.first; - if (!quality.IsModuleBad(det)) { - const auto detConn_it = detCabling.find(det); - - if (detCabling.end() != detConn_it) { - for (const auto& chan : (*detConn_it).second) { - if (chan && chan->fedId() && chan->isConnected()) { - const auto detID = chan->detId(); - const auto fedID = chan->fedId(); - const auto fedCh = chan->fedCh(); - const auto iPair = chan->apvPairNumber(); - - detToFeds_.emplace_back(detID, iPair, fedID, fedCh); - - conditions_->detID_[stripgpu::fedIndex(fedID)][fedCh] = detID; - conditions_->iPair_[stripgpu::fedIndex(fedID)][fedCh] = iPair; - conditions_->setInvThickness(fedID, fedCh, siStripClusterTools::sensorThicknessInverse(detID)); - - auto offset = 256 * iPair; - - for (auto strip = 0; strip < 256; ++strip) { - const auto gainRange = gains->getRange(det); - - const auto detstrip = strip + offset; - const std::uint16_t noise = SiStripNoises::getRawNoise(detstrip, noises.getRange(det)); - const auto gain = SiStripGain::getStripGain(detstrip, gainRange); - const auto bad = quality.IsStripBad(quality.getRange(det), detstrip); - - // gain is actually stored per-APV, not per-strip - conditions_->setStrip(fedID, fedCh, strip, noise, gain, bad); +namespace stripgpu { + SiStripClusterizerConditionsGPU::SiStripClusterizerConditionsGPU(const SiStripQuality& quality, + const SiStripGain* gains, + const SiStripNoises& noises) + + : noise_(kFedCount * kStripsPerFed), + invthick_(kFedCount * kChannelCount), + detID_(kFedCount * kChannelCount), + iPair_(kFedCount * kChannelCount), + gain_(kFedCount * kApvCount) { + detToFeds_.clear(); + + // connected: map> + // map of KEY=detid DATA=vector of apvs, maximum 6 APVs per detector module : + const auto& connected = quality.cabling()->connected(); + // detCabling: map + // map of KEY=detid DATA=vector + const auto& detCabling = quality.cabling()->getDetCabling(); + + for (const auto& conn : connected) { + const auto det = conn.first; + if (!quality.IsModuleBad(det)) { + const auto detConn_it = detCabling.find(det); + + if (detCabling.end() != detConn_it) { + for (const auto& chan : (*detConn_it).second) { + if (chan && chan->fedId() && chan->isConnected()) { + const auto detID = chan->detId(); + const auto fedID = chan->fedId(); + const auto fedCh = chan->fedCh(); + const auto iPair = chan->apvPairNumber(); + + detToFeds_.emplace_back(detID, iPair, fedID, fedCh); + + detID_[channelIndex(fedID, fedCh)] = detID; + iPair_[channelIndex(fedID, fedCh)] = iPair; + setInvThickness(fedID, fedCh, siStripClusterTools::sensorThicknessInverse(detID)); + + auto offset = 256 * iPair; + + for (auto strip = 0; strip < 256; ++strip) { + const auto gainRange = gains->getRange(det); + + const auto detstrip = strip + offset; + const std::uint16_t noise = SiStripNoises::getRawNoise(detstrip, noises.getRange(det)); + const auto gain = SiStripGain::getStripGain(detstrip, gainRange); + const auto bad = quality.IsStripBad(quality.getRange(det), detstrip); + + // gain is actually stored per-APV, not per-strip + setStrip(fedID, fedCh, detstrip, noise, gain, bad); + } } } } } } - } - std::sort(detToFeds_.begin(), detToFeds_.end(), [](const DetToFed& a, const DetToFed& b) { - return a.detID() < b.detID() || (a.detID() == b.detID() && a.pair() < b.pair()); - }); -} + std::sort(detToFeds_.begin(), detToFeds_.end(), [](const DetToFed& a, const DetToFed& b) { + return a.detID() < b.detID() || (a.detID() == b.detID() && a.pair() < b.pair()); + }); + } -SiStripClusterizerConditionsGPU::~SiStripClusterizerConditionsGPU() { - if (nullptr != conditions_) { - cudaCheck(cudaFreeHost(conditions_)); + SiStripClusterizerConditionsGPU::Data const& SiStripClusterizerConditionsGPU::getGPUProductAsync( + cudaStream_t stream) const { + auto const& data = gpuData_.dataForCurrentDeviceAsync(stream, [this](Data& data, cudaStream_t stream) { + data.noise_ = cms::cuda::make_device_unique(noise_.size(), stream); + data.invthick_ = cms::cuda::make_device_unique(invthick_.size(), stream); + data.detID_ = cms::cuda::make_device_unique(detID_.size(), stream); + data.iPair_ = cms::cuda::make_device_unique(iPair_.size(), stream); + data.gain_ = cms::cuda::make_device_unique(gain_.size(), stream); + + cms::cuda::copyAsync(data.noise_, noise_, stream); + cms::cuda::copyAsync(data.invthick_, invthick_, stream); + cms::cuda::copyAsync(data.detID_, detID_, stream); + cms::cuda::copyAsync(data.iPair_, iPair_, stream); + cms::cuda::copyAsync(data.gain_, gain_, stream); + + data.hostView_ = cms::cuda::make_host_unique(stream); + data.hostView_->noise_ = data.noise_.get(); + data.hostView_->invthick_ = data.invthick_.get(); + data.hostView_->detID_ = data.detID_.get(); + data.hostView_->iPair_ = data.iPair_.get(); + data.hostView_->gain_ = data.gain_.get(); + + data.deviceView_ = cms::cuda::make_device_unique(stream); + cms::cuda::copyAsync(data.deviceView_, data.hostView_, stream); + }); + + return data; } -} - -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(Data))); - cudaCheck(cudaMemcpyAsync(data.conditionsDevice, conditions_, sizeof(Data), cudaMemcpyDefault, stream)); - }); - // Returns the payload object on the memory of the current device - return data.conditionsDevice; -} - -SiStripClusterizerConditionsGPU::GPUData::~GPUData() { cudaCheck(cudaFree(conditionsDevice)); } +} // namespace stripgpu diff --git a/DataFormats/SiStripCluster/interface/SiStripClustersSOA.h b/DataFormats/SiStripCluster/interface/SiStripClustersSOA.h index b277d365da38c..1d43b5f67ef64 100644 --- a/DataFormats/SiStripCluster/interface/SiStripClustersSOA.h +++ b/DataFormats/SiStripCluster/interface/SiStripClustersSOA.h @@ -13,7 +13,7 @@ namespace detail { class SiStripClustersSOA : public SiStripClustersSOABase { public: SiStripClustersSOA() = default; - explicit SiStripClustersSOA(size_t maxClusters, int clustersPerStrip); + explicit SiStripClustersSOA(uint32_t maxClusters, uint32_t maxStripsPerCluster); ~SiStripClustersSOA() override = default; SiStripClustersSOA(const SiStripClustersSOA &) = delete; diff --git a/DataFormats/SiStripCluster/interface/SiStripClustersSOABase.h b/DataFormats/SiStripCluster/interface/SiStripClustersSOABase.h index dc97f262ad155..036ab7c3dd3e5 100644 --- a/DataFormats/SiStripCluster/interface/SiStripClustersSOABase.h +++ b/DataFormats/SiStripCluster/interface/SiStripClustersSOABase.h @@ -9,10 +9,10 @@ template