ATLAS Offline Software
Loading...
Searching...
No Matches
Spacepoints.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
10
12#include <fstream>
13
22
23StatusCode Spacepoints::execute(const EventContext &ctx) const
24{
25 ATH_MSG_DEBUG("In execute(), event slot: "<<ctx.slot());
26
27 int MAX_DATA_SIZE = 46219;
28
29 // Prepare input test vector
30 EFTrackingFPGAIntegration::TVHolder spacePointsTV("Spacepoints");
31 ATH_CHECK(m_testVectorTool->prepareTV(m_inputTV, spacePointsTV.inputTV));
32 ATH_CHECK(m_testVectorTool->prepareTV(m_refTV, spacePointsTV.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 << spacePointsTV.inputTV[i]<<std::dec);
38 }
39
40 // Work with the accelerator
41 cl_int err = 0;
42
43 // Allocate buffers on acc. card
44 cl::Buffer acc_inbuff(m_context, CL_MEM_READ_ONLY, spacePointsTV.inputTV.size() * sizeof(uint64_t), NULL, &err);
45 cl::Buffer acc_outbuff(m_context, CL_MEM_READ_WRITE, spacePointsTV.inputTV.size() * sizeof(uint64_t), NULL, &err);
46
47 // Prepare kernel
48 // Connect kernel to buffer before command queue
49 cl::Kernel acc_kernel(m_program, m_kernelName.value().data(), &err);
50 acc_kernel.setArg(0, acc_inbuff);
51 acc_kernel.setArg(1, acc_outbuff);
52 acc_kernel.setArg<int>(2, spacePointsTV.inputTV.size());
53
54 // Make queue of commands
55 cl::CommandQueue acc_queue(m_context, m_accelerator);
56
57 acc_queue.enqueueWriteBuffer(acc_inbuff, CL_TRUE, 0, spacePointsTV.inputTV.size() * sizeof(uint64_t), spacePointsTV.inputTV.data(), NULL, NULL);
58
59 // // Enqueue task
60 acc_queue.enqueueTask(acc_kernel);
61
62 acc_queue.finish();
63
64 std::vector<uint64_t> output(spacePointsTV.inputTV.size(), 0);
65
66 acc_queue.enqueueReadBuffer(acc_outbuff, CL_TRUE, 0, spacePointsTV.inputTV.size() * sizeof(uint64_t), output.data(), NULL, NULL);
67
68 // Compare the output with the reference
69 ATH_CHECK(m_testVectorTool->compare(spacePointsTV.refTV, output));
70
71 return StatusCode::SUCCESS;
72}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
StatusCode loadProgram(const std::string &xclbin)
Find the xclbin file and load it into the OpenCL program object.
cl::Program m_program
Program object containing the kernel.
virtual StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
cl::Context m_context
Context object for the application.
StatusCode precheck(const std::vector< Gaudi::Property< std::string > > &inputs) const
Check if the the desired Gaudi properties are set.
cl::Device m_accelerator
Device object for the accelerator card.
Gaudi::Property< std::string > m_kernelName
Kernel name.
Definition Spacepoints.h:31
Gaudi::Property< std::string > m_inputTV
Input TestVector.
Definition Spacepoints.h:32
ToolHandle< TestVectorTool > m_testVectorTool
Tool handle for TestVectorTool.
Definition Spacepoints.h:35
StatusCode execute(const EventContext &ctx) const override
Should be overriden by derived classes to perform meaningful work.
Gaudi::Property< std::string > m_xclbin
Path and name of the xclbin file.
Definition Spacepoints.h:30
StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
Gaudi::Property< std::string > m_refTV
Reference TestVector.
Definition Spacepoints.h:33
std::vector< uint64_t > inputTV