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++)
80 for (
const auto& cuName: listofCUs)
92 else if(cuName.find(
m_pixelL2GKernelName.value()) != std::string::npos) m_pixelL2GKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
95 else if(cuName.find(
m_stripL2GKernelName.value()) != std::string::npos) m_stripL2GKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
98 else if(cuName.find(
m_pixelEdmKernelName.value()) != std::string::npos) m_pixelEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
100 else if(cuName.find(
m_stripEdmKernelName.value()) != std::string::npos) m_stripEdmPrepKernels.emplace_back(cl::Kernel(
m_program, cuName.c_str()));
117 return StatusCode::SUCCESS;
126 const std::vector<uint64_t>* pixelInput{
nullptr}, *stripInput{
nullptr};
138 size_t bufferIndex = ctx.slot() % nthreads;
141 size_t pixelStartClusterIndex = ctx.slot() % m_pixelStartClusteringKernels.size();
142 size_t pixelEndClusterIndex = ctx.slot() % m_pixelEndClusteringClusterKernels.size();
143 size_t pixelEndClusterEDMIndex = ctx.slot() % m_pixelEndClusteringEDMKernels.size();
144 size_t stripStartClusterIndex = ctx.slot() % m_stripStartClusteringKernels.size();
145 size_t stripEndClusterIndex = ctx.slot() % m_stripEndClusteringKernels.size();
146 size_t pixelL2GIndex = m_pixelL2GKernels.size() ? ctx.slot() % m_pixelL2GKernels.size() : 0;
147 size_t stripL2GIndex = ctx.slot() % m_stripL2GKernels.size();
148 size_t pixelEDMIndex = m_pixelEdmPrepKernels.size() ? ctx.slot() % m_pixelEdmPrepKernels.size() : 0;
149 size_t stripEDMIndex = m_stripEdmPrepKernels.size() ? ctx.slot() % m_stripEdmPrepKernels.size() : 0;
151 const cl::CommandQueue &acc_queue =
m_acc_queues[bufferIndex];
153 ATH_MSG_INFO(
"Thread number "<<ctx.slot()<<
" running on buffer "<<bufferIndex<<
" pixelStartClusterIndex: "<< pixelStartClusterIndex<<
" stripStartClusterIndex: "<< stripStartClusterIndex<<
" stripEndClusterIndex: "<< stripEndClusterIndex<<
" stripL2GIndex: "<< stripL2GIndex<<
" pixelEDMIndex: "<< pixelEDMIndex<<
" stripEDMIndex: "<< stripEDMIndex);
155 cl::Kernel &pixelStartClusteringKernel = m_pixelStartClusteringKernels[pixelStartClusterIndex];
156 cl::Kernel &pixelEndClusteringClusterKernel = m_pixelEndClusteringClusterKernels[pixelEndClusterIndex];
157 cl::Kernel &pixelEndClusteringEDMKernel = m_pixelEndClusteringEDMKernels[pixelEndClusterEDMIndex];
158 cl::Kernel &stripStartClusteringKernel = m_stripStartClusteringKernels[stripStartClusterIndex];
159 cl::Kernel &stripEndClusteringKernel = m_stripEndClusteringKernels[stripEndClusterIndex];
160 cl::Kernel &stripL2GKernel = m_stripL2GKernels[stripL2GIndex];
161 cl::Kernel &pixelL2GKernel = m_pixelL2GKernels[pixelL2GIndex];
163 cl::Kernel &pixelEdmPrepKernel = m_pixelEdmPrepKernels[pixelEDMIndex];
164 cl::Kernel &stripEdmPrepKernel = m_stripEdmPrepKernels[stripEDMIndex];
169 pixelStartClusteringKernel.setArg(2,
static_cast<unsigned long long>((*pixelInput).size()));
175 stripStartClusteringKernel.setArg(2,
static_cast<unsigned long long>((*stripInput).size()));
203 std::vector<cl::Event> evt_vec_pixel_input{evt_write_pixel_input};
204 std::vector<cl::Event> evt_vec_strip_input{evt_write_strip_input};
208 cl::Event evt_pixel_end_clustering_cluster;
219 acc_queue.enqueueTask(pixelStartClusteringKernel, &evt_vec_pixel_input, &evt_pixel_start_clustering);
220 acc_queue.enqueueTask(pixelEndClusteringClusterKernel, NULL , &evt_pixel_end_clustering_cluster);
221 acc_queue.enqueueTask(pixelEndClusteringEDMKernel, NULL , &evt_pixel_end_clustering_edm);
222 acc_queue.enqueueTask(stripStartClusteringKernel, &evt_vec_strip_input, &evt_strip_start_clustering);
223 acc_queue.enqueueTask(stripEndClusteringKernel, NULL, &evt_strip_end_clustering);
225 std::vector<cl::Event> evt_vec_pixel_clustering{
226 evt_pixel_end_clustering_cluster,
227 evt_pixel_end_clustering_edm,
230 acc_queue.enqueueTask(pixelL2GKernel, &evt_vec_pixel_clustering, &evt_pixel_l2g);
232 std::vector<cl::Event> evt_vec_strip_clustering{evt_strip_end_clustering};
233 acc_queue.enqueueTask(stripL2GKernel, &evt_vec_strip_clustering, &evt_strip_l2g);
235 std::vector<cl::Event> evt_vec_pixel_l2g{evt_pixel_l2g};
236 acc_queue.enqueueTask(pixelEdmPrepKernel, &evt_vec_pixel_l2g, &evt_pixel_edm_prep);
238 std::vector<cl::Event> evt_vec_strip_l2g{evt_strip_l2g};
239 acc_queue.enqueueTask(stripEdmPrepKernel, &evt_vec_strip_l2g, &evt_strip_edm_prep);
246 std::vector<cl::Event> evt_vec_pixel_edm_prep;
247 std::vector<cl::Event> evt_vec_strip_edm_prep;
249 evt_vec_pixel_edm_prep.push_back(evt_pixel_edm_prep);
250 evt_vec_strip_edm_prep.push_back(evt_strip_edm_prep);
261 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);
262 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);
264 std::vector<cl::Event> wait_for_reads = { evt_pixel_cluster_output, evt_strip_cluster_output };
265 cl::Event::waitForEvents(wait_for_reads);
268 if(pixelInput->size() == 6) (*FPGAPixelOutput)[0] = 0;
269 if(stripInput->size() == 6) (*FPGAStripOutput)[0] = 0;
274 cl_ulong pixel_input_time = evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_pixel_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
276 ATH_MSG_DEBUG(
"Pixel input buffer write time: " << pixel_input_time / 1e6 <<
" ms");
279 cl_ulong strip_input_time = evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_write_strip_input.getProfilingInfo<CL_PROFILING_COMMAND_START>();
281 ATH_MSG_DEBUG(
"Strip input buffer write time: " << strip_input_time / 1e6 <<
" ms");
284 cl_ulong pixel_clustering_cluster_time = evt_pixel_end_clustering_cluster.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_start_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
286 ATH_MSG_DEBUG(
"Pixel clustering_cluster time: " << pixel_clustering_cluster_time / 1e6 <<
" ms");
288 cl_ulong pixel_clustering_edm_time = evt_pixel_end_clustering_edm.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_start_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
290 ATH_MSG_DEBUG(
"Pixel clustering_edm time: " << pixel_clustering_edm_time / 1e6 <<
" ms");
293 cl_ulong strip_clustering_time = evt_strip_end_clustering.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_start_clustering.getProfilingInfo<CL_PROFILING_COMMAND_START>();
295 ATH_MSG_DEBUG(
"Strip clustering time: " << strip_clustering_time / 1e6 <<
" ms");
298 cl_ulong pixel_l2g_time = evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
300 ATH_MSG_DEBUG(
"Pixel L2G time: " << pixel_l2g_time / 1e6 <<
" ms");
303 cl_ulong strip_l2g_time = evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_l2g.getProfilingInfo<CL_PROFILING_COMMAND_START>();
305 ATH_MSG_DEBUG(
"Strip L2G time: " << strip_l2g_time / 1e6 <<
" ms");
308 cl_ulong pixel_edm_prep_time = evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
309 cl_ulong strip_edm_prep_time = evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_START>();
312 ATH_MSG_DEBUG(
"PixelEDMPrep time: " << pixel_edm_prep_time / 1e6 <<
" ms");
315 ATH_MSG_DEBUG(
"StripEDMPrep time: " << strip_edm_prep_time / 1e6 <<
" ms");
319 cl_ulong kernel_start = evt_pixel_start_clustering.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
320 cl_ulong kernel_end =
std::max(evt_pixel_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>(), evt_strip_edm_prep.getProfilingInfo<CL_PROFILING_COMMAND_END>());
322 ATH_MSG_DEBUG(
"Kernel execution time: " << (kernel_end - kernel_start) / 1e6 <<
" ms");
325 cl_ulong pixel_output_time = evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_pixel_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
327 ATH_MSG_DEBUG(
"Pixel output buffer read time: " << pixel_output_time / 1e6 <<
" ms");
330 cl_ulong strip_output_time = evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_END>() - evt_strip_cluster_output.getProfilingInfo<CL_PROFILING_COMMAND_START>();
332 ATH_MSG_DEBUG(
"Strip output buffer read time: " << strip_output_time / 1e6 <<
" ms");
334 return StatusCode::SUCCESS;
357 return StatusCode::SUCCESS;
365 ATH_MSG_INFO(
"fpga name: "<<xrt_xclbin.get_fpga_device_name());
366 ATH_MSG_INFO(
"uuid: "<<xrt_xclbin.get_uuid().to_string());
368 for (
const xrt::xclbin::kernel &kernel : xrt_xclbin.get_kernels()) {
369 const std::string& kernelName = kernel.get_name();
375 const std::string& computeUnitName = computeUnit.get_name();
376 const std::string computeUnitIsolatedName = computeUnitName.substr(kernelName.size() + 1);
378 const std::string computeUnitUsableName = kernelName +
":{" + computeUnitIsolatedName +
"}";
381 cuNames.push_back(computeUnitUsableName);