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

hgcal_conditions::HeterogeneousHEFConditionsESProduct const * getHeterogeneousConditionsESProductAsync (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 *)
 
double *& select_pointer_d_ (cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
 
std::vector< double > select_pointer_d_ (const HGCalParameters *, const unsigned int &) const
 
int32_t *& select_pointer_i_ (cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
 
std::vector< int32_t > select_pointer_i_ (const HGCalParameters *, 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)

Definition at line 3 of file HeterogeneousHGCalHEFConditions.cc.

References allocate_memory_params_(), calculate_memory_bytes_params_(), chunk_params_, sizes_params_, and transfer_data_to_heterogeneous_pointers_params_().

4  {
5  //HGCalParameters as defined in CMSSW
6  this->sizes_params_ = calculate_memory_bytes_params_(cpuHGCalParameters);
9 }
size_t allocate_memory_params_(const std::vector< size_t > &)
void transfer_data_to_heterogeneous_pointers_params_(const std::vector< size_t > &, const HGCalParameters *)
std::vector< size_t > calculate_memory_bytes_params_(const HGCalParameters *)

◆ ~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.

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

Referenced by HeterogeneousHGCalHEFConditionsWrapper().

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 }
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
cpar::HeterogeneousHGCalHEFParameters params_

◆ 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.

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().

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 }
const std::array< HeterogeneousHGCalHEFParametersType, 5 > typesHEF
Definition: HGCConditions.h:97
int32_t *& select_pointer_i_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
double *& select_pointer_d_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ getHeterogeneousConditionsESProductAsync()

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

Definition at line 150 of file HeterogeneousHGCalHEFConditions.cc.

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.

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 }
const std::array< HeterogeneousHGCalHEFParametersType, 5 > typesHEF
Definition: HGCConditions.h:97
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
int32_t *& select_pointer_i_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
double *& select_pointer_d_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const

◆ select_pointer_d_() [1/2]

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

Definition at line 93 of file HeterogeneousHGCalHEFConditions.cc.

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_().

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 }
Log< level::Error, false > LogError

◆ select_pointer_d_() [2/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.

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

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 }
std::vector< double > cellFineY_
Log< level::Error, false > LogError
std::vector< double > cellCoarseX_
std::vector< double > cellFineX_
std::vector< double > cellCoarseY_

◆ select_pointer_i_() [1/2]

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

Definition at line 127 of file HeterogeneousHGCalHEFConditions.cc.

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

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

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 }
Log< level::Error, false > LogError

◆ select_pointer_i_() [2/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.

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

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 }
Log< level::Error, false > LogError
std::vector< int > waferTypeL_

◆ 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.

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().

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 }
const std::array< HeterogeneousHGCalHEFParametersType, 5 > typesHEF
Definition: HGCConditions.h:97
int32_t *& select_pointer_i_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const
static unsigned int const shift
cpar::HeterogeneousHGCalHEFParameters params_
double *& select_pointer_d_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const

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