CMS 3D CMS Logo

SiPixelROCsStatusAndMappingWrapper.cc
Go to the documentation of this file.
1 // C++ includes
2 #include <algorithm>
3 #include <iomanip>
4 #include <iostream>
5 #include <vector>
6 
7 // CUDA includes
8 #include <cuda_runtime.h>
9 
10 // CMSSW includes
22 
24  TrackerGeometry const& trackerGeom,
25  SiPixelQuality const* badPixelInfo)
26  : cablingMap_(&cablingMap), modToUnpDefault(pixelgpudetails::MAX_SIZE), hasQuality_(badPixelInfo != nullptr) {
27  cudaCheck(cudaMallocHost(&cablingMapHost, sizeof(SiPixelROCsStatusAndMapping)));
28 
29  std::vector<unsigned int> const& fedIds = cablingMap.fedIds();
30  std::unique_ptr<SiPixelFedCablingTree> const& cabling = cablingMap.cablingTree();
31 
32  unsigned int startFed = *(fedIds.begin());
33  unsigned int endFed = *(fedIds.end() - 1);
34 
36  int index = 1;
37 
38  for (unsigned int fed = startFed; fed <= endFed; fed++) {
39  for (unsigned int link = 1; link <= pixelgpudetails::MAX_LINK; link++) {
40  for (unsigned int roc = 1; roc <= pixelgpudetails::MAX_ROC; roc++) {
41  path = {fed, link, roc};
42  const sipixelobjects::PixelROC* pixelRoc = cabling->findItem(path);
43  cablingMapHost->fed[index] = fed;
46  if (pixelRoc != nullptr) {
47  cablingMapHost->rawId[index] = pixelRoc->rawId();
48  cablingMapHost->rocInDet[index] = pixelRoc->idInDetUnit();
49  modToUnpDefault[index] = false;
50  if (badPixelInfo != nullptr)
51  cablingMapHost->badRocs[index] = badPixelInfo->IsRocBad(pixelRoc->rawId(), pixelRoc->idInDetUnit());
52  else
53  cablingMapHost->badRocs[index] = false;
54  } else { // store some dummy number
57  cablingMapHost->badRocs[index] = true;
58  modToUnpDefault[index] = true;
59  }
60  index++;
61  }
62  }
63  } // end of FED loop
64 
65  // Given FedId, Link and idinLnk; use the following formula
66  // to get the rawId and idinDU
67  // index = (FedID-1200) * MAX_LINK* MAX_ROC + (Link-1)* MAX_ROC + idinLnk;
68  // where, MAX_LINK = 48, MAX_ROC = 8 for Phase1 as mentioned Danek's email
69  // FedID varies between 1200 to 1338 (In total 108 FED's)
70  // Link varies between 1 to 48
71  // idinLnk varies between 1 to 8
72 
73  for (int i = 1; i < index; i++) {
76  } else {
77  /*
78  std::cout << cablingMapHost->rawId[i] << std::endl;
79  */
80  auto gdet = trackerGeom.idToDetUnit(cablingMapHost->rawId[i]);
81  if (!gdet) {
82  LogDebug("SiPixelROCsStatusAndMapping") << " Not found: " << cablingMapHost->rawId[i] << std::endl;
83  continue;
84  }
85  cablingMapHost->moduleId[i] = gdet->index();
86  }
87  LogDebug("SiPixelROCsStatusAndMapping")
88  << "----------------------------------------------------------------------------" << std::endl;
89  LogDebug("SiPixelROCsStatusAndMapping")
90  << i << std::setw(20) << cablingMapHost->fed[i] << std::setw(20) << cablingMapHost->link[i] << std::setw(20)
91  << cablingMapHost->roc[i] << std::endl;
92  LogDebug("SiPixelROCsStatusAndMapping")
93  << i << std::setw(20) << cablingMapHost->rawId[i] << std::setw(20) << cablingMapHost->rocInDet[i]
94  << std::setw(20) << cablingMapHost->moduleId[i] << std::endl;
95  LogDebug("SiPixelROCsStatusAndMapping")
96  << i << std::setw(20) << (bool)cablingMapHost->badRocs[i] << std::setw(20) << std::endl;
97  LogDebug("SiPixelROCsStatusAndMapping")
98  << "----------------------------------------------------------------------------" << std::endl;
99  }
100 
101  cablingMapHost->size = index - 1;
102 }
103 
105 
107  cudaStream_t cudaStream) const {
108  const auto& data = gpuData_.dataForCurrentDeviceAsync(cudaStream, [this](GPUData& data, cudaStream_t stream) {
109  // allocate
110  cudaCheck(cudaMalloc(&data.cablingMapDevice, sizeof(SiPixelROCsStatusAndMapping)));
111 
112  // transfer
113  cudaCheck(cudaMemcpyAsync(
114  data.cablingMapDevice, this->cablingMapHost, sizeof(SiPixelROCsStatusAndMapping), cudaMemcpyDefault, stream));
115  });
116  return data.cablingMapDevice;
117 }
118 
119 const unsigned char* SiPixelROCsStatusAndMappingWrapper::getModToUnpAllAsync(cudaStream_t cudaStream) const {
120  const auto& data =
121  modToUnp_.dataForCurrentDeviceAsync(cudaStream, [this](ModulesToUnpack& data, cudaStream_t stream) {
122  cudaCheck(cudaMalloc((void**)&data.modToUnpDefault, pixelgpudetails::MAX_SIZE_BYTE_BOOL));
123  cudaCheck(cudaMemcpyAsync(data.modToUnpDefault,
124  this->modToUnpDefault.data(),
125  this->modToUnpDefault.size() * sizeof(unsigned char),
126  cudaMemcpyDefault,
127  stream));
128  });
129  return data.modToUnpDefault;
130 }
131 
133  std::set<unsigned int> const& modules, cudaStream_t cudaStream) const {
134  auto modToUnpDevice = cms::cuda::make_device_unique<unsigned char[]>(pixelgpudetails::MAX_SIZE, cudaStream);
135  auto modToUnpHost = cms::cuda::make_host_unique<unsigned char[]>(pixelgpudetails::MAX_SIZE, cudaStream);
136 
137  std::vector<unsigned int> const& fedIds = cablingMap_->fedIds();
138  std::unique_ptr<SiPixelFedCablingTree> const& cabling = cablingMap_->cablingTree();
139 
140  unsigned int startFed = *(fedIds.begin());
141  unsigned int endFed = *(fedIds.end() - 1);
142 
144  int index = 1;
145 
146  for (unsigned int fed = startFed; fed <= endFed; fed++) {
147  for (unsigned int link = 1; link <= pixelgpudetails::MAX_LINK; link++) {
148  for (unsigned int roc = 1; roc <= pixelgpudetails::MAX_ROC; roc++) {
149  path = {fed, link, roc};
150  const sipixelobjects::PixelROC* pixelRoc = cabling->findItem(path);
151  if (pixelRoc != nullptr) {
152  modToUnpHost[index] = (not modules.empty()) and (modules.find(pixelRoc->rawId()) == modules.end());
153  } else { // store some dummy number
154  modToUnpHost[index] = true;
155  }
156  index++;
157  }
158  }
159  }
160 
161  cudaCheck(cudaMemcpyAsync(modToUnpDevice.get(),
162  modToUnpHost.get(),
163  pixelgpudetails::MAX_SIZE * sizeof(unsigned char),
164  cudaMemcpyHostToDevice,
165  cudaStream));
166  return modToUnpDevice;
167 }
168 
170 
const unsigned char * getModToUnpAllAsync(cudaStream_t cudaStream) const
unsigned char badRocs[pixelgpudetails::MAX_SIZE]
unsigned int rawId[pixelgpudetails::MAX_SIZE]
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const SiPixelROCsStatusAndMapping * getGPUProductAsync(cudaStream_t cudaStream) const
unsigned int moduleId[pixelgpudetails::MAX_SIZE]
unsigned int roc[pixelgpudetails::MAX_SIZE]
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
unsigned int rocInDet[pixelgpudetails::MAX_SIZE]
cms::cuda::ESProduct< ModulesToUnpack > modToUnp_
constexpr unsigned int MAX_ROC
std::vector< unsigned int > fedIds() const
constexpr uint16_t invalidModuleId
unsigned int link[pixelgpudetails::MAX_SIZE]
SiPixelROCsStatusAndMappingWrapper(SiPixelFedCablingMap const &cablingMap, TrackerGeometry const &trackerGeom, SiPixelQuality const *badPixelInfo)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< unsigned char, cms::cuda::HostAllocator< unsigned char > > modToUnpDefault
constexpr unsigned int MAX_SIZE
constexpr unsigned int MAX_SIZE_BYTE_BOOL
unsigned int fed[pixelgpudetails::MAX_SIZE]
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
constexpr unsigned int MAX_LINK
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: PixelROC.h:34
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
#define LogDebug(id)
cms::cuda::device::unique_ptr< unsigned char[]> getModToUnpRegionalAsync(std::set< unsigned int > const &modules, cudaStream_t cudaStream) const