ATLAS Offline Software
PixelClustering.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "PixelClustering.h"
12 #include <fstream>
13 #include <CL/cl_ext.h>
14 
16 {
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode PixelClustering::execute(const EventContext &ctx) const
25 {
26  ATH_MSG_DEBUG("In execute(), event slot: " << ctx.slot());
27 
28  // Make a TVHolder object
29  EFTrackingFPGAIntegration::TVHolder pixelTV("PixelClustering");
30 
31  ATH_CHECK(m_testVectorTool->prepareTV(m_inputTV, pixelTV.inputTV));
32  ATH_CHECK(m_testVectorTool->prepareTV(m_refTV, pixelTV.refTV));
33 
34  // print the first 10 elements of the input vector
35  for (int i = 0; i < 10; i++)
36  {
37  ATH_MSG_DEBUG("inputTV[" << std::dec << i << "] = " << std::hex << pixelTV.inputTV[i]);
38  }
39 
40  // Prepare output vector
41  // keep it the same size as the input vector for current development
42  std::vector<uint64_t> outputTV(pixelTV.inputTV.size(), 0);
43 
44  // Work with the accelerator
45  cl_int err = 0;
46 
47  // Allocate buffers on accelerator
48  cl::Buffer acc_inbuff(m_context, CL_MEM_READ_ONLY, sizeof(uint64_t) * pixelTV.inputTV.size(), NULL, &err);
49  cl::Buffer acc_outbuff(m_context, CL_MEM_READ_WRITE, sizeof(uint64_t) * outputTV.size(), NULL, &err);
50 
51  // Prepare kernel
52  cl::Kernel acc_kernel(m_program, m_kernelName.value().data(), &err);
53  acc_kernel.setArg<uint>(0, 0);
54  acc_kernel.setArg<cl::Buffer>(1, acc_inbuff);
55  acc_kernel.setArg<cl::Buffer>(2, acc_outbuff);
56 
57  // Make queue of commands
58  cl::CommandQueue acc_queue(m_context, m_accelerator);
59 
60  acc_queue.enqueueWriteBuffer(acc_inbuff, CL_TRUE, 0, sizeof(uint64_t) * pixelTV.inputTV.size(), pixelTV.inputTV.data(), NULL, NULL);
61 
62  err = acc_queue.enqueueTask(acc_kernel);
63 
64  acc_queue.finish();
65 
66  // The current implementation of the kernel Read/Write the same buffer
67  // So the line below reads the inbuff insatead of outbuff
68  acc_queue.enqueueReadBuffer(acc_inbuff, CL_TRUE, 0, sizeof(uint64_t) * outputTV.size(), outputTV.data(), NULL, NULL);
69 
70  // Quick validation
71  // Print the fist 10 elements of output vector
72  for (int i = 0; i < 10; i++)
73  {
74  ATH_MSG_DEBUG("outputTV[" << std::dec << i << "] = " << std::hex << outputTV[i]);
75  }
76 
77  // Compare the output vector with the reference vector
78  ATH_CHECK(m_testVectorTool->compare(pixelTV, outputTV));
79 
80  return StatusCode::SUCCESS;
81 }
EFTrackingFPGAIntegration::TVHolder::refTV
std::vector< uint64_t > refTV
Definition: TestVectorTool.h:32
IntegrationBase::m_accelerator
cl::Device m_accelerator
Device object for the accelerator card.
Definition: IntegrationBase.h:66
IntegrationBase::initialize
virtual StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
Definition: IntegrationBase.cxx:14
PixelClustering::execute
StatusCode execute(const EventContext &ctx) const override
Should be overriden by derived classes to perform meaningful work.
Definition: PixelClustering.cxx:24
IntegrationBase::m_context
cl::Context m_context
Context object for the application.
Definition: IntegrationBase.h:67
PixelClustering::m_refTV
Gaudi::Property< std::string > m_refTV
Reference TestVector.
Definition: PixelClustering.h:33
PixelClustering.h
Class for the pixel clustering kernel.
PixelClustering::initialize
StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
Definition: PixelClustering.cxx:15
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
PixelClustering::m_xclbin
Gaudi::Property< std::string > m_xclbin
Path and name of the xclbin file.
Definition: PixelClustering.h:30
PixelClustering::m_kernelName
Gaudi::Property< std::string > m_kernelName
Kernel name.
Definition: PixelClustering.h:31
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PixelClustering::m_inputTV
Gaudi::Property< std::string > m_inputTV
Input TestVector.
Definition: PixelClustering.h:32
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EFTrackingFPGAIntegration::TVHolder
Definition: TestVectorTool.h:27
IntegrationBase::loadProgram
StatusCode loadProgram(const std::string &xclbin)
Find the xclbin file and load it into the OpenCL program object.
Definition: IntegrationBase.cxx:82
IntegrationBase::precheck
StatusCode precheck(std::vector< Gaudi::Property< std::string >> inputs) const
Check if the the desired Gaudi properties are set.
Definition: IntegrationBase.cxx:121
PixelClustering::m_testVectorTool
ToolHandle< TestVectorTool > m_testVectorTool
Tool handle for TestVectorTool.
Definition: PixelClustering.h:35
IntegrationBase::m_program
cl::Program m_program
Program object containing the kernel.
Definition: IntegrationBase.h:68
EFTrackingFPGAIntegration::TVHolder::inputTV
std::vector< uint64_t > inputTV
Definition: TestVectorTool.h:31