8 #include <xrt/xrt_bo.h>
9 #include <xrt/xrt_device.h>
10 #include <xrt/xrt_kernel.h>
11 #include <xrt/xrt_uuid.h>
41 std::vector<std::string> listofCUs;
54 for(
unsigned int i = 0;
i < nthreads;
i++)
82 for (
const auto& cuName: listofCUs)
94 else if(cuName.find(
m_stripL2GKernelName.value()) != std::string::npos) m_stripL2GKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
116 return StatusCode::SUCCESS;
125 const std::vector<uint64_t>* pixelInput{
nullptr}, *stripInput{
nullptr};
137 size_t bufferIndex = ctx.slot() % nthreads;
140 size_t pixelClusterIndex = ctx.slot() % m_pixelClusteringKernels.size();
141 size_t stripClusterIndex = ctx.slot() % m_stripClusteringKernels.size();
142 size_t stripL2GIndex = ctx.slot() % m_stripL2GKernels.size();
143 size_t pixelL2GIndex = m_pixelL2GKernels.size() ? ctx.slot() % m_pixelL2GKernels.size() : 0;
144 size_t edmIndex = m_edmPrepKernels.size() ? ctx.slot() % m_edmPrepKernels.size() : 0;
145 size_t pixelEDMIndex = m_pixelEdmPrepKernels.size() ? ctx.slot() % m_pixelEdmPrepKernels.size() : 0;
146 size_t stripEDMIndex = m_stripEdmPrepKernels.size() ? ctx.slot() % m_stripEdmPrepKernels.size() : 0;
148 const cl::CommandQueue &acc_queue =
m_acc_queues[bufferIndex];
150 ATH_MSG_INFO(
"Thread number "<<ctx.slot()<<
" running on buffer "<<bufferIndex<<
" pixelClusterIndex: "<< pixelClusterIndex<<
" stripClusterIndex: "<< stripClusterIndex<<
" stripL2GIndex: "<< stripL2GIndex<<
" pixelL2GIndex: "<< pixelL2GIndex<<
" edmIndex: "<< edmIndex<<
" pixelEDMIndex: "<< pixelEDMIndex<<
" stripEDMIndex: "<< stripEDMIndex);
152 cl::Kernel &pixelClusteringKernel = m_pixelClusteringKernels[pixelClusterIndex];
153 cl::Kernel &stripClusteringKernel = m_stripClusteringKernels[stripClusterIndex];
154 cl::Kernel &stripL2GKernel = m_stripL2GKernels[stripL2GIndex];
156 cl::Kernel *pixelL2GKernel =
nullptr;
157 cl::Kernel *edmPrepKernel =
nullptr;
158 cl::Kernel *pixelEdmPrepKernel =
nullptr;
159 cl::Kernel *stripEdmPrepKernel =
nullptr;
162 pixelEdmPrepKernel = &m_pixelEdmPrepKernels[pixelEDMIndex];
163 stripEdmPrepKernel = &m_stripEdmPrepKernels[stripEDMIndex];
165 edmPrepKernel = &m_edmPrepKernels[edmIndex];
166 pixelL2GKernel = &m_pixelL2GKernels[pixelL2GIndex];
181 stripClusteringKernel.setArg(3,
static_cast<unsigned int>((*stripInput).size()));
215 std::vector<cl::Event> evt_vec_pixel_input{evt_write_pixel_input};
216 std::vector<cl::Event> evt_vec_strip_input{evt_write_strip_input};
228 acc_queue.enqueueTask(pixelClusteringKernel, &evt_vec_pixel_input, &evt_pixel_clustering);
229 acc_queue.enqueueTask(stripClusteringKernel, &evt_vec_strip_input, &evt_strip_clustering);
231 std::vector<cl::Event> evt_vec_pixel_clustering{evt_pixel_clustering};
232 std::vector<cl::Event> evt_vec_strip_clustering{evt_strip_clustering};
235 acc_queue.enqueueTask(*pixelL2GKernel, &evt_vec_pixel_clustering, &evt_pixel_l2g);
237 acc_queue.enqueueTask(stripL2GKernel, &evt_vec_strip_clustering, &evt_strip_l2g);
241 std::vector<cl::Event> evt_vec_l2g{evt_pixel_l2g, evt_strip_l2g};
242 acc_queue.enqueueTask(*edmPrepKernel, &evt_vec_l2g, &evt_edm_prep);
245 std::vector<cl::Event> evt_vec_strip_l2g{evt_strip_l2g};
246 acc_queue.enqueueTask(*pixelEdmPrepKernel, &evt_vec_pixel_clustering, &evt_pixel_edm_prep);
247 acc_queue.enqueueTask(*stripEdmPrepKernel, &evt_vec_strip_l2g, &evt_strip_edm_prep);
254 std::vector<cl::Event> evt_vec_pixel_edm_prep;
255 std::vector<cl::Event> evt_vec_strip_edm_prep;
258 evt_vec_pixel_edm_prep.push_back(evt_pixel_edm_prep);
259 evt_vec_strip_edm_prep.push_back(evt_strip_edm_prep);
263 evt_vec_pixel_edm_prep.push_back(evt_edm_prep);
264 evt_vec_strip_edm_prep.push_back(evt_edm_prep);
275 acc_queue.enqueueReadBuffer(
m_edmPixelOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * (*FPGAPixelOutput).size(), (*FPGAPixelOutput).data(), &evt_vec_pixel_edm_prep, &evt_pixel_cluster_output);
276 acc_queue.enqueueReadBuffer(
m_edmStripOutputBufferList[bufferIndex], CL_FALSE, 0,
sizeof(
uint64_t) * (*FPGAStripOutput).size(), (*FPGAStripOutput).data(), &evt_vec_strip_edm_prep, &evt_strip_cluster_output);
278 std::vector<cl::Event> wait_for_reads = { evt_pixel_cluster_output, evt_strip_cluster_output };
279 cl::Event::waitForEvents(wait_for_reads);
282 if(pixelInput->size() == 6) (*FPGAPixelOutput)[0] = 0;
283 if(stripInput->size() == 6) (*FPGAStripOutput)[0] = 0;
288 cl_ulong pixel_input_time = evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
290 ATH_MSG_DEBUG(
"Pixel input buffer write time: " << pixel_input_time / 1e6 <<
" ms");
293 cl_ulong strip_input_time = evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
295 ATH_MSG_DEBUG(
"Strip input buffer write time: " << strip_input_time / 1e6 <<
" ms");
298 cl_ulong pixel_clustering_time = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
300 ATH_MSG_DEBUG(
"Pixel clustering time: " << pixel_clustering_time / 1e6 <<
" ms");
303 cl_ulong strip_clustering_time = evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
305 ATH_MSG_DEBUG(
"Strip clustering time: " << strip_clustering_time / 1e6 <<
" ms");
309 cl_ulong pixel_l2g_time = evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
311 ATH_MSG_DEBUG(
"Pixel L2G time: " << pixel_l2g_time / 1e6 <<
" ms");
315 cl_ulong strip_l2g_time = evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
317 ATH_MSG_DEBUG(
"Strip L2G time: " << strip_l2g_time / 1e6 <<
" ms");
321 cl_ulong pixel_edm_prep_time = evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
322 cl_ulong strip_edm_prep_time = evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
325 ATH_MSG_DEBUG(
"PixelEDMPrep time: " << pixel_edm_prep_time / 1e6 <<
" ms");
328 ATH_MSG_DEBUG(
"StripEDMPrep time: " << strip_edm_prep_time / 1e6 <<
" ms");
331 cl_ulong edm_prep_time = evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
334 ATH_MSG_DEBUG(
"EDMPrep time: " << edm_prep_time / 1e6 <<
" ms");
338 cl_ulong kernel_start = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
340 std::max(evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>(), evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>()) :
341 evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>();
343 ATH_MSG_DEBUG(
"Kernel execution time: " << (kernel_end - kernel_start) / 1e6 <<
" ms");
346 cl_ulong pixel_output_time = evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
348 ATH_MSG_DEBUG(
"Pixel output buffer read time: " << pixel_output_time / 1e6 <<
" ms");
351 cl_ulong strip_output_time = evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
353 ATH_MSG_DEBUG(
"Strip output buffer read time: " << strip_output_time / 1e6 <<
" ms");
355 return StatusCode::SUCCESS;
384 return StatusCode::SUCCESS;
392 ATH_MSG_INFO(
"fpga name: "<<xrt_xclbin.get_fpga_device_name());
393 ATH_MSG_INFO(
"uuid: "<<xrt_xclbin.get_uuid().to_string());
395 for (
const xrt::xclbin::kernel &kernel : xrt_xclbin.get_kernels()) {
396 const std::string& kernelName = kernel.get_name();
402 const std::string& computeUnitName = computeUnit.get_name();
403 const std::string computeUnitIsolatedName = computeUnitName.substr(kernelName.size() + 1);
405 const std::string computeUnitUsableName = kernelName +
":{" + computeUnitIsolatedName +
"}";
408 cuNames.push_back(computeUnitUsableName);