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()));
97 else if(cuName.find(
m_pixelEdmKernelName.value()) != std::string::npos) m_pixelEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
99 else if(cuName.find(
m_stripEdmKernelName.value()) != std::string::npos) m_stripEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
114 return StatusCode::SUCCESS;
123 const std::vector<uint64_t>* pixelInput{
nullptr}, *stripInput{
nullptr};
135 size_t bufferIndex = ctx.slot() % nthreads;
138 size_t pixelClusterIndex = ctx.slot() % m_pixelClusteringKernels.size();
139 size_t stripClusterIndex = ctx.slot() % m_stripClusteringKernels.size();
140 size_t stripL2GIndex = ctx.slot() % m_stripL2GKernels.size();
141 size_t pixelL2GIndex = m_pixelL2GKernels.size() ? ctx.slot() % m_pixelL2GKernels.size() : 0;
142 size_t pixelEDMIndex = m_pixelEdmPrepKernels.size() ? ctx.slot() % m_pixelEdmPrepKernels.size() : 0;
143 size_t stripEDMIndex = m_stripEdmPrepKernels.size() ? ctx.slot() % m_stripEdmPrepKernels.size() : 0;
145 const cl::CommandQueue &acc_queue =
m_acc_queues[bufferIndex];
147 ATH_MSG_INFO(
"Thread number "<<ctx.slot()<<
" running on buffer "<<bufferIndex<<
" pixelClusterIndex: "<< pixelClusterIndex<<
" stripClusterIndex: "<< stripClusterIndex<<
" stripL2GIndex: "<< stripL2GIndex<<
" pixelL2GIndex: "<< pixelL2GIndex<<
" pixelEDMIndex: "<< pixelEDMIndex<<
" stripEDMIndex: "<< stripEDMIndex);
149 cl::Kernel &pixelClusteringKernel = m_pixelClusteringKernels[pixelClusterIndex];
150 cl::Kernel &stripClusteringKernel = m_stripClusteringKernels[stripClusterIndex];
151 cl::Kernel &stripL2GKernel = m_stripL2GKernels[stripL2GIndex];
152 cl::Kernel &pixelEdmPrepKernel = m_pixelEdmPrepKernels[pixelEDMIndex];
153 cl::Kernel &stripEdmPrepKernel = m_stripEdmPrepKernels[stripEDMIndex];
154 cl::Kernel *pixelL2GKernel =
nullptr;
156 if (!
m_doF110) pixelL2GKernel = &m_pixelL2GKernels[pixelL2GIndex];
167 uint32_t cluster_vector_size_bytes =
sizeof(
uint64_t) * (*pixelInput).size();
168 uint32_t edm_vector_size_bytes =
sizeof(
uint64_t) * (*pixelInput).size() * 8;
171 pixelClusteringKernel.setArg(3, hit_vector_size_bytes);
172 pixelClusteringKernel.setArg(4, cluster_vector_size_bytes);
173 pixelClusteringKernel.setArg(5, edm_vector_size_bytes);
179 stripClusteringKernel.setArg(3,
static_cast<unsigned int>((*stripInput).size()));
207 std::vector<cl::Event> evt_vec_pixel_input{evt_write_pixel_input};
208 std::vector<cl::Event> evt_vec_strip_input{evt_write_strip_input};
220 acc_queue.enqueueTask(pixelClusteringKernel, &evt_vec_pixel_input, &evt_pixel_clustering);
221 acc_queue.enqueueTask(stripClusteringKernel, &evt_vec_strip_input, &evt_strip_clustering);
223 std::vector<cl::Event> evt_vec_strip_clustering{evt_strip_clustering};
226 std::vector<cl::Event> evt_vec_pixel_clustering{evt_pixel_clustering};
227 acc_queue.enqueueTask(*pixelL2GKernel, &evt_vec_pixel_clustering, &evt_pixel_l2g);
229 acc_queue.enqueueTask(stripL2GKernel, &evt_vec_strip_clustering, &evt_strip_l2g);
231 std::vector<cl::Event> evt_vec_pixelEDM;
232 if(
m_doF110) evt_vec_pixelEDM.push_back(evt_pixel_clustering);
233 else evt_vec_pixelEDM.push_back(evt_pixel_l2g);
234 std::vector<cl::Event> evt_vec_strip_l2g{evt_strip_l2g};
235 acc_queue.enqueueTask(pixelEdmPrepKernel, &evt_vec_pixelEDM, &evt_pixel_edm_prep);
236 acc_queue.enqueueTask(stripEdmPrepKernel, &evt_vec_strip_l2g, &evt_strip_edm_prep);
243 std::vector<cl::Event> evt_vec_pixel_edm_prep;
244 std::vector<cl::Event> evt_vec_strip_edm_prep;
246 evt_vec_pixel_edm_prep.push_back(evt_pixel_edm_prep);
247 evt_vec_strip_edm_prep.push_back(evt_strip_edm_prep);
258 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);
259 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);
261 std::vector<cl::Event> wait_for_reads = { evt_pixel_cluster_output, evt_strip_cluster_output };
262 cl::Event::waitForEvents(wait_for_reads);
265 if(pixelInput->size() == 6) (*FPGAPixelOutput)[0] = 0;
266 if(stripInput->size() == 6) (*FPGAStripOutput)[0] = 0;
271 cl_ulong pixel_input_time = evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
273 ATH_MSG_DEBUG(
"Pixel input buffer write time: " << pixel_input_time / 1e6 <<
" ms");
276 cl_ulong strip_input_time = evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
278 ATH_MSG_DEBUG(
"Strip input buffer write time: " << strip_input_time / 1e6 <<
" ms");
281 cl_ulong pixel_clustering_time = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
283 ATH_MSG_DEBUG(
"Pixel clustering time: " << pixel_clustering_time / 1e6 <<
" ms");
286 cl_ulong strip_clustering_time = evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
288 ATH_MSG_DEBUG(
"Strip clustering time: " << strip_clustering_time / 1e6 <<
" ms");
292 cl_ulong pixel_l2g_time = evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
294 ATH_MSG_DEBUG(
"Pixel L2G time: " << pixel_l2g_time / 1e6 <<
" ms");
298 cl_ulong strip_l2g_time = evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
300 ATH_MSG_DEBUG(
"Strip L2G time: " << strip_l2g_time / 1e6 <<
" ms");
304 cl_ulong pixel_edm_prep_time = evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
305 cl_ulong strip_edm_prep_time = evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
308 ATH_MSG_DEBUG(
"PixelEDMPrep time: " << pixel_edm_prep_time / 1e6 <<
" ms");
311 ATH_MSG_DEBUG(
"StripEDMPrep time: " << strip_edm_prep_time / 1e6 <<
" ms");
314 cl_ulong edm_prep_time = evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
317 ATH_MSG_DEBUG(
"EDMPrep time: " << edm_prep_time / 1e6 <<
" ms");
321 cl_ulong kernel_start = evt_pixel_clustering.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
323 std::max(evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>(), evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>()) :
324 evt_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>();
326 ATH_MSG_DEBUG(
"Kernel execution time: " << (kernel_end - kernel_start) / 1e6 <<
" ms");
329 cl_ulong pixel_output_time = evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
331 ATH_MSG_DEBUG(
"Pixel output buffer read time: " << pixel_output_time / 1e6 <<
" ms");
334 cl_ulong strip_output_time = evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
336 ATH_MSG_DEBUG(
"Strip output buffer read time: " << strip_output_time / 1e6 <<
" ms");
338 return StatusCode::SUCCESS;
367 return StatusCode::SUCCESS;
375 ATH_MSG_INFO(
"fpga name: "<<xrt_xclbin.get_fpga_device_name());
376 ATH_MSG_INFO(
"uuid: "<<xrt_xclbin.get_uuid().to_string());
378 for (
const xrt::xclbin::kernel &kernel : xrt_xclbin.get_kernels()) {
379 const std::string& kernelName = kernel.get_name();
385 const std::string& computeUnitName = computeUnit.get_name();
386 const std::string computeUnitIsolatedName = computeUnitName.substr(kernelName.size() + 1);
388 const std::string computeUnitUsableName = kernelName +
":{" + computeUnitIsolatedName +
"}";
391 cuNames.push_back(computeUnitUsableName);