CMS 3D CMS Logo

ClustersFromRawProducerGPU.cc
Go to the documentation of this file.
1 /*
2  */
4 
6 
9 
12 
22 
24 
26 
28 #include "ChannelLocsGPU.h"
29 
30 //#include <sstream>
31 #include <memory>
32 #include <mutex>
33 
34 namespace {
35  std::unique_ptr<sistrip::FEDBuffer> fillBuffer(int fedId, const FEDRawData& rawData) {
36  std::unique_ptr<sistrip::FEDBuffer> buffer;
37 
38  // Check on FEDRawData pointer
39  const auto st_buffer = sistrip::preconstructCheckFEDBuffer(rawData);
41  LogDebug(sistrip::mlRawToCluster_) << "[ClustersFromRawProducer::" << __func__ << "]" << st_buffer
42  << " for FED ID " << fedId;
43  return buffer;
44  }
45  buffer = std::make_unique<sistrip::FEDBuffer>(rawData);
46  const auto st_chan = buffer->findChannels();
48  LogDebug(sistrip::mlRawToCluster_) << "Exception caught when creating FEDBuffer object for FED " << fedId << ": "
49  << st_chan;
50  buffer.reset();
51  return buffer;
52  }
53  if UNLIKELY (!buffer->doChecks(false)) {
54  LogDebug(sistrip::mlRawToCluster_) << "Exception caught when creating FEDBuffer object for FED " << fedId
55  << ": FED Buffer check fails";
56  buffer.reset();
57  return buffer;
58  }
59 
60  return buffer;
61  }
62 } // namespace
63 
64 class SiStripClusterizerFromRawGPU final : public edm::stream::EDProducer<edm::ExternalWork> {
65 public:
69  gpuAlgo_(conf.getParameter<edm::ParameterSet>("Clusterizer")),
70  inputToken_(consumes(conf.getParameter<edm::InputTag>("ProductLabel"))),
71  outputToken_(produces<cms::cuda::Product<SiStripClustersCUDADevice>>()),
72  conditionsToken_(esConsumes(edm::ESInputTag{"", conf.getParameter<std::string>("ConditionsLabel")})),
73  cpuConditionsToken_(esConsumes(edm::ESInputTag{"", conf.getParameter<std::string>("ConditionsLabel")})) {}
74 
75  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
76 
77 private:
78  void acquire(edm::Event const& ev,
79  edm::EventSetup const& es,
80  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override {
81  const auto& conditions = es.getData(conditionsToken_); //these need to be GPU conditions
82  const auto& cpuConditions = es.getData(cpuConditionsToken_); //CPU conditions
83 
84  // Sets the current device and creates a CUDA stream
85  cms::cuda::ScopedContextAcquire ctx{ev.streamID(), std::move(waitingTaskHolder), ctxState_};
86 
87  // get raw data
88  auto const& rawData = ev.get(inputToken_);
89  run(rawData, cpuConditions);
90 
91  // Queues asynchronous data transfers and kernels to the CUDA stream
92  // returned by cms::cuda::ScopedContextAcquire::stream()
93  gpuAlgo_.makeAsync(raw_, buffers_, conditions, ctx.stream());
94 
95  // Destructor of ctx queues a callback to the CUDA stream notifying
96  // waitingTaskHolder when the queued asynchronous work has finished
97  }
98 
99  void produce(edm::Event& ev, const edm::EventSetup& es) override {
101 
102  // Now getResult() returns data in GPU memory that is passed to the
103  // constructor of OutputData. cms::cuda::ScopedContextProduce::emplace() wraps the
104  // OutputData to cms::cuda::Product<OutputData>. cms::cuda::Product<T> stores also
105  // the current device and the CUDA stream since those will be needed
106  // in the consumer side.
107  ctx.emplace(ev, outputToken_, gpuAlgo_.getResults(ctx.stream()));
108 
109  for (auto& buf : buffers_)
110  buf.reset(nullptr);
111  }
112 
113 private:
115  void fill(uint32_t idet, const FEDRawDataCollection& rawColl, const SiStripClusterizerConditions& conditions);
116 
117 private:
118  std::vector<std::unique_ptr<sistrip::FEDBuffer>> buffers_;
119  std::vector<const FEDRawData*> raw_;
121 
123 
128 };
129 
132 
133  desc.add("ProductLabel", edm::InputTag("rawDataCollector"));
134  desc.add<std::string>("ConditionsLabel", "");
135 
138  desc.add("Clusterizer", clusterizer);
139 
140  descriptions.addWithDefaultLabel(desc);
141 }
142 
145  // loop over good det in cabling
146  for (auto idet : conditions.allDetIds()) {
147  fill(idet, rawColl, conditions);
148  } // end loop over dets
149 }
150 
152  const FEDRawDataCollection& rawColl,
154  auto const& det = conditions.findDetId(idet);
155  if (!det.valid())
156  return;
157 
158  // Loop over apv-pairs of det
159  for (auto const conn : conditions.currentConnection(det)) {
160  if UNLIKELY (!conn)
161  continue;
162 
163  const uint16_t fedId = conn->fedId();
164 
165  // If fed id is null or connection is invalid continue
166  if UNLIKELY (!fedId || !conn->isConnected()) {
167  continue;
168  }
169 
170  // If Fed hasnt already been initialised, extract data and initialise
172  if (!buffer) {
173  const FEDRawData& rawData = rawColl.FEDData(fedId);
174  raw_[fedId] = &rawData;
175  buffers_[fedId] = fillBuffer(fedId, rawData);
176  }
177  } // end loop over conn
178 }
179 
std::vector< const FEDRawData * > raw_
edm::ESGetToken< stripgpu::SiStripClusterizerConditionsGPU, SiStripClusterizerConditionsRcd > conditionsToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< FEDRawDataCollection > inputToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::vector< std::unique_ptr< sistrip::FEDBuffer > > buffers_
edm::EDPutTokenT< cms::cuda::Product< SiStripClustersCUDADevice > > outputToken_
static const char mlRawToCluster_[]
void makeAsync(const std::vector< const FEDRawData *> &rawdata, const std::vector< std::unique_ptr< sistrip::FEDBuffer >> &buffers, const SiStripClusterizerConditionsGPU &conditions, cudaStream_t stream)
sistrip classes
void acquire(edm::Event const &ev, edm::EventSetup const &es, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
SiStripClustersCUDADevice getResults(cudaStream_t stream)
stripgpu::SiStripRawToClusterGPUKernel gpuAlgo_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Namespace of DDCMS conversion namespace.
void fill(uint32_t idet, const FEDRawDataCollection &rawColl, const SiStripClusterizerConditions &conditions)
edm::ESGetToken< SiStripClusterizerConditions, SiStripClusterizerConditionsRcd > cpuConditionsToken_
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
conn
Definition: getInfo.py:9
FEDBufferStatusCode preconstructCheckFEDBuffer(const FEDRawData &fedBuffer, bool allowBadBuffer=false)
static void fillDescriptions(edm::ParameterSetDescription &clusterizer)
static const uint16_t FED_ID_MAX
#define UNLIKELY(x)
Definition: Likely.h:21
void run(const FEDRawDataCollection &rawColl, const SiStripClusterizerConditions &conditions)
SiStripClusterizerFromRawGPU(const edm::ParameterSet &conf)
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &ev, const edm::EventSetup &es) override
#define LogDebug(id)