ATLAS Offline Software
F150KernelTesterAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "AthenaKernel/Chrono.h"
9 
11 {
12  std::string F150KernelTesterAlg::get_cu_name(const std::string& kernel_name, int cu) {
13  std::string full_cu_name = kernel_name + ":{" + kernel_name + "_" + std::to_string(cu) + "}";
14  ATH_MSG_DEBUG("LOADING " + full_cu_name);
15  return full_cu_name;
16  }
17 
18  void F150KernelTesterAlg::dumpHexData(size_t dataLen, uint64_t *data, const std::string& dataDescriptor) const {
19  ATH_MSG_DEBUG("STARTING " << dataDescriptor << " words:");
20  for (size_t i = 0; i < dataLen; i++) {
21  ATH_MSG_DEBUG(std::hex << std::setw(16) << std::setfill('0') << data[i]);
22  }
23  ATH_MSG_DEBUG("ENDING " << dataDescriptor << " words");
24  }
25 
27  {
28  ATH_MSG_INFO("Running on the FPGA accelerator");
29  ATH_MSG_INFO("Testing Slicing Engine: " + m_runSE);
30  ATH_MSG_INFO("Testing Inside Out: " + m_runIO);
31  ATH_MSG_INFO("Testing Inside Out on Slicing Engine Output: " + m_runIOOnSE);
32 
33  ATH_CHECK(m_chronoSvc.retrieve());
34 
35  {
36  Athena::Chrono chrono("Platform and device initialize", m_chronoSvc.get());
38  }
39 
40  {
41  Athena::Chrono chrono("CL::loadProgram", m_chronoSvc.get());
42  ATH_MSG_INFO("Loading Program: " + m_xclbin);
44  }
45 
46  cl_int err = CL_SUCCESS;
47 
48  int cu = 1;
49 
50  if (m_runSE) {
53 
54  xrt::uuid loadedXclbinUUID = m_xrt_accelerator.get_xclbin_uuid();
56  }
57  if (m_runIO) {
58  m_insideOutInput = cl::Kernel(m_program, get_cu_name(m_insideOutInputName, cu).c_str(), &err);
59  m_insideOutOutput = cl::Kernel(m_program, get_cu_name(m_insideOutOutputName, cu).c_str(), &err);
60  }
61 
62  m_queue = cl::CommandQueue(m_context, m_accelerator, CL_QUEUE_PROFILING_ENABLE | CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
63 
64  if (err != CL_SUCCESS) {
65  return StatusCode::FAILURE;
66  }
67 
68  ATH_CHECK(m_xaodClusterMaker.retrieve());
69  ATH_CHECK(m_testVectorTool.retrieve());
70  ATH_CHECK(m_FPGADataFormatTool.retrieve());
72 
73  // Initialize track sim keys
77 
78  return StatusCode::SUCCESS;
79  }
80 
81  StatusCode F150KernelTesterAlg::execute(const EventContext &ctx) const
82  {
83  ATH_MSG_DEBUG("Executing F150KernelTesterAlg");
84 
85  cl_int err = CL_SUCCESS;
86 
87  int n_pixel_words = 4;
88  size_t pixel_size_bytes = n_pixel_words * sizeof(uint64_t);
89 
90  if (m_runSE) {
91  ATH_MSG_DEBUG("Allocating SE buffers");
92  m_slicingEngineInputBuffer = cl::Buffer(m_context, CL_MEM_READ_ONLY, pixel_size_bytes, NULL, &err);
93  m_slicingEngineOutputBuffer = cl::Buffer(m_context, CL_MEM_WRITE_ONLY, pixel_size_bytes, NULL, &err);
94 
95  ATH_MSG_DEBUG("Setting SE args");
96  // TODO: FIX ARGS
97  m_slicingEngineInput.setArg(0, m_slicingEngineInputBuffer); // Input buffer
98  m_slicingEngineInput.setArg(1, n_pixel_words); // Input words
99  m_slicingEngineOutput.setArg(0, m_slicingEngineOutputBuffer); // Output buffer
100  m_slicingEngineOutput.setArg(1, n_pixel_words); // Output words (TODO: how do we get this???)
101 
102  uint64_t out_data[n_pixel_words];
103 
104  // Write
105  ATH_MSG_DEBUG("Loading input data to SE input kernel");
106  // TODO: Replace with real data to write
107  m_queue.enqueueWriteBuffer(m_slicingEngineInputBuffer, CL_TRUE, 0, pixel_size_bytes, &out_data);
108  m_queue.finish();
109 
110  // Execute
111  ATH_MSG_DEBUG("Executing SE kernel");
113  m_queue.enqueueTask(m_slicingEngineInput);
114  m_queue.enqueueTask(m_slicingEngineOutput);
115  m_queue.finish();
116 
117  // Read
118  ATH_MSG_DEBUG("Reading output data from kernel");
119  m_queue.enqueueReadBuffer(m_slicingEngineOutputBuffer, CL_TRUE, 0, pixel_size_bytes, &out_data);
120  m_queue.finish();
121 
122  dumpHexData(n_pixel_words, out_data, "Real Slicing Engine Output");
123  }
124  if (m_runIO) {
125  ATH_MSG_DEBUG("Allocating IO buffers");
126  if (!m_runIOOnSE) {
127  m_insideOutInputBuffer = cl::Buffer(m_context, CL_MEM_READ_ONLY, pixel_size_bytes, NULL, &err);
128  }
129  m_insideOutOutputBuffer = cl::Buffer(m_context, CL_MEM_WRITE_ONLY, pixel_size_bytes, NULL, &err);
130 
131  ATH_MSG_DEBUG("Setting IO args");
132  // TODO: FIX ARGS
135 
136  uint64_t out_data[n_pixel_words];
137 
138  if (!m_runIOOnSE) {
139  // Write
140  ATH_MSG_DEBUG("Loading input data to IO input kernel");
141  // TODO: Replace with real data to write
142  m_queue.enqueueWriteBuffer(m_insideOutInputBuffer, CL_TRUE, 0, pixel_size_bytes, &out_data);
143  m_queue.finish();
144  }
145 
146  // Execute
147  ATH_MSG_DEBUG("Executing IO kernel");
148  m_queue.enqueueTask(m_insideOutInput);
149  m_queue.enqueueTask(m_insideOutOutput);
150  m_queue.finish();
151 
152  // Read
153  ATH_MSG_DEBUG("Reading output data from kernel");
154  m_queue.enqueueReadBuffer(m_slicingEngineOutputBuffer, CL_TRUE, 0, pixel_size_bytes, &out_data);
155  m_queue.finish();
156 
157  dumpHexData(n_pixel_words, out_data, "Real Inside Out Output");
158  }
159 
160 
161  return StatusCode::SUCCESS;
162  }
163 
165  {
166  ATH_MSG_INFO("Average Kernel execution time: " << m_sum_kernelTime /m_num_Events /1e6 << " ms");
167  return StatusCode::SUCCESS;
168  }
169 }
EFTrackingFPGAIntegration::F150KernelTesterAlg::get_cu_name
std::string get_cu_name(const std::string &kernel_name, int cu)
Definition: F150KernelTesterAlg.cxx:12
IntegrationBase::m_accelerator
cl::Device m_accelerator
Device object for the accelerator card.
Definition: IntegrationBase.h:66
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
IntegrationBase::initialize
virtual StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
Definition: IntegrationBase.cxx:16
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineInputName
Gaudi::Property< std::string > m_slicingEngineInputName
Definition: F150KernelTesterAlg.h:78
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_FPGADataFormatTool
ToolHandle< FPGADataFormatTool > m_FPGADataFormatTool
Tool for formatting FPGA data.
Definition: F150KernelTesterAlg.h:61
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutOutput
cl::Kernel m_insideOutOutput
Definition: F150KernelTesterAlg.h:100
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineName
Gaudi::Property< std::string > m_slicingEngineName
Definition: F150KernelTesterAlg.h:79
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_chronoSvc
ServiceHandle< IChronoSvc > m_chronoSvc
Service for timing the algorithm.
Definition: F150KernelTesterAlg.h:49
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineOutputName
Gaudi::Property< std::string > m_slicingEngineOutputName
Definition: F150KernelTesterAlg.h:80
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_outputConversionTool
ToolHandle< OutputConversionTool > m_outputConversionTool
Definition: F150KernelTesterAlg.h:75
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutInputName
Gaudi::Property< std::string > m_insideOutInputName
Definition: F150KernelTesterAlg.h:81
IntegrationBase::m_context
cl::Context m_context
Context object for the application.
Definition: IntegrationBase.h:67
EFTrackingFPGAIntegration::F150KernelTesterAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Should be overriden by derived classes to perform meaningful work.
Definition: F150KernelTesterAlg.cxx:81
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_num_Events
std::atomic< ulonglong > m_num_Events
Number of events for the average time of the kernel execution.
Definition: F150KernelTesterAlg.h:86
F150KernelTesterAlg.h
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_queue
cl::CommandQueue m_queue
Definition: F150KernelTesterAlg.h:110
Chrono.h
Exception-safe IChronoSvc caller.
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_runIOOnSE
Gaudi::Property< bool > m_runIOOnSE
Whether to run inside out on the output of slicing engine.
Definition: F150KernelTesterAlg.h:68
EFTrackingFPGAIntegration::F150KernelTesterAlg::dumpHexData
void dumpHexData(size_t dataLen, uint64_t *data, const std::string &dataDescriptor) const
Definition: F150KernelTesterAlg.cxx:18
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_sum_kernelTime
std::atomic< cl_ulong > m_sum_kernelTime
Sum for the average time of the kernel execution.
Definition: F150KernelTesterAlg.h:85
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutInput
cl::Kernel m_insideOutInput
Definition: F150KernelTesterAlg.h:99
DataPreparationPipeline.h
Athena::Chrono
Exception-safe IChronoSvc caller.
Definition: Chrono.h:50
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:183
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineInput
cl::Kernel m_slicingEngineInput
Definition: F150KernelTesterAlg.h:97
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_xaodClusterMaker
ToolHandle< xAODClusterMaker > m_xaodClusterMaker
Tool for creating xAOD containers.
Definition: F150KernelTesterAlg.h:52
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
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineOutputBuffer
cl::Buffer m_slicingEngineOutputBuffer
Definition: F150KernelTesterAlg.h:105
EFTrackingFPGAIntegration::F150KernelTesterAlg::initialize
virtual StatusCode initialize() override final
Detect the OpenCL devices and prepare OpenCL context.
Definition: F150KernelTesterAlg.cxx:26
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EVENT_COUNT_RST
#define EVENT_COUNT_RST
Definition: F150KernelTesterAlg.h:34
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_xrt_accelerator
xrt::device m_xrt_accelerator
Definition: F150KernelTesterAlg.h:88
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
EFTrackingFPGAIntegration
The class for enconding RDO to FPGA format.
Definition: BenchmarkAlg.h:28
IntegrationBase::loadProgram
StatusCode loadProgram(const std::string &xclbin)
Find the xclbin file and load it into the OpenCL program object.
Definition: IntegrationBase.cxx:115
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_runIO
Gaudi::Property< bool > m_runIO
Whether to run inside out or not.
Definition: F150KernelTesterAlg.h:67
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_testVectorTool
ToolHandle< TestVectorTool > m_testVectorTool
Tool for preparing test vectors.
Definition: F150KernelTesterAlg.h:58
EFTrackingTransient.h
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineOutput
cl::Kernel m_slicingEngineOutput
Definition: F150KernelTesterAlg.h:98
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_xclbin
Gaudi::Property< std::string > m_xclbin
Path and name of the xclbin file.
Definition: F150KernelTesterAlg.h:64
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineIP
xrt::ip m_slicingEngineIP
Definition: F150KernelTesterAlg.h:96
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_runSE
Gaudi::Property< bool > m_runSE
Whether to run SE or not.
Definition: F150KernelTesterAlg.h:66
USER_CTRL_OFFSET
#define USER_CTRL_OFFSET
Definition: F150KernelTesterAlg.h:35
EFTrackingFPGAIntegration::F150KernelTesterAlg::finalize
virtual StatusCode finalize() override final
Definition: F150KernelTesterAlg.cxx:164
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutOutputName
Gaudi::Property< std::string > m_insideOutOutputName
Definition: F150KernelTesterAlg.h:82
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutInputBuffer
cl::Buffer m_insideOutInputBuffer
Definition: F150KernelTesterAlg.h:106
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_slicingEngineInputBuffer
cl::Buffer m_slicingEngineInputBuffer
Definition: F150KernelTesterAlg.h:104
IntegrationBase::m_program
cl::Program m_program
Program object containing the kernel.
Definition: IntegrationBase.h:68
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_insideOutOutputBuffer
cl::Buffer m_insideOutOutputBuffer
Definition: F150KernelTesterAlg.h:107
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_FPGASlicedHitKey
SG::ReadHandleKey< FPGATrackSimHitCollection > m_FPGASlicedHitKey
Definition: F150KernelTesterAlg.h:71
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_FPGATrackKey
SG::ReadHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
Definition: F150KernelTesterAlg.h:72
EFTrackingFPGAIntegration::F150KernelTesterAlg::m_FPGAHitKey
SG::ReadHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Definition: F150KernelTesterAlg.h:70