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 
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
SiPixelROCsStatusAndMappingWrapper::cablingMap_
const SiPixelFedCablingMap * cablingMap_
Definition: SiPixelROCsStatusAndMappingWrapper.h:35
TrackerGeometry.h
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
SiPixelROCsStatusAndMappingWrapper::getGPUProductAsync
const SiPixelROCsStatusAndMapping * getGPUProductAsync(cudaStream_t cudaStream) const
Definition: SiPixelROCsStatusAndMappingWrapper.cc:106
modules
Definition: MuonCleanerBySegments.cc:35
SiPixelROCsStatusAndMapping::rawId
unsigned int rawId[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:18
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
GeomDetType.h
SiPixelROCsStatusAndMapping::roc
unsigned int roc[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:17
SiPixelFedCablingMap.h
SiPixelFedCablingTree.h
device_unique_ptr.h
SiPixelROCsStatusAndMappingWrapper::~SiPixelROCsStatusAndMappingWrapper
~SiPixelROCsStatusAndMappingWrapper()
Definition: SiPixelROCsStatusAndMappingWrapper.cc:104
SiPixelROCsStatusAndMapping::link
unsigned int link[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:16
TrackerGeometry::idToDetUnit
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: TrackerGeometry.cc:183
pixelgpudetails::MAX_LINK
constexpr unsigned int MAX_LINK
Definition: SiPixelROCsStatusAndMapping.h:8
pixelgpudetails
Definition: SiPixelROCsStatusAndMapping.h:4
SiPixelROCsStatusAndMappingWrapper::getModToUnpRegionalAsync
cms::cuda::device::unique_ptr< unsigned char[]> getModToUnpRegionalAsync(std::set< unsigned int > const &modules, cudaStream_t cudaStream) const
Definition: SiPixelROCsStatusAndMappingWrapper.cc:132
SiPixelROCsStatusAndMapping::rocInDet
unsigned int rocInDet[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:19
host_unique_ptr.h
SiPixelROCsStatusAndMapping::size
unsigned int size
Definition: SiPixelROCsStatusAndMapping.h:22
pixelgpudetails::MAX_SIZE
constexpr unsigned int MAX_SIZE
Definition: SiPixelROCsStatusAndMapping.h:10
sipixelobjects::CablingPathToDetUnit
Definition: CablingPathToDetUnit.h:5
SiPixelROCsStatusAndMappingWrapper::cablingMapHost
SiPixelROCsStatusAndMapping * cablingMapHost
Definition: SiPixelROCsStatusAndMappingWrapper.h:40
SiPixelROCsStatusAndMappingWrapper::SiPixelROCsStatusAndMappingWrapper
SiPixelROCsStatusAndMappingWrapper(SiPixelFedCablingMap const &cablingMap, TrackerGeometry const &trackerGeom, SiPixelQuality const *badPixelInfo)
Definition: SiPixelROCsStatusAndMappingWrapper.cc:23
SiPixelROCsStatusAndMappingWrapper.h
SiPixelROCsStatusAndMapping::moduleId
unsigned int moduleId[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:20
sipixelobjects::PixelROC::rawId
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: PixelROC.h:34
SiPixelFedCablingMap::cablingTree
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
Definition: SiPixelFedCablingMap.cc:103
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
SiPixelQuality
Definition: SiPixelQuality.h:27
gpuClustering::invalidModuleId
constexpr uint16_t invalidModuleId
Definition: gpuClusteringConstants.h:20
gpuClusteringConstants.h
cudaCheck.h
SiPixelFedCablingMap
Definition: SiPixelFedCablingMap.h:19
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
sipixelobjects::PixelROC
Definition: PixelROC.h:23
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
SiPixelROCsStatusAndMapping::fed
unsigned int fed[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:15
SiPixelROCsStatusAndMapping::badRocs
unsigned char badRocs[pixelgpudetails::MAX_SIZE]
Definition: SiPixelROCsStatusAndMapping.h:21
SiPixelROCsStatusAndMappingWrapper::GPUData::~GPUData
~GPUData()
Definition: SiPixelROCsStatusAndMappingWrapper.cc:169
SiPixelROCsStatusAndMappingWrapper::ModulesToUnpack::~ModulesToUnpack
~ModulesToUnpack()
Definition: SiPixelROCsStatusAndMappingWrapper.cc:171
pixelgpudetails::MAX_SIZE_BYTE_BOOL
constexpr unsigned int MAX_SIZE_BYTE_BOOL
Definition: SiPixelROCsStatusAndMapping.h:11
SiPixelROCsStatusAndMappingWrapper::modToUnpDefault
std::vector< unsigned char, cms::cuda::HostAllocator< unsigned char > > modToUnpDefault
Definition: SiPixelROCsStatusAndMappingWrapper.h:36
SiPixelROCsStatusAndMappingWrapper::ModulesToUnpack
Definition: SiPixelROCsStatusAndMappingWrapper.h:48
SiPixelROCsStatusAndMappingWrapper::modToUnp_
cms::cuda::ESProduct< ModulesToUnpack > modToUnp_
Definition: SiPixelROCsStatusAndMappingWrapper.h:52
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
L1TStage2BMTF_cff.fedIds
fedIds
Definition: L1TStage2BMTF_cff.py:10
SiPixelROCsStatusAndMappingWrapper::GPUData
Definition: SiPixelROCsStatusAndMappingWrapper.h:42
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
SiPixelQuality.h
SiPixelROCsStatusAndMappingWrapper::gpuData_
cms::cuda::ESProduct< GPUData > gpuData_
Definition: SiPixelROCsStatusAndMappingWrapper.h:46
pixelgpudetails::MAX_ROC
constexpr unsigned int MAX_ROC
Definition: SiPixelROCsStatusAndMapping.h:9
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
SiPixelQuality::IsRocBad
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
Definition: SiPixelQuality.cc:107
SiPixelROCsStatusAndMapping
Definition: SiPixelROCsStatusAndMapping.h:14
SiPixelROCsStatusAndMappingWrapper::GPUData::cablingMapDevice
SiPixelROCsStatusAndMapping * cablingMapDevice
Definition: SiPixelROCsStatusAndMappingWrapper.h:44
sipixelobjects::PixelROC::idInDetUnit
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
SiPixelROCsStatusAndMappingWrapper::getModToUnpAllAsync
const unsigned char * getModToUnpAllAsync(cudaStream_t cudaStream) const
Definition: SiPixelROCsStatusAndMappingWrapper.cc:119
TrackerGeometry
Definition: TrackerGeometry.h:14
SiPixelFedCablingMap::fedIds
std::vector< unsigned int > fedIds() const
Definition: SiPixelFedCablingMap.cc:114