8 #include <xrt/xrt_bo.h>
9 #include <xrt/xrt_device.h>
10 #include <xrt/xrt_kernel.h>
11 #include <xrt/xrt_uuid.h>
43 std::vector<std::string> listofCUs;
56 for(
unsigned int i = 0;
i < nthreads;
i++)
90 for (
const auto& cuName: listofCUs)
98 else if(cuName.find(
m_stripL2GKernelName.value()) != std::string::npos) m_stripL2GKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
101 else if(cuName.find(
m_pixelEdmKernelName.value()) != std::string::npos) m_pixelEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
102 else if(cuName.find(
m_stripEdmKernelName.value()) != std::string::npos) m_stripEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
107 else if(cuName.find(
m_insideOutInputName.value()) != std::string::npos) m_insideOutInputKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
108 else if(cuName.find(
m_insideOutOutputName.value()) != std::string::npos) m_insideOutOutputKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
125 if(m_pixelClusteringKernels.size()==0){
127 return StatusCode::FAILURE;
138 return StatusCode::SUCCESS;
144 auto withEvt = [&](
const std::string&
fname) {
145 const auto evt = ctx.eventID().event_number();
147 if (
dot == std::string::npos) {
155 std::ofstream
outputFile(withEvt(dataDescriptor));
158 outputFile << std::hex << std::setw(16) << std::setfill(
'0') <<
d <<
'\n';
172 mnt_timer_Total.start();
177 const std::vector<uint64_t>* pixelInput{
nullptr}, *stripInput{
nullptr};
189 size_t bufferIndex = ctx.slot() % nthreads;
192 size_t pixelClusterIndex = ctx.slot() % m_pixelClusteringKernels.size();
193 size_t stripClusterIndex = ctx.slot() % m_stripClusteringKernels.size();
194 size_t stripL2GIndex = ctx.slot() % m_stripL2GKernels.size();
195 size_t pixelEDMIndex = ctx.slot() % m_pixelEdmPrepKernels.size();
196 size_t stripEDMIndex = ctx.slot() % m_stripEdmPrepKernels.size();
197 size_t slicingInIndex = ctx.slot() % m_slicingEngineInputKernels.size();
198 size_t slicingOutIndex = ctx.slot() % m_slicingEngineOutputKernels.size();
199 size_t insideOutInputIndex = ctx.slot() % m_insideOutInputKernels.size();
200 size_t insideOutOutputIndex = ctx.slot() % m_insideOutOutputKernels.size();
202 const cl::CommandQueue &acc_queue =
m_acc_queues[bufferIndex];
204 cl::Kernel &pixelClusteringKernel = m_pixelClusteringKernels[pixelClusterIndex];
205 cl::Kernel &stripClusteringKernel = m_stripClusteringKernels[stripClusterIndex];
206 cl::Kernel &stripL2GKernel = m_stripL2GKernels[stripL2GIndex];
207 cl::Kernel &pixelEdmPrepKernel = m_pixelEdmPrepKernels[pixelEDMIndex];
208 cl::Kernel &stripEdmPrepKernel = m_stripEdmPrepKernels[stripEDMIndex];
209 cl::Kernel &slicingEngineInputKernel = m_slicingEngineInputKernels[slicingInIndex];
210 cl::Kernel &slicingEngineOutputKernel = m_slicingEngineOutputKernels[slicingOutIndex];
211 cl::Kernel &insideOutInputKernel = m_insideOutInputKernels[insideOutInputIndex];
212 cl::Kernel &insideOutOutputKernel = m_insideOutOutputKernels[insideOutOutputIndex];
225 stripClusteringKernel.setArg(3,
static_cast<unsigned int>((*stripInput).size()));
255 acc_queue.enqueueWriteBuffer(
m_pixelClusterInputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * (*pixelInput).size(), (*pixelInput).data(),
nullptr, &evt_write_pixel_input);
256 acc_queue.enqueueWriteBuffer(
m_stripClusterInputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * (*stripInput).size(), (*stripInput).data(),
nullptr, &evt_write_strip_input);
257 std::vector<cl::Event> evt_vec_pixel_input{evt_write_pixel_input};
258 std::vector<cl::Event> evt_vec_strip_input{evt_write_strip_input};
261 cl::Event evt_pixel_clustering, evt_strip_clustering;
263 cl::Event evt_pixel_edm_prep, evt_strip_edm_prep;
264 cl::Event evt_copy_strip_clusters_to_l2g_in, evt_copy_strip_edm_to_l2g_in;
265 cl::Event evt_copy_pix_edm_in, evt_copy_str_edm_in;
269 acc_queue.enqueueTask(pixelClusteringKernel, &evt_vec_pixel_input, &evt_pixel_clustering);
270 acc_queue.enqueueTask(stripClusteringKernel, &evt_vec_strip_input, &evt_strip_clustering);
272 std::vector<cl::Event> after_strip_cluster { evt_strip_clustering };
276 std::vector<cl::Event> l2g_inputs {evt_copy_strip_clusters_to_l2g_in, evt_copy_strip_edm_to_l2g_in};
277 acc_queue.enqueueTask(stripL2GKernel, &l2g_inputs, &evt_strip_l2g);
279 std::vector<cl::Event> after_pix_cluster { evt_pixel_clustering };
282 std::vector<cl::Event> after_l2g { evt_strip_l2g };
285 std::vector<cl::Event> after_pix_edm_in { evt_copy_pix_edm_in };
286 std::vector<cl::Event> after_str_edm_in { evt_copy_str_edm_in };
287 acc_queue.enqueueTask(pixelEdmPrepKernel, &after_pix_edm_in, &evt_pixel_edm_prep);
288 acc_queue.enqueueTask(stripEdmPrepKernel, &after_str_edm_in, &evt_strip_edm_prep);
294 std::vector<cl::Event> evt_vec_pixel_edm_prep {evt_pixel_edm_prep};
295 std::vector<cl::Event> evt_vec_strip_edm_prep {evt_strip_edm_prep};
304 acc_queue.enqueueReadBuffer(
m_edmPixelOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint32_t) * (*FPGAPixelOutput).size(), (*FPGAPixelOutput).data(), &evt_vec_pixel_edm_prep, &evt_pixel_cluster_output);
305 acc_queue.enqueueReadBuffer(
m_edmStripOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint32_t) * (*FPGAStripOutput).size(), (*FPGAStripOutput).data(), &evt_vec_strip_edm_prep, &evt_strip_cluster_output);
310 std::vector<cl::Event> after_pix_cluster { evt_pixel_clustering };
311 acc_queue.enqueueReadBuffer(
m_pixelClusterOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * pixelClusterOut.size(), pixelClusterOut.data(), &after_pix_cluster, &evt_read_pixel_cluster_raw);
313 std::vector<cl::Event> wait_for_reads = { evt_pixel_cluster_output, evt_read_pixel_cluster_raw };
314 cl::Event::waitForEvents(wait_for_reads);
316 mnt_timer_Total.stop();
318 if(pixelInput->size() == 6) (*FPGAPixelOutput)[0] = 0;
319 if(stripInput->size() == 6) (*FPGAStripOutput)[0] = 0;
324 int nWords =
static_cast<int>(pixelClusterOut.size()) - 1;
325 for (; nWords >= 0; --nWords)
327 if (pixelClusterOut[nWords] == 0xcd00000000000000)
break;
331 ATH_MSG_ERROR(
"Footer 0xcd00000000000000 not found in pixelClusterOut");
332 return StatusCode::FAILURE;
334 if (nWords > 0) nWords += 3;
337 for (
int i = 0; i < 8 && (nWords + i) < static_cast<int>(pixelClusterOut.size()); ++
i)
339 pixelClusterOut[nWords +
i] = 0;
343 cl::Event evt_se_input_done, evt_se_output_done;
344 cl::Event evt_insideoutInput_done, evt_insideoutOutput_done;
349 slicingEngineInputKernel.setArg(2,
static_cast<unsigned long long>(nWords));
356 std::vector<cl::Event> after_se_write { evt_write_se_in };
357 acc_queue.enqueueTask(slicingEngineInputKernel, &after_se_write, &evt_se_input_done);
358 acc_queue.enqueueTask(slicingEngineOutputKernel,
nullptr, &evt_se_output_done);
363 std::vector<cl::Event> after_se_out { evt_se_output_done };
366 std::vector<cl::Event> after_io_in { evt_copy_se_to_io_in };
367 acc_queue.enqueueTask(insideOutInputKernel, &after_io_in, &evt_insideoutInput_done);
368 acc_queue.enqueueTask(insideOutOutputKernel,
nullptr, &evt_insideoutOutput_done);
376 std::vector<cl::Event> evt_vec_insideout_output { evt_insideoutOutput_done };
377 acc_queue.enqueueReadBuffer(
m_insideOutOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * (*FPGATrackOutput).size(), (*FPGATrackOutput).data(), &evt_vec_insideout_output, &evt_track_output);
379 std::vector<cl::Event> wait_for_Trackreads = { evt_track_output };
380 cl::Event::waitForEvents(wait_for_Trackreads);
384 cl_ulong pixel_input_time = evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
386 ATH_MSG_DEBUG(
"Pixel input buffer write time: " << pixel_input_time / 1e6 <<
" ms");
389 cl_ulong strip_input_time = evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
391 ATH_MSG_DEBUG(
"Strip input buffer write time: " << strip_input_time / 1e6 <<
" ms");
394 cl_ulong pixel_clustering_time = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
396 ATH_MSG_DEBUG(
"Pixel clustering time: " << pixel_clustering_time / 1e6 <<
" ms");
399 cl_ulong strip_clustering_time = evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
401 ATH_MSG_DEBUG(
"Strip clustering time: " << strip_clustering_time / 1e6 <<
" ms");
404 cl_ulong strip_l2g_time = evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
406 ATH_MSG_DEBUG(
"Strip L2G time: " << strip_l2g_time / 1e6 <<
" ms");
408 cl_ulong pixel_edm_prep_time = evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
409 cl_ulong strip_edm_prep_time = evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
412 ATH_MSG_DEBUG(
"PixelEDMPrep time: " << pixel_edm_prep_time / 1e6 <<
" ms");
415 ATH_MSG_DEBUG(
"StripEDMPrep time: " << strip_edm_prep_time / 1e6 <<
" ms");
419 cl_ulong kernel_start = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
420 cl_ulong kernel_end =
std::max(evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>(), evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>());
422 ATH_MSG_DEBUG(
"Kernel execution time: " << (kernel_end - kernel_start) / 1e6 <<
" ms");
425 cl_ulong pixel_output_time = evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
427 ATH_MSG_DEBUG(
"Pixel output buffer read time: " << pixel_output_time / 1e6 <<
" ms");
430 cl_ulong strip_output_time = evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
432 ATH_MSG_DEBUG(
"Strip output buffer read time: " << strip_output_time / 1e6 <<
" ms");
434 return StatusCode::SUCCESS;
456 return StatusCode::SUCCESS;
461 xrt::xclbin xrt_xclbin(
m_xclbin.value());
464 ATH_MSG_INFO(
"fpga name: "<<xrt_xclbin.get_fpga_device_name());
465 ATH_MSG_INFO(
"uuid: "<<xrt_xclbin.get_uuid().to_string());
467 for (
const xrt::xclbin::kernel &kernel : xrt_xclbin.get_kernels()) {
468 const std::string& kernelName = kernel.get_name();
474 const std::string& computeUnitName = computeUnit.get_name();
475 const std::string computeUnitIsolatedName = computeUnitName.substr(kernelName.size() + 1);
477 const std::string computeUnitUsableName = kernelName +
":{" + computeUnitIsolatedName +
"}";
480 cuNames.push_back(computeUnitUsableName);