ATLAS Offline Software
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 
11 #include "Spacepoints.h"
12 #include <fstream>
13 
15 {
19 
20  return StatusCode::SUCCESS;
21 }
22 
24 {
25  ATH_MSG_DEBUG("In execute()");
26 
27  int MAX_DATA_SIZE = 46219;
28 
29  // Read in the testvector
30  std::ifstream ifs;
31  ATH_MSG_DEBUG("Reading in TV");
32 
33  // Open the testvector to ifstream and check if it is open
34  ifs.open(m_inputTV, std::ios::binary);
35  if (!ifs.is_open())
36  {
37  ATH_MSG_ERROR("Error reading testvector file");
38  return StatusCode::FAILURE;
39  }
40 
41  // make new vector of uint64_t
42  std::vector<uint64_t> inputTV;
43  // a new buffer to read in the file
44  uint64_t temp = 0;
45  // read in the file 8 bytes at a time and store it in the vector of uint64_t
46  while (ifs.good())
47  {
48  ifs.read(reinterpret_cast<char *>(&temp), sizeof(temp));
49  if (ifs.good())
50  {
51  // Reverse the byte order
52  temp = __builtin_bswap64(temp);
53  inputTV.push_back(temp);
54  }
55  }
56 
57  // Close the file
58  ifs.close();
59 
60  // Work with the accelerator
61  cl_int err = 0;
62 
63  // Allocate buffers on acc. card
64  cl::Buffer acc_inbuff(m_context, CL_MEM_READ_ONLY, inputTV.size() * sizeof(uint64_t), NULL, &err);
65  cl::Buffer acc_outbuff(m_context, CL_MEM_READ_WRITE, inputTV.size() * sizeof(uint64_t), NULL, &err);
66 
67  // Make queue of commands
68  cl::CommandQueue acc_queue(m_context, m_accelerator);
69 
70  acc_queue.enqueueWriteBuffer(acc_inbuff, CL_TRUE, 0, inputTV.size() * sizeof(uint64_t), inputTV.data(), NULL, NULL);
71 
72  // // Prepare kernel
73  cl::Kernel acc_kernel(m_program, m_kernelName.value().data(), &err);
74  acc_kernel.setArg(0, acc_inbuff);
75  acc_kernel.setArg(1, acc_outbuff);
76  acc_kernel.setArg<int>(2, inputTV.size());
77 
78  // // Enqueue task
79  acc_queue.enqueueTask(acc_kernel);
80 
81  std::vector<uint64_t> output(MAX_DATA_SIZE);
82  acc_queue.enqueueReadBuffer(acc_outbuff, CL_TRUE, 0, inputTV.size() * sizeof(uint64_t), output.data(), NULL, NULL);
83 
84  acc_queue.finish();
85 
86  return StatusCode::SUCCESS;
87 }
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
IntegrationBase::m_context
cl::Context m_context
Context object for the application.
Definition: IntegrationBase.h:67
Spacepoints.h
Class for the spacepoints kernel.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
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
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Spacepoints::m_kernelName
Gaudi::Property< std::string > m_kernelName
Kernel name.
Definition: Spacepoints.h:30
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
merge.output
output
Definition: merge.py:17
Spacepoints::execute
StatusCode execute() override
Should be overriden by derived classes to perform meaningful work.
Definition: Spacepoints.cxx:23
Spacepoints::m_refTV
Gaudi::Property< std::string > m_refTV
Reference TestVector.
Definition: Spacepoints.h:32
Spacepoints::m_xclbin
Gaudi::Property< std::string > m_xclbin
Path and name of the xclbin file.
Definition: Spacepoints.h:29
Spacepoints::initialize
StatusCode initialize() override
Detect the OpenCL devices and prepare OpenCL context.
Definition: Spacepoints.cxx:14
IntegrationBase::m_program
cl::Program m_program
Program object containing the kernel.
Definition: IntegrationBase.h:68
Spacepoints::m_inputTV
Gaudi::Property< std::string > m_inputTV
Input TestVector.
Definition: Spacepoints.h:31