CMS 3D CMS Logo

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

#include <HeterogeneousHGCalHEFConditions.h>

Classes

struct  GPUData
 

Public Member Functions

const hgcal_conditions::HeterogeneousHEFConditionsESProductgetHeterogeneousConditionsESProductAsync (cudaStream_t stream) const
 
 HeterogeneousHGCalHEFConditionsWrapper (const HGCalParameters *)
 
 ~HeterogeneousHGCalHEFConditionsWrapper ()
 

Private Member Functions

size_t allocate_memory_params_ (const std::vector< size_t > &)
 
std::vector< size_t > calculate_memory_bytes_params_ (const HGCalParameters *)
 
std::vector< double > select_pointer_d_ (const HGCalParameters *, const unsigned int &) const
 
double *& select_pointer_d_ (cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
 
std::vector< int32_t > select_pointer_i_ (const HGCalParameters *, const unsigned int &) const
 
int32_t *& select_pointer_i_ (cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
 
void transfer_data_to_heterogeneous_pointers_params_ (const std::vector< size_t > &, const HGCalParameters *)
 

Private Attributes

size_t chunk_params_
 
cms::cuda::ESProduct< GPUDatagpuData_
 
cpar::HeterogeneousHGCalHEFParameters params_
 
std::vector< size_t > sizes_params_
 

Detailed Description

Definition at line 19 of file HeterogeneousHGCalHEFConditions.h.

Constructor & Destructor Documentation

◆ HeterogeneousHGCalHEFConditionsWrapper()

HeterogeneousHGCalHEFConditionsWrapper::HeterogeneousHGCalHEFConditionsWrapper ( const HGCalParameters cpuHGCalParameters)

◆ ~HeterogeneousHGCalHEFConditionsWrapper()

HeterogeneousHGCalHEFConditionsWrapper::~HeterogeneousHGCalHEFConditionsWrapper ( )

Member Function Documentation

◆ allocate_memory_params_()

size_t HeterogeneousHGCalHEFConditionsWrapper::allocate_memory_params_ ( const std::vector< size_t > &  sz)
private

Definition at line 11 of file HeterogeneousHGCalHEFConditions.cc.

11  {
12  size_t chunk_ = std::accumulate(sz.begin(), sz.end(), 0); //total memory required in bytes
13  cudaCheck(cudaMallocHost(&this->params_.cellFineX_, chunk_));
14  return chunk_;
15 }

References hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellFineX_, cudaCheck, and params_.

Referenced by HeterogeneousHGCalHEFConditionsWrapper().

◆ calculate_memory_bytes_params_()

std::vector< size_t > HeterogeneousHGCalHEFConditionsWrapper::calculate_memory_bytes_params_ ( const HGCalParameters cpuParams)
private

Definition at line 61 of file HeterogeneousHGCalHEFConditions.cc.

62  {
63  size_t npointers = hgcal_conditions::parameters::typesHEF.size();
64  std::vector<size_t> sizes(npointers);
65  for (unsigned int i = 0; i < npointers; ++i) {
67  sizes[i] = select_pointer_d_(cpuParams, i).size();
68  else
69  sizes[i] = select_pointer_i_(cpuParams, i).size();
70  }
71 
72  std::vector<size_t> sizes_units(npointers);
73  for (unsigned int i = 0; i < npointers; ++i) {
75  sizes_units[i] = sizeof(double);
76  else if (cpar::typesHEF[i] == cpar::HeterogeneousHGCalHEFParametersType::Int32_t)
77  sizes_units[i] = sizeof(int32_t);
78  }
79 
80  //element by element multiplication
81  this->sizes_params_.resize(npointers);
83  sizes.begin(), sizes.end(), sizes_units.begin(), this->sizes_params_.begin(), std::multiplies<size_t>());
84  return this->sizes_params_;
85 }

References hgcal_conditions::parameters::Double, mps_fire::i, select_pointer_d_(), select_pointer_i_(), sizes_params_, HcalDetIdTransform::transform(), and hgcal_conditions::parameters::typesHEF.

Referenced by HeterogeneousHGCalHEFConditionsWrapper().

◆ getHeterogeneousConditionsESProductAsync()

hgcal_conditions::HeterogeneousHEFConditionsESProduct const * HeterogeneousHGCalHEFConditionsWrapper::getHeterogeneousConditionsESProductAsync ( cudaStream_t  stream) const

Definition at line 150 of file HeterogeneousHGCalHEFConditions.cc.

150  {
151  // cms::cuda::ESProduct<T> essentially holds an array of GPUData objects,
152  // one per device. If the data have already been transferred to the
153  // current device (or the transfer has been queued), the helper just
154  // returns a reference to that GPUData object. Otherwise, i.e. data are
155  // not yet on the current device, the helper calls the lambda to do the
156  // necessary memory allocations and to queue the transfers.
157  auto const& data = gpuData_.dataForCurrentDeviceAsync(stream, [this](GPUData& data, cudaStream_t stream) {
158  // Allocate the payload object on pinned host memory.
160  // Allocate the payload array(s) on device memory.
161  cudaCheck(cudaMalloc(&(data.host->params.cellFineX_), chunk_params_));
162 
163  // Complete the host-side information on the payload
164 
165  //(set the pointers of the parameters)
166  size_t sdouble = sizeof(double);
167  for (unsigned int j = 0; j < this->sizes_params_.size() - 1; ++j) {
170  select_pointer_d_(&(data.host->params), j + 1) =
171  select_pointer_d_(&(data.host->params), j) + (this->sizes_params_[j] / sdouble);
173  cpar::typesHEF[j + 1] == cpar::HeterogeneousHGCalHEFParametersType::Int32_t)
174  select_pointer_i_(&(data.host->params), j + 1) =
175  reinterpret_cast<int32_t*>(select_pointer_d_(&(data.host->params), j) + (this->sizes_params_[j] / sdouble));
176  else
177  throw cms::Exception("HeterogeneousHGCalHEFConditionsWrapper")
178  << "compare this functions' logic with hgcal_conditions::parameters::typesHEF";
179  }
180 
181  // Allocate the payload object on the device memory.
183  // Transfer the payload, first the array(s) ...
184  cudaCheck(cudaMemcpyAsync(
185  data.host->params.cellFineX_, this->params_.cellFineX_, chunk_params_, cudaMemcpyHostToDevice, stream));
186 
187  // ... and then the payload object
188  cudaCheck(cudaMemcpyAsync(data.device,
189  data.host,
191  cudaMemcpyHostToDevice,
192  stream));
193  }); //gpuData_.dataForCurrentDeviceAsync
194 
195  // Returns the payload object on the memory of the current device
196  return data.device;
197 }

References chunk_params_, cudaCheck, data, hgcal_conditions::parameters::Double, Exception, gpuData_, dqmiolumiharvest::j, select_pointer_d_(), select_pointer_i_(), sizes_params_, cms::cuda::stream, and hgcal_conditions::parameters::typesHEF.

◆ select_pointer_d_() [1/2]

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

Definition at line 110 of file HeterogeneousHGCalHEFConditions.cc.

111  {
112  switch (item) {
113  case 0:
114  return cpuObject->cellFineX_;
115  case 1:
116  return cpuObject->cellFineY_;
117  case 2:
118  return cpuObject->cellCoarseX_;
119  case 3:
120  return cpuObject->cellCoarseY_;
121  default:
122  edm::LogError("HeterogeneousHGCalHEFConditionsWrapper") << "select_pointer_d(non-heterogeneous): no item.";
123  return cpuObject->cellCoarseY_;
124  }
125 }

References HGCalParameters::cellCoarseX_, HGCalParameters::cellCoarseY_, HGCalParameters::cellFineX_, HGCalParameters::cellFineY_, and B2GTnPMonitor_cfi::item.

◆ select_pointer_d_() [2/2]

double *& HeterogeneousHGCalHEFConditionsWrapper::select_pointer_d_ ( cpar::HeterogeneousHGCalHEFParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 93 of file HeterogeneousHGCalHEFConditions.cc.

94  {
95  switch (item) {
96  case 0:
97  return cpuObject->cellFineX_;
98  case 1:
99  return cpuObject->cellFineY_;
100  case 2:
101  return cpuObject->cellCoarseX_;
102  case 3:
103  return cpuObject->cellCoarseY_;
104  default:
105  edm::LogError("HeterogeneousHGCalHEFConditionsWrapper") << "select_pointer_d(heterogeneous): no item.";
106  return cpuObject->cellCoarseY_;
107  }
108 }

References hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellCoarseX_, hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellCoarseY_, hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellFineX_, hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellFineY_, and B2GTnPMonitor_cfi::item.

Referenced by calculate_memory_bytes_params_(), getHeterogeneousConditionsESProductAsync(), and transfer_data_to_heterogeneous_pointers_params_().

◆ select_pointer_i_() [1/2]

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

Definition at line 138 of file HeterogeneousHGCalHEFConditions.cc.

139  {
140  switch (item) {
141  case 4:
142  return cpuObject->waferTypeL_;
143  default:
144  edm::LogError("HeterogeneousHGCalHEFConditionsWrapper") << "select_pointer_i(non-heterogeneous): no item.";
145  return cpuObject->waferTypeL_;
146  }
147 }

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

◆ select_pointer_i_() [2/2]

int32_t *& HeterogeneousHGCalHEFConditionsWrapper::select_pointer_i_ ( cpar::HeterogeneousHGCalHEFParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 127 of file HeterogeneousHGCalHEFConditions.cc.

128  {
129  switch (item) {
130  case 4:
131  return cpuObject->waferTypeL_;
132  default:
133  edm::LogError("HeterogeneousHGCalHEFConditionsWrapper") << "select_pointer_i(heterogeneous): no item.";
134  return cpuObject->waferTypeL_;
135  }
136 }

References B2GTnPMonitor_cfi::item, and hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::waferTypeL_.

Referenced by calculate_memory_bytes_params_(), getHeterogeneousConditionsESProductAsync(), and transfer_data_to_heterogeneous_pointers_params_().

◆ transfer_data_to_heterogeneous_pointers_params_()

void HeterogeneousHGCalHEFConditionsWrapper::transfer_data_to_heterogeneous_pointers_params_ ( const std::vector< size_t > &  sz,
const HGCalParameters cpuParams 
)
private

Definition at line 17 of file HeterogeneousHGCalHEFConditions.cc.

18  {
19  //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
20  std::vector<size_t> cumsum_sizes(sz.size() + 1, 0); //starting with zero
21  std::partial_sum(sz.begin(), sz.end(), cumsum_sizes.begin() + 1);
22  for (unsigned int i = 1; i < cumsum_sizes.size(); ++i) //start at second element (the first is zero)
23  {
24  size_t typesHEFsize = 0;
26  typesHEFsize = sizeof(double);
27  else if (cpar::typesHEF[i - 1] == cpar::HeterogeneousHGCalHEFParametersType::Int32_t)
28  typesHEFsize = sizeof(int32_t);
29  else
30  throw cms::Exception("HeterogeneousHGCalHEFConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
31  cumsum_sizes[i] /= typesHEFsize;
32  }
33 
34  for (unsigned int j = 0; j < sz.size(); ++j) {
35  //setting the pointers
36  if (j != 0) {
37  const unsigned int jm1 = j - 1;
38  const size_t shift = cumsum_sizes[j] - cumsum_sizes[jm1];
41  select_pointer_d_(&this->params_, j) = select_pointer_d_(&this->params_, jm1) + shift;
43  cpar::typesHEF[j] == cpar::HeterogeneousHGCalHEFParametersType::Int32_t)
44  select_pointer_i_(&this->params_, j) =
45  reinterpret_cast<int32_t*>(select_pointer_d_(&this->params_, jm1) + shift);
46  }
47 
48  //copying the pointers' content
49  for (unsigned int i = cumsum_sizes[j]; i < cumsum_sizes[j + 1]; ++i) {
50  unsigned int index = i - cumsum_sizes[j];
52  select_pointer_d_(&this->params_, j)[index] = select_pointer_d_(cpuParams, j)[index];
53  } else if (cpar::typesHEF[j] == cpar::HeterogeneousHGCalHEFParametersType::Int32_t) {
54  select_pointer_i_(&this->params_, j)[index] = select_pointer_i_(cpuParams, j)[index];
55  } else
56  throw cms::Exception("HeterogeneousHGCalHEFConditionsWrapper") << "Wrong HeterogeneousHGCalParameters type";
57  }
58  }
59 }

References hgcal_conditions::parameters::Double, Exception, mps_fire::i, dqmiolumiharvest::j, params_, select_pointer_d_(), select_pointer_i_(), edm::shift, and hgcal_conditions::parameters::typesHEF.

Referenced by HeterogeneousHGCalHEFConditionsWrapper().

Member Data Documentation

◆ chunk_params_

size_t HeterogeneousHGCalHEFConditionsWrapper::chunk_params_
private

◆ gpuData_

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

◆ params_

cpar::HeterogeneousHGCalHEFParameters HeterogeneousHGCalHEFConditionsWrapper::params_
private

◆ sizes_params_

std::vector<size_t> HeterogeneousHGCalHEFConditionsWrapper::sizes_params_
private
HeterogeneousHGCalHEFConditionsWrapper::transfer_data_to_heterogeneous_pointers_params_
void transfer_data_to_heterogeneous_pointers_params_(const std::vector< size_t > &, const HGCalParameters *)
Definition: HeterogeneousHGCalHEFConditions.cc:17
HeterogeneousHGCalHEFConditionsWrapper::allocate_memory_params_
size_t allocate_memory_params_(const std::vector< size_t > &)
Definition: HeterogeneousHGCalHEFConditions.cc:11
mps_fire.i
i
Definition: mps_fire.py:428
hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::waferTypeL_
std::int32_t * waferTypeL_
Definition: HGCConditions.h:125
HeterogeneousHGCalHEFConditionsWrapper::sizes_params_
std::vector< size_t > sizes_params_
Definition: HeterogeneousHGCalHEFConditions.h:37
HGCalParameters::cellFineY_
std::vector< double > cellFineY_
Definition: HGCalParameters.h:121
HeterogeneousHGCalHEFConditionsWrapper::select_pointer_d_
double *& select_pointer_d_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
Definition: HeterogeneousHGCalHEFConditions.cc:93
HeterogeneousHGCalHEFConditionsWrapper::gpuData_
cms::cuda::ESProduct< GPUData > gpuData_
Definition: HeterogeneousHGCalHEFConditions.h:65
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
hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellCoarseX_
double * cellCoarseX_
Definition: HGCConditions.h:122
hgcal_conditions::parameters::HeterogeneousHGCalHEFParametersType::Double
hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellFineY_
double * cellFineY_
Definition: HGCConditions.h:121
HeterogeneousHGCalHEFConditionsWrapper::chunk_params_
size_t chunk_params_
Definition: HeterogeneousHGCalHEFConditions.h:38
hgcal_conditions::parameters::typesHEF
const std::array< HeterogeneousHGCalHEFParametersType, 5 > typesHEF
Definition: HGCConditions.h:97
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
HGCalParameters::cellCoarseY_
std::vector< double > cellCoarseY_
Definition: HGCalParameters.h:125
hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellCoarseY_
double * cellCoarseY_
Definition: HGCConditions.h:123
hgcal_conditions::parameters::HeterogeneousHGCalHEFParameters::cellFineX_
double * cellFineX_
Definition: HGCConditions.h:120
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
hgcal_conditions::HeterogeneousHEFConditionsESProduct
Definition: HGCConditions.h:187
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
HeterogeneousHGCalHEFConditionsWrapper::calculate_memory_bytes_params_
std::vector< size_t > calculate_memory_bytes_params_(const HGCalParameters *)
Definition: HeterogeneousHGCalHEFConditions.cc:61
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
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
HeterogeneousHGCalHEFConditionsWrapper::params_
cpar::HeterogeneousHGCalHEFParameters params_
Definition: HeterogeneousHGCalHEFConditions.h:35
HGCalParameters::cellCoarseX_
std::vector< double > cellCoarseX_
Definition: HGCalParameters.h:124
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HeterogeneousHGCalHEFConditionsWrapper::select_pointer_i_
int32_t *& select_pointer_i_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
Definition: HeterogeneousHGCalHEFConditions.cc:127