CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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

Private Member Functions

void calculate_memory_bytes (const HGCalParameters *)
 
double *& select_pointer_d (cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
 
std::vector< double > select_pointer_d (const HGCalParameters *, const unsigned int &) const
 
int32_t *& select_pointer_i (cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
 
std::vector< int32_t > select_pointer_i (const HGCalParameters *, 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 ( const HGCalParameters cpuHGCalParameters)

Definition at line 3 of file HeterogeneousHGCalHEBConditions.cc.

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.

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 }
int32_t *& select_pointer_i(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
double *& select_pointer_d(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
const std::array< HeterogeneousHGCalHEBParametersType, 2 > typesHEB
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
HeterogeneousHGCalHEBConditionsWrapper::~HeterogeneousHGCalHEBConditionsWrapper ( )

Member Function Documentation

void HeterogeneousHGCalHEBConditionsWrapper::calculate_memory_bytes ( const HGCalParameters cpuHGCalParameters)
private

Definition at line 51 of file HeterogeneousHGCalHEBConditions.cc.

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

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 }
int32_t *& select_pointer_i(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
double *& select_pointer_d(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
const std::array< HeterogeneousHGCalHEBParametersType, 2 > typesHEB
unsigned transform(const HcalDetId &id, unsigned transformCode)
hgcal_conditions::HeterogeneousHEBConditionsESProduct const * HeterogeneousHGCalHEBConditionsWrapper::getHeterogeneousConditionsESProductAsync ( cudaStream_t  stream) const

Definition at line 125 of file HeterogeneousHGCalHEBConditions.cc.

References chunk_, cudaCheck, data, HeterogeneousHGCalHEBConditionsWrapper::GPUData::device, hgcal_conditions::parameters::Double, Exception, gpuData_, HeterogeneousHGCalHEBConditionsWrapper::GPUData::host, dqmiolumiharvest::j, hgcal_conditions::HeterogeneousHEBConditionsESProduct::params, select_pointer_d(), select_pointer_i(), sizes_, hgcal_conditions::parameters::HeterogeneousHGCalHEBParameters::testD_, and hgcal_conditions::parameters::typesHEB.

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.
134  cudaCheck(cudaMallocHost(&data.host, sizeof(hgcal_conditions::HeterogeneousHEBConditionsESProduct)));
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.
139  cudaCheck(cudaMalloc(&data.device, sizeof(hgcal_conditions::HeterogeneousHEBConditionsESProduct)));
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 }
int32_t *& select_pointer_i(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
double *& select_pointer_d(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const
const std::array< HeterogeneousHGCalHEBParametersType, 2 > typesHEB
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
double *& HeterogeneousHGCalHEBConditionsWrapper::select_pointer_d ( cp::HeterogeneousHGCalHEBParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 80 of file HeterogeneousHGCalHEBConditions.cc.

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

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

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 }
std::vector< double > HeterogeneousHGCalHEBConditionsWrapper::select_pointer_d ( const HGCalParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 91 of file HeterogeneousHGCalHEBConditions.cc.

References HGCalParameters::cellFineX_, and Exception.

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 }
std::vector< double > cellFineX_
int32_t *& HeterogeneousHGCalHEBConditionsWrapper::select_pointer_i ( cp::HeterogeneousHGCalHEBParameters cpuObject,
const unsigned int &  item 
) const
private

Definition at line 102 of file HeterogeneousHGCalHEBConditions.cc.

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

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

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

References Exception, and HGCalParameters::waferTypeL_.

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 }
std::vector< int > waferTypeL_

Member Data Documentation

size_t HeterogeneousHGCalHEBConditionsWrapper::chunk_
private
cms::cuda::ESProduct<GPUData> HeterogeneousHGCalHEBConditionsWrapper::gpuData_
private
cp::HeterogeneousHGCalHEBParameters HeterogeneousHGCalHEBConditionsWrapper::params_
private
std::vector<size_t> HeterogeneousHGCalHEBConditionsWrapper::sizes_
private