CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
HeterogeneousHGCalHEBConditionsWrapper Class Reference

#include <HeterogeneousHGCalHEBConditions.h>

Classes

struct  GPUData
 

Public Member Functions

const hgcal_conditions::HeterogeneousHEBConditionsESProductgetHeterogeneousConditionsESProductAsync (cudaStream_t stream) const
 
 HeterogeneousHGCalHEBConditionsWrapper (const HGCalParameters *)
 
 ~HeterogeneousHGCalHEBConditionsWrapper ()
 

Private Member Functions

void calculate_memory_bytes (const HGCalParameters *)
 
std::vector< double > select_pointer_d (const HGCalParameters *, const unsigned int &) const
 
double *& select_pointer_d (cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
 
std::vector< int32_t > select_pointer_i (const HGCalParameters *, const unsigned int &) const
 
int32_t *& select_pointer_i (cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
 

Private Attributes

size_t chunk_
 
cms::cuda::ESProduct< GPUDatagpuData_
 
cp::HeterogeneousHGCalHEBParameters params_
 
std::vector< size_t > sizes_
 

Detailed Description

Definition at line 19 of file HeterogeneousHGCalHEBConditions.h.

Constructor & Destructor Documentation

◆ HeterogeneousHGCalHEBConditionsWrapper()

HeterogeneousHGCalHEBConditionsWrapper::HeterogeneousHGCalHEBConditionsWrapper ( const HGCalParameters cpuHGCalParameters)

Definition at line 3 of file HeterogeneousHGCalHEBConditions.cc.

4  {
5  calculate_memory_bytes(cpuHGCalParameters);
6 
7  chunk_ = std::accumulate(this->sizes_.begin(), this->sizes_.end(), 0); //total memory required in bytes
8  cudaCheck(cudaMallocHost(&this->params_.testD_, chunk_));
9 
10  //store cumulative sum in bytes and convert it to sizes in units of C++ typesHEB, i.e., number if items to be transferred to GPU
11  std::vector<size_t> cumsum_sizes(this->sizes_.size() + 1, 0); //starting with zero
12  std::partial_sum(this->sizes_.begin(), this->sizes_.end(), cumsum_sizes.begin() + 1);
13  for (unsigned int i = 1; i < cumsum_sizes.size(); ++i) //start at second element (the first is zero)
14  {
15  unsigned int typesHEBize = 0;
17  typesHEBize = sizeof(double);
18  else if (cp::typesHEB[i - 1] == cp::HeterogeneousHGCalHEBParametersType::Int32_t)
19  typesHEBize = sizeof(int32_t);
20  else
21  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
22  cumsum_sizes[i] /= typesHEBize;
23  }
24 
25  for (unsigned int j = 0; j < this->sizes_.size(); ++j) {
26  //setting the pointers
27  if (j != 0) {
28  const unsigned int jm1 = j - 1;
31  select_pointer_d(&this->params_, j) = select_pointer_d(&this->params_, jm1) + this->sizes_[jm1];
33  cp::typesHEB[j] == cp::HeterogeneousHGCalHEBParametersType::Int32_t)
34  select_pointer_i(&this->params_, j) =
35  reinterpret_cast<int32_t*>(select_pointer_d(&this->params_, jm1) + this->sizes_[jm1]);
36  }
37 
38  //copying the pointers' content
39  for (unsigned int i = cumsum_sizes[j]; i < cumsum_sizes[j + 1]; ++i) {
40  unsigned int index = i - cumsum_sizes[j];
42  select_pointer_d(&this->params_, j)[index] = select_pointer_d(cpuHGCalParameters, j)[index];
43  } else if (cp::typesHEB[j] == cp::HeterogeneousHGCalHEBParametersType::Int32_t)
44  select_pointer_i(&this->params_, j)[index] = select_pointer_i(cpuHGCalParameters, j)[index];
45  else
46  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
47  }
48  }
49 }

References calculate_memory_bytes(), chunk_, cudaCheck, hgcal_conditions::parameters::Double, Exception, mps_fire::i, dqmiolumiharvest::j, params_, select_pointer_d(), select_pointer_i(), sizes_, hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testD_, and hgcal_conditions::parameters::typesHEB.

◆ ~HeterogeneousHGCalHEBConditionsWrapper()

HeterogeneousHGCalHEBConditionsWrapper::~HeterogeneousHGCalHEBConditionsWrapper ( )

Member Function Documentation

◆ calculate_memory_bytes()

void HeterogeneousHGCalHEBConditionsWrapper::calculate_memory_bytes ( const HGCalParameters cpuHGCalParameters)
private

Definition at line 51 of file HeterogeneousHGCalHEBConditions.cc.

51  {
52  size_t npointers = hgcal_conditions::parameters::typesHEB.size();
53  std::vector<size_t> sizes(npointers);
54  for (unsigned int i = 0; i < npointers; ++i) {
56  sizes[i] = select_pointer_d(cpuHGCalParameters, i).size();
57  else
58  sizes[i] = select_pointer_i(cpuHGCalParameters, i).size();
59  }
60 
61  std::vector<size_t> sizes_units(npointers);
62  for (unsigned int i = 0; i < npointers; ++i) {
64  sizes_units[i] = sizeof(double);
65  else if (cp::typesHEB[i] == cp::HeterogeneousHGCalHEBParametersType::Int32_t)
66  sizes_units[i] = sizeof(int32_t);
67  }
68 
69  //element by element multiplication
70  this->sizes_.resize(npointers);
71  std::transform(sizes.begin(), sizes.end(), sizes_units.begin(), this->sizes_.begin(), std::multiplies<size_t>());
72 }

References hgcal_conditions::parameters::Double, mps_fire::i, select_pointer_d(), select_pointer_i(), sizes_, HcalDetIdTransform::transform(), and hgcal_conditions::parameters::typesHEB.

Referenced by HeterogeneousHGCalHEBConditionsWrapper().

◆ getHeterogeneousConditionsESProductAsync()

hgcal_conditions::HeterogeneousHEBConditionsESProduct const * HeterogeneousHGCalHEBConditionsWrapper::getHeterogeneousConditionsESProductAsync ( cudaStream_t  stream) const

Definition at line 125 of file HeterogeneousHGCalHEBConditions.cc.

125  {
126  // cms::cuda::ESProduct<T> essentially holds an array of GPUData objects,
127  // one per device. If the data have already been transferred to the
128  // current device (or the transfer has been queued), the helper just
129  // returns a reference to that GPUData object. Otherwise, i.e. data are
130  // not yet on the current device, the helper calls the lambda to do the
131  // necessary memory allocations and to queue the transfers.
132  auto const& data = gpuData_.dataForCurrentDeviceAsync(stream, [this](GPUData& data, cudaStream_t stream) {
133  // Allocate the payload object on pinned host memory.
135  // Allocate the payload array(s) on device memory.
136  cudaCheck(cudaMalloc(&(data.host->params.testD_), chunk_));
137 
138  // Allocate the payload object on the device memory.
140  // Transfer the payload, first the array(s) ...
141  cudaCheck(cudaMemcpyAsync(data.host->params.testD_, this->params_.testD_, chunk_, cudaMemcpyHostToDevice, stream));
142 
143  for (unsigned int j = 0; j < this->sizes_.size() - 1; ++j) {
146  select_pointer_d(&(data.host->params), j + 1) = select_pointer_d(&(data.host->params), j) + this->sizes_[j];
148  cp::typesHEB[j + 1] == cp::HeterogeneousHGCalHEBParametersType::Int32_t)
149  select_pointer_i(&(data.host->params), j + 1) =
150  reinterpret_cast<int32_t*>(select_pointer_d(&(data.host->params), j) + this->sizes_[j]);
151  else
152  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper")
153  << "compare this functions' logic with hgcal_conditions::parameters::typesHEB";
154  }
155 
156  // ... and then the payload object
157  cudaCheck(cudaMemcpyAsync(data.device,
158  data.host,
160  cudaMemcpyHostToDevice,
161  stream));
162  }); //gpuData_.dataForCurrentDeviceAsync
163 
164  // Returns the payload object on the memory of the current device
165  return data.device;
166 }

References chunk_, cudaCheck, data, hgcal_conditions::parameters::Double, Exception, gpuData_, dqmiolumiharvest::j, select_pointer_d(), select_pointer_i(), sizes_, cms::cuda::stream, and hgcal_conditions::parameters::typesHEB.

◆ select_pointer_d() [1/2]

std::vector< double > HeterogeneousHGCalHEBConditionsWrapper::select_pointer_d ( const HGCalParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 91 of file HeterogeneousHGCalHEBConditions.cc.

92  {
93  switch (item) {
94  case 0:
95  return cpuObject->cellFineX_;
96  default:
97  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "select_pointer_d(non-heterogeneous): no item.";
98  return cpuObject->cellFineX_;
99  }
100 }

References HGCalParameters::cellFineX_, Exception, and B2GTnPMonitor_cfi::item.

◆ select_pointer_d() [2/2]

double *& HeterogeneousHGCalHEBConditionsWrapper::select_pointer_d ( cp::HeterogeneousHGCalHEBParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 80 of file HeterogeneousHGCalHEBConditions.cc.

81  {
82  switch (item) {
83  case 0:
84  return cpuObject->testD_;
85  default:
86  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "select_pointer_d(heterogeneous): no item.";
87  return cpuObject->testD_;
88  }
89 }

References Exception, B2GTnPMonitor_cfi::item, and hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testD_.

Referenced by calculate_memory_bytes(), getHeterogeneousConditionsESProductAsync(), and HeterogeneousHGCalHEBConditionsWrapper().

◆ select_pointer_i() [1/2]

std::vector< int32_t > HeterogeneousHGCalHEBConditionsWrapper::select_pointer_i ( const HGCalParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 113 of file HeterogeneousHGCalHEBConditions.cc.

114  {
115  switch (item) {
116  case 4:
117  return cpuObject->waferTypeL_;
118  default:
119  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "select_pointer_i(non-heterogeneous): no item.";
120  return cpuObject->waferTypeL_;
121  }
122 }

References Exception, B2GTnPMonitor_cfi::item, and HGCalParameters::waferTypeL_.

◆ select_pointer_i() [2/2]

int32_t *& HeterogeneousHGCalHEBConditionsWrapper::select_pointer_i ( cp::HeterogeneousHGCalHEBParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 102 of file HeterogeneousHGCalHEBConditions.cc.

103  {
104  switch (item) {
105  case 1:
106  return cpuObject->testI_;
107  default:
108  throw cms::Exception("HeterogeneousHGCalHEBConditionsWrapper") << "select_pointer_i(heterogeneous): no item.";
109  return cpuObject->testI_;
110  }
111 }

References Exception, B2GTnPMonitor_cfi::item, and hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testI_.

Referenced by calculate_memory_bytes(), getHeterogeneousConditionsESProductAsync(), and HeterogeneousHGCalHEBConditionsWrapper().

Member Data Documentation

◆ chunk_

size_t HeterogeneousHGCalHEBConditionsWrapper::chunk_
private

◆ gpuData_

cms::cuda::ESProduct<GPUData> HeterogeneousHGCalHEBConditionsWrapper::gpuData_
private

◆ params_

cp::HeterogeneousHGCalHEBParameters HeterogeneousHGCalHEBConditionsWrapper::params_
private

◆ sizes_

std::vector<size_t> HeterogeneousHGCalHEBConditionsWrapper::sizes_
private
HeterogeneousHGCalHEBConditionsWrapper::sizes_
std::vector< size_t > sizes_
Definition: HeterogeneousHGCalHEBConditions.h:37
HeterogeneousHGCalHEBConditionsWrapper::select_pointer_i
int32_t *& select_pointer_i(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
Definition: HeterogeneousHGCalHEBConditions.cc:102
mps_fire.i
i
Definition: mps_fire.py:428
hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testI_
std::int32_t * testI_
Definition: HGCConditions.h:130
hgcal_conditions::parameters::HeterogeneousHGCalHEBParametersType::Double
HeterogeneousHGCalHEBConditionsWrapper::gpuData_
cms::cuda::ESProduct< GPUData > gpuData_
Definition: HeterogeneousHGCalHEBConditions.h:59
HeterogeneousHGCalHEBConditionsWrapper::select_pointer_d
double *& select_pointer_d(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
Definition: HeterogeneousHGCalHEBConditions.cc:80
HeterogeneousHGCalHEBConditionsWrapper::calculate_memory_bytes
void calculate_memory_bytes(const HGCalParameters *)
Definition: HeterogeneousHGCalHEBConditions.cc:51
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition: HistoContainer.h:51
HeterogeneousHGCalHEBConditionsWrapper::params_
cp::HeterogeneousHGCalHEBParameters params_
Definition: HeterogeneousHGCalHEBConditions.h:35
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
hgcal_conditions::HeterogeneousHEBConditionsESProduct
Definition: HGCConditions.h:192
hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testD_
double * testD_
Definition: HGCConditions.h:129
hgcal_conditions::parameters::typesHEB
const std::array< HeterogeneousHGCalHEBParametersType, 2 > typesHEB
Definition: HGCConditions.h:104
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
HeterogeneousHGCalHEBConditionsWrapper::chunk_
size_t chunk_
Definition: HeterogeneousHGCalHEBConditions.h:38
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
Exception
Definition: hltDiff.cc:245
HGCalParameters::cellFineX_
std::vector< double > cellFineX_
Definition: HGCalParameters.h:120
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HGCalParameters::waferTypeL_
std::vector< int > waferTypeL_
Definition: HGCalParameters.h:116
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66