112 throw std::runtime_error(
113 "TracccTritonRunner: initializer is not ready");
116 if (cudaSetDevice(initializer.
deviceId()) != cudaSuccess) {
117 throw std::runtime_error(
118 "TracccTritonRunner: cudaSetDevice(" +
119 std::to_string(initializer.deviceId()) +
") failed");
122 if (
m_impl->eventStore.retrieve().isFailure() || !
m_impl->eventStore) {
123 throw std::runtime_error(
124 "TracccTritonRunner: could not retrieve StoreGateSvc");
131 svcLocator->service<IHiveWhiteBoard>(
"EventDataSvc",
false);
133 throw std::runtime_error(
134 "TracccTritonRunner: EventDataSvc is not an IHiveWhiteBoard");
136 if (slot >=
m_impl->whiteboard->getNumberOfStores()) {
137 throw std::runtime_error(
138 "TracccTritonRunner: slot " + std::to_string(slot) +
139 " is out of range, the whiteboard has only " +
140 std::to_string(m_impl->whiteboard->getNumberOfStores()) +
145 SmartIF<AthCUDA::IStreamSvc> streamSvc =
149 throw std::runtime_error(
150 "TracccTritonRunner: could not retrieve the CUDA stream service '" +
152 "'; TracccTritonBootstrap.py has to set "
153 "flags.CUDA.Stream = CUDAStream.PerEvent");
155 m_impl->stream =
static_cast<cudaStream_t
>(
156 streamSvc->stream(EventContext(0, slot)));
159 IAlgManager* algMgr = svcLocator.as<IAlgManager>();
161 throw std::runtime_error(
162 "TracccTritonRunner: no IAlgManager in the embedded application");
167 throw std::runtime_error(
168 "TracccTritonRunner: could not retrieve the device chain '" +
169 initializer.config().sequenceName +
170 "' from the embedded Athena application");
176 svcLocator->service<IIncidentSvc>(
"IncidentSvc",
false);
178 throw std::runtime_error(
179 "TracccTritonRunner: could not retrieve IncidentSvc");
186 m_impl->conditionsCleaner =
187 svcLocator->service<Athena::IConditionsCleanerSvc>(
188 "Athena::ConditionsCleanerSvc", true);
189 if (!m_impl->conditionsCleaner) {
190 throw std::runtime_error(
191 "TracccTritonRunner: could not retrieve "
192 "Athena::ConditionsCleanerSvc");
199 m_impl->algExecStates = svcLocator->service<IAlgExecStateSvc>(
200 "AlgExecStateSvc",
false);
201 if (!
m_impl->algExecStates) {
202 throw std::runtime_error(
203 "TracccTritonRunner: could not retrieve AlgExecStateSvc");
210 const EventIDBase& eventID,
211 EventIDBase::number_type conditionsRun,
212 bool printStats,
Output& output) {
213 const auto& keys =
m_impl->initializer.config();
215 auto t0 = std::chrono::high_resolution_clock::now();
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");
224 auto t1 = std::chrono::high_resolution_clock::now();
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));
233 if (
m_impl->eventStore->clearStore().isFailure()) {
234 throw std::runtime_error(
"TracccTritonRunner: clearStore() failed");
240 const std::size_t eventNumber =
m_impl->eventCounter++;
241 EventContext ctx(eventNumber,
m_impl->slot);
242 EventIDBase ctxEventID(eventID);
243 ctxEventID.set_event_number(eventNumber);
244 ctx.setEventID(ctxEventID);
246 m_impl->eventStore->hiveProxyDict(), conditionsRun));
247 Gaudi::Hive::setCurrentContext(ctx);
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();
256 ->record(std::move(deviceCells), keys.cellsKey)
258 throw std::runtime_error(
259 "TracccTritonRunner: failed to record cells under '" +
260 keys.cellsKey +
"'");
264 auto t2 = std::chrono::high_resolution_clock::now();
269 m_impl->algExecStates->reset(ctx);
272 std::lock_guard<std::mutex>
lock(sharedRunState.mutex);
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));
287 if (
m_impl->conditionsCleaner->event(ctx,
false)
289 throw std::runtime_error(
290 "TracccTritonRunner: conditions cleaning failed");
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());
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());
314 if (cudaStreamSynchronize(
m_impl->stream) != cudaSuccess) {
315 throw std::runtime_error(
316 "TracccTritonRunner: cudaStreamSynchronize failed after the "
320 auto t3 = std::chrono::high_resolution_clock::now();
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 +
"'");
331 const ::traccc::edm::measurement_collection::buffer* measurementsDevice =
334 ->retrieve(measurementsDevice, keys.measurementsKey)
336 measurementsDevice ==
nullptr) {
337 throw std::runtime_error(
338 "TracccTritonRunner: could not retrieve measurements under '" +
339 keys.measurementsKey +
"'");
342 const ::traccc::edm::silicon_cluster_collection::buffer* clustersDevice =
344 if (
m_impl->eventStore->retrieve(clustersDevice, keys.clustersKey)
346 clustersDevice ==
nullptr) {
347 throw std::runtime_error(
348 "TracccTritonRunner: could not retrieve clusters under '" +
349 keys.clustersKey +
"'");
352 const vecmem::copy& copy = *
m_impl->copy;
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);
361 auto t4 = std::chrono::high_resolution_clock::now();
364 auto ms = [](
auto a,
auto b) {
365 return std::chrono::duration_cast<std::chrono::milliseconds>(b -
a)
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()