Run the full chain for one request.
212 {
213 const auto&
keys =
m_impl->initializer.config();
214
215 auto t0 = std::chrono::high_resolution_clock::now();
216
217
218 ::traccc::edm::silicon_cell_collection::host
cells(
m_impl->host_mr);
219 if (buffer == nullptr) {
220 throw std::runtime_error("TracccTritonRunner: no CELLS buffer");
221 }
223
224 auto t1 = std::chrono::high_resolution_clock::now();
225
226 if (
m_impl->whiteboard->selectStore(
m_impl->slot).isFailure()) {
227 throw std::runtime_error(
228 "TracccTritonRunner: could not select store for slot " +
229 std::to_string(
m_impl->slot));
230 }
231
232
233 if (
m_impl->eventStore->clearStore().isFailure()) {
234 throw std::runtime_error("TracccTritonRunner: clearStore() failed");
235 }
236
237
238
239
241 EventContext ctx(eventNumber,
m_impl->slot);
242 EventIDBase ctxEventID(eventID);
243 ctxEventID.set_event_number(eventNumber);
244 ctx.setEventID(ctxEventID);
245 ctx.setExtension(Atlas::ExtendedEventContext(
246 m_impl->eventStore->hiveProxyDict(), conditionsRun));
247 Gaudi::Hive::setCurrentContext(ctx);
248 {
249 auto deviceCells =
250 std::make_unique<::traccc::edm::silicon_cell_collection::buffer>(
251 static_cast<unsigned int>(
cells.size()),
m_impl->device_mr);
252 m_impl->copy->setup(*deviceCells)->ignore();
253 (*
m_impl->copy)(vecmem::get_data(cells), *deviceCells)->wait();
254
256 ->record(std::move(deviceCells),
keys.cellsKey)
257 .isFailure()) {
258 throw std::runtime_error(
259 "TracccTritonRunner: failed to record cells under '" +
260 keys.cellsKey +
"'");
261 }
262 }
263
264 auto t2 = std::chrono::high_resolution_clock::now();
265
266
267
268
269 m_impl->algExecStates->reset(ctx);
270
272 std::lock_guard<std::mutex>
lock(sharedRunState.mutex);
273
274
275
276
277 const EventIDBase::number_type
run = ctx.eventID().run_number();
278 if (sharedRunState.currentRun !=
run) {
279 sharedRunState.currentRun =
run;
280 m_impl->incidentSvc->fireIncident(
281 Incident("TracccTritonRunner", IncidentType::BeginRun, ctx));
282 }
283
284
285
286
287 if (
m_impl->conditionsCleaner->event(ctx,
false)
288 .isFailure()) {
289 throw std::runtime_error(
290 "TracccTritonRunner: conditions cleaning failed");
291 }
292
293
294
295
296 if (
m_impl->condChain->sysExecute(ctx).isFailure()) {
297 std::ostringstream
states;
298 m_impl->algExecStates->dump(states, ctx);
299 throw std::runtime_error(
300 "TracccTritonRunner: conditions sequence '" +
301 m_impl->condChain->name() +
302 "' failed during execute(). Algorithm states:\n" +
states.str());
303 }
304 }
305
306 if (
m_impl->chain->sysExecute(ctx).isFailure()) {
307 std::ostringstream
states;
308 m_impl->algExecStates->dump(states, ctx);
309 throw std::runtime_error(
310 "TracccTritonRunner: device chain '" +
m_impl->chain->name() +
311 "' failed during execute(). Algorithm states:\n" +
states.str());
312 }
313
314 if (cudaStreamSynchronize(
m_impl->stream) != cudaSuccess) {
315 throw std::runtime_error(
316 "TracccTritonRunner: cudaStreamSynchronize failed after the "
317 "device chain");
318 }
319
320 auto t3 = std::chrono::high_resolution_clock::now();
321
322
323 const traccc_track_container::buffer* tracksDevice = nullptr;
324 if (
m_impl->eventStore->retrieve(tracksDevice,
keys.tracksKey).isFailure() ||
325 tracksDevice == nullptr) {
326 throw std::runtime_error(
327 "TracccTritonRunner: could not retrieve tracks under '" +
328 keys.tracksKey +
"'");
329 }
330
331 const ::traccc::edm::measurement_collection::buffer* measurementsDevice =
332 nullptr;
334 ->retrieve(measurementsDevice,
keys.measurementsKey)
335 .isFailure() ||
336 measurementsDevice == nullptr) {
337 throw std::runtime_error(
338 "TracccTritonRunner: could not retrieve measurements under '" +
339 keys.measurementsKey +
"'");
340 }
341
342 const ::traccc::edm::silicon_cluster_collection::buffer* clustersDevice =
343 nullptr;
344 if (
m_impl->eventStore->retrieve(clustersDevice,
keys.clustersKey)
345 .isFailure() ||
346 clustersDevice == nullptr) {
347 throw std::runtime_error(
348 "TracccTritonRunner: could not retrieve clusters under '" +
349 keys.clustersKey +
"'");
350 }
351
353 copyJaggedToHost(copy, tracksDevice->tracks,
output.tracks.tracks,
355 copy(tracksDevice->states,
output.tracks.states,
356 vecmem::copy::type::device_to_host)->wait();
357 copy(*measurementsDevice,
output.measurements,
358 vecmem::copy::type::device_to_host)->wait();
359 copyJaggedToHost(copy, *clustersDevice,
output.clusters,
m_impl->host_mr);
360
361 auto t4 = std::chrono::high_resolution_clock::now();
362
363 if (printStats) {
364 auto ms = [](
auto a,
auto b) {
365 return std::chrono::duration_cast<std::chrono::milliseconds>(b -
a)
366 .count();
367 };
368
369 const std::string
tag =
370 "[TIMING][slot " + std::to_string(
m_impl->slot) +
"] ";
371 std::cout <<
tag <<
"Cell deserialization : " <<
ms(
t0, t1) <<
" ms\n"
372 <<
tag <<
"Cell H2D + record : " <<
ms(t1, t2) <<
" ms\n"
373 <<
tag <<
"Device chain : " <<
ms(t2, t3) <<
" ms\n"
374 <<
tag <<
"Output D2H : " <<
ms(t3, t4) <<
" ms\n"
375 <<
tag <<
"Tracks: " <<
output.tracks.tracks.size()
376 << std::endl;
377 }
378}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
void run(const uint8_t *buffer, std::size_t byteSize, const EventIDBase &eventID, EventIDBase::number_type conditionsRun, bool printStats, Output &output)
Run the full chain for one request.
std::vector< ALFA_RawDataContainer_p1 > t2
std::vector< ALFA_RawDataCollection_p1 > t1
std::vector< LUCID_RawDataContainer_p1 > t4
std::vector< LUCID_RawData_p1 > t3
void deserialize(const std::uint8_t *data, std::size_t size, vecmem::edm::host< vecmem::edm::schema< VARTYPES... >, INTERFACE > &container)
Fill container from size bytes at data.