Skip to content

Commit

Permalink
move HeterogeneousHGCalRecHit code to official CMSSW folders
Browse files Browse the repository at this point in the history
move obtention of conditions data from `acquire` to `beginRun`
  • Loading branch information
bfontana authored and bfonta committed Sep 15, 2020
1 parent 60128cc commit 09f5af5
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 67 deletions.
14 changes: 10 additions & 4 deletions RecoLocalCalo/HGCalRecProducers/plugins/BuildFile.xml
@@ -1,12 +1,18 @@
<use name="cuda"/>
<use name="HeterogeneousCore/CUDACore"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="Geometry/CaloGeometry"/>
<use name="RecoLocalCalo/HGCalRecProducers"/>
<use name="RecoLocalCalo/HGCalRecAlgos"/>
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/HGCDigi"/>
<use name="DataFormats/HGCRecHit"/>
<use name="DataFormats/HcalDetId"/>
<use name="RecoLocalCalo/HGCalRecAlgos"/>
<use name="RecoLocalCalo/HGCalRecProducers"/>
<use name="FWCore/MessageLogger"/>
<use name="Geometry/HGCalGeometry"/>
<library file="*.cc" name="RecoLocalCaloHGCalRecProducersPlugins">
<flags EDM_PLUGIN="1"/>
<use name="Geometry/HGCalCommonData"/>
<library file="*.cc *.cu" name="RecoLocalCaloHGCalRecProducersPlugins">
<flags EDM_PLUGIN="1"/>
</library>
Expand Up @@ -108,7 +108,7 @@ void hef_to_rechit(HGCRecHitSoA dst_soa, HGCUncalibratedRecHitSoA src_soa, const
{
unsigned int tid = blockDim.x * blockIdx.x + threadIdx.x;
HeterogeneousHGCSiliconDetId detid(src_soa.id_[tid]);
//printf("waferTypeL: %d - cellCoarseY: %lf - cellX: %d\n", conds->params.waferTypeL_[0], conds->params.cellCoarseY_[12], detid.cellX());
printf("waferTypeL: %d - cellCoarseY: %lf - cellX: %d\n", conds->params.waferTypeL_[0], conds->params.cellCoarseY_[12], detid.cellX());

for (unsigned int i = tid; i < length; i += blockDim.x * gridDim.x)
{
Expand Down
@@ -1,11 +1,13 @@
#include "UserCode/CodeGPU/plugins/HeterogeneousHGCalEEConditions.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/HeterogeneousHGCalEEConditions.h"

HeterogeneousHGCalEEConditionsWrapper::HeterogeneousHGCalEEConditionsWrapper(const HGCalParameters* cpuHGCalParameters)
{
calculate_memory_bytes(cpuHGCalParameters);

chunk_ = std::accumulate(this->sizes_.begin(), this->sizes_.end(), 0); //total memory required in bytes
std::cout << "ee: check before" << std::endl;
gpuErrchk(cudaMallocHost(&this->params_.cellFineX_, chunk_));
std::cout << "ee: check after" << std::endl;

//store cumulative sum in bytes and convert it to sizes in units of C++ typesEE, i.e., number if items to be transferred to GPU
std::vector<size_t> cumsum_sizes( this->sizes_.size()+1, 0 ); //starting with zero
Expand Down Expand Up @@ -36,9 +38,7 @@ HeterogeneousHGCalEEConditionsWrapper::HeterogeneousHGCalEEConditionsWrapper(con
select_pointer_i(&this->params_, j) = reinterpret_cast<int32_t*>( select_pointer_d(&this->params_, jm1) + this->sizes_[jm1] );
}


//copying the pointers' content
/*
for(unsigned int i=cumsum_sizes[j]; i<cumsum_sizes[j+1]; ++i)
{
unsigned int index = i - cumsum_sizes[j];
Expand All @@ -50,7 +50,6 @@ HeterogeneousHGCalEEConditionsWrapper::HeterogeneousHGCalEEConditionsWrapper(con
else
edm::LogError("HeterogeneousHGCalEEConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
}
*/
}
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
#include "CUDADataFormats/HGCal/interface/HGCConditions.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "UserCode/CodeGPU/plugins/KernelManagerHGCalRecHit.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"

namespace cp = hgcal_conditions::parameters;

Expand Down
Expand Up @@ -22,6 +22,16 @@ HeterogeneousHGCalEERecHitProducer::HeterogeneousHGCalEERecHitProducer(const edm
produces<HGCeeRecHitCollection>(collection_name_);
}

void HeterogeneousHGCalEERecHitProducer::beginRun(edm::Run const & run, edm::EventSetup const& setup)
{
set_conditions_(setup);
HeterogeneousHGCalEEConditionsWrapper esproduct(params_);
/*
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;
}

void HeterogeneousHGCalEERecHitProducer::set_conditions_(const edm::EventSetup& setup)
{
tools_->getEventSetup(setup);
Expand Down Expand Up @@ -76,13 +86,6 @@ void HeterogeneousHGCalEERecHitProducer::acquire(edm::Event const& event, edm::E
stride_ = ( (nhits-1)/32 + 1 ) * 32; //align to warp boundary
allocate_memory_();

set_conditions_(setup);
HeterogeneousHGCalEEConditionsWrapper esproduct(params_);
/*
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;

kcdata_ = new KernelConstantData<HGCeeUncalibratedRecHitConstantData>(cdata_, vdata_);
convert_constant_data_(kcdata_);
convert_collection_data_to_soa_(hits_ee, uncalibSoA_, nhits);
Expand Down
Expand Up @@ -36,6 +36,7 @@ class HeterogeneousHGCalEERecHitProducer: public edm::stream::EDProducer<edm::Ex
explicit HeterogeneousHGCalEERecHitProducer(const edm::ParameterSet& ps);
~HeterogeneousHGCalEERecHitProducer() override;

virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
virtual void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
virtual void produce(edm::Event&, const edm::EventSetup&) override;

Expand Down
@@ -1,4 +1,4 @@
#include "UserCode/CodeGPU/plugins/HeterogeneousHGCalHEBConditions.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/HeterogeneousHGCalHEBConditions.h"

HeterogeneousHGCalHEBConditionsWrapper::HeterogeneousHGCalHEBConditionsWrapper(const HGCalParameters* cpuHGCalParameters)
{
Expand Down
Expand Up @@ -9,7 +9,7 @@
#include "CUDADataFormats/HGCal/interface/HGCConditions.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "UserCode/CodeGPU/plugins/KernelManagerHGCalRecHit.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"

namespace cp = hgcal_conditions::parameters;

Expand Down
Expand Up @@ -26,6 +26,16 @@ HeterogeneousHGCalHEBRecHitProducer::~HeterogeneousHGCalHEBRecHitProducer()
delete calibSoA_;
}

void HeterogeneousHGCalHEBRecHitProducer::beginRun(edm::Run const & run, edm::EventSetup const& setup)
{
set_conditions_(setup);
/*adapt HeterogeneousHGCalHEBConditionsWrapper
HeterogeneousHGCalHEBConditionsWrapper esproduct(params_);
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;
}

std::string HeterogeneousHGCalHEBRecHitProducer::assert_error_message_(std::string var, const size_t& s)
{
std::string str1 = "The '";
Expand All @@ -50,13 +60,6 @@ void HeterogeneousHGCalHEBRecHitProducer::acquire(edm::Event const& event, edm::
stride_ = ( (nhits-1)/32 + 1 ) * 32; //align to warp boundary
allocate_memory_();

set_conditions_(setup);
/*adapt HeterogeneousHGCalHEBConditionsWrapper
HeterogeneousHGCalHEBConditionsWrapper esproduct(params_);
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;

kcdata_ = new KernelConstantData<HGChebUncalibratedRecHitConstantData>(cdata_, vdata_);
convert_constant_data_(kcdata_);
convert_collection_data_to_soa_(hits_heb, uncalibSoA_, nhits);
Expand Down
Expand Up @@ -37,6 +37,7 @@ class HeterogeneousHGCalHEBRecHitProducer: public edm::stream::EDProducer<edm::E
explicit HeterogeneousHGCalHEBRecHitProducer(const edm::ParameterSet& ps);
~HeterogeneousHGCalHEBRecHitProducer() override;

virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
virtual void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
virtual void produce(edm::Event&, const edm::EventSetup&) override;

Expand Down
@@ -1,11 +1,13 @@
#include "UserCode/CodeGPU/plugins/HeterogeneousHGCalHEFConditions.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/HeterogeneousHGCalHEFConditions.h"

HeterogeneousHGCalHEFConditionsWrapper::HeterogeneousHGCalHEFConditionsWrapper(const HGCalParameters* cpuHGCalParameters)
{
calculate_memory_bytes(cpuHGCalParameters);

chunk_ = std::accumulate(this->sizes_.begin(), this->sizes_.end(), 0); //total memory required in bytes
std::cout << "hef: check before" << std::endl;
gpuErrchk(cudaMallocHost(&this->params_.cellFineX_, chunk_));
std::cout << "hef: check after" << std::endl;

//store cumulative sum in bytes and convert it to sizes in units of C++ typesHEF, i.e., number if items to be transferred to GPU
std::vector<size_t> cumsum_sizes( this->sizes_.size()+1, 0 ); //starting with zero
Expand Down Expand Up @@ -37,6 +39,7 @@ HeterogeneousHGCalHEFConditionsWrapper::HeterogeneousHGCalHEFConditionsWrapper(c
}

//copying the pointers' content
std::cout << "hef: check pointers before" << std::endl;
for(unsigned int i=cumsum_sizes[j]; i<cumsum_sizes[j+1]; ++i)
{
unsigned int index = i - cumsum_sizes[j];
Expand All @@ -45,13 +48,12 @@ HeterogeneousHGCalHEFConditionsWrapper::HeterogeneousHGCalHEFConditionsWrapper(c
}
else if( cp::typesHEF[j] == cp::HeterogeneousHGCalHEFParametersType::Int32_t )
{
std::cout << "index: " << index << std::endl;
std::cout << select_pointer_i(cpuHGCalParameters, j)[index] << std::endl;
select_pointer_i(&this->params_, j)[index] = select_pointer_i(cpuHGCalParameters, j)[index];
}
else
edm::LogError("HeterogeneousHGCalHEFConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
}
std::cout << "hef: check pointers after" << std::endl;
}
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
#include "CUDADataFormats/HGCal/interface/HGCConditions.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "UserCode/CodeGPU/plugins/KernelManagerHGCalRecHit.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"

namespace cp = hgcal_conditions::parameters;

Expand Down
Expand Up @@ -33,6 +33,16 @@ HeterogeneousHGCalHEFRecHitProducer::~HeterogeneousHGCalHEFRecHitProducer()
delete calibSoA_;
}

void HeterogeneousHGCalHEFRecHitProducer::beginRun(edm::Run const & run, edm::EventSetup const& setup)
{
set_conditions_(setup);
HeterogeneousHGCalHEFConditionsWrapper esproduct(params_);
/*
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;
}

std::string HeterogeneousHGCalHEFRecHitProducer::assert_error_message_(std::string var, const size_t& s)
{
std::string str1 = "The '";
Expand Down Expand Up @@ -65,14 +75,6 @@ void HeterogeneousHGCalHEFRecHitProducer::acquire(edm::Event const& event, edm::
stride_ = ( (nhits-1)/32 + 1 ) * 32; //align to warp boundary
allocate_memory_();

set_conditions_(setup);
HeterogeneousHGCalHEFConditionsWrapper esproduct(params_);
/*
d_conds = esproduct.getHeterogeneousConditionsESProductAsync(ctx.stream());
*/
d_conds = nullptr;


kcdata_ = new KernelConstantData<HGChefUncalibratedRecHitConstantData>(cdata_, vdata_);
convert_constant_data_(kcdata_);
convert_collection_data_to_soa_(hits_hef, uncalibSoA_, nhits);
Expand Down
Expand Up @@ -37,6 +37,7 @@ class HeterogeneousHGCalHEFRecHitProducer: public edm::stream::EDProducer<edm::E
explicit HeterogeneousHGCalHEFRecHitProducer(const edm::ParameterSet& ps);
~HeterogeneousHGCalHEFRecHitProducer() override;

virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
virtual void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
virtual void produce(edm::Event&, const edm::EventSetup&) override;

Expand Down
@@ -1,7 +1,7 @@
#include <cuda.h>
#include <cuda_runtime.h>
#include <inttypes.h>
#include "KernelManagerHGCalRecHit.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"
#include "HGCalRecHitKernelImpl.cuh"

KernelManagerHGCalRecHit::KernelManagerHGCalRecHit(KernelModifiableData<HGCUncalibratedRecHitSoA, HGCRecHitSoA> *data):
Expand Down
@@ -1,4 +1,4 @@
#include "UserCode/CodeGPU/plugins/TEST_HeterogeneousESProduct.h"
#include "RecoLocalCalo/HGCalRecProducers/plugins/TEST_HeterogeneousESProduct.h"

HeterogeneousGeometryESProductWrapper::HeterogeneousGeometryESProductWrapper(HeterogeneousGeometryESProduct const& cpuGeometry) {
cudaCheck(cudaMallocHost(&payload_array_, sizeof(float)*nelements_));
Expand Down
15 changes: 0 additions & 15 deletions UserCode/CodeGPU/plugins/BuildFile.xml

This file was deleted.

10 changes: 0 additions & 10 deletions UserCode/CodeGPU/plugins/Types.h

This file was deleted.

4 changes: 2 additions & 2 deletions UserCode/CodeGPU/python/HeterogeneousHGCalRecHit_cfg.py
Expand Up @@ -78,8 +78,8 @@
)

fNameOut = 'out'
process.task = cms.Task( process.HeterogeneousHGCalEERecHitProducer, process.HeterogeneousHGCalHEFRecHitProducer )
#process.task = cms.Task( process.HeterogeneousHGCalHEFRecHitProducer )
#process.task = cms.Task( process.HeterogeneousHGCalEERecHitProducer, process.HeterogeneousHGCalHEFRecHitProducer )
process.task = cms.Task( process.HeterogeneousHGCalHEFRecHitProducer )
process.path = cms.Path( process.task )

process.out = cms.OutputModule("PoolOutputModule",
Expand Down

0 comments on commit 09f5af5

Please sign in to comment.