ATLAS Offline Software
VectorAddOCLExampleAlg.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 //
4 #ifndef ATHEXXRT_VECTORADDOCLEXAMPLEALG_H
5 #define ATHEXXRT_VECTORADDOCLEXAMPLEALG_H
6 
7 // STL include(s).
8 #include <memory>
9 
10 // AthXRT include(s).
12 
13 // Framework include(s).
16 #include "GaudiKernel/ServiceHandle.h"
17 
18 namespace AthExXRT {
19 
29 
30  public:
31  // Inherit the base class's constructor(s).
33 
35  virtual StatusCode initialize() override;
36 
38  virtual StatusCode execute(const EventContext& ctx) const override;
39 
41  virtual StatusCode finalize() override;
42 
43  private:
46  this, "DeviceMgmtSvc", "AthXRT::DeviceMgmtSvc",
47  "The XRT device manager service to use"};
48 
49  // Kernel name string
50  static constexpr char s_krnl_name[] = "krnl_VectorAdd";
51 
52  // Kernel arguments indexes
53  // Must match the kernel arguments order.
54  static constexpr int s_krnl_param_in1 = 0;
55  static constexpr int s_krnl_param_in2 = 1;
56  static constexpr int s_krnl_param_out = 2;
57  static constexpr int s_krnl_param_size = 3;
58 
59  // Number of uint32_t element in the vectors
60  static constexpr int s_element_count = 4096;
61 
63  struct SlotData {
65  std::shared_ptr<cl::Context> m_context = nullptr;
66 
68  std::shared_ptr<cl::Program> m_program = nullptr;
69 
71  std::unique_ptr<cl::Kernel> m_kernel = nullptr;
72 
74  std::unique_ptr<cl::CommandQueue> m_queue = nullptr;
75 
77  std::unique_ptr<cl::Buffer> m_dev_buf_in1 = nullptr;
78  std::unique_ptr<cl::Buffer> m_dev_buf_in2 = nullptr;
79  std::unique_ptr<cl::Buffer> m_dev_buf_out = nullptr;
80 
84  };
85 
88 
89 }; // class VectorAddOCLExampleAlg
90 
91 } // namespace AthExXRT
92 
93 #endif // ATHEXXRT_VECTORADDOCLEXAMPLEALG_H
AthExXRT::VectorAddOCLExampleAlg::s_krnl_param_out
static constexpr int s_krnl_param_out
Definition: VectorAddOCLExampleAlg.h:56
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_host_buf_out
uint32_t * m_host_buf_out
Definition: VectorAddOCLExampleAlg.h:83
AthExXRT::VectorAddOCLExampleAlg::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: VectorAddOCLExampleAlg.cxx:13
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_dev_buf_out
std::unique_ptr< cl::Buffer > m_dev_buf_out
Definition: VectorAddOCLExampleAlg.h:79
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AthExXRT::VectorAddOCLExampleAlg::m_slots
SG::SlotSpecificObj< SlotData > m_slots
List of slot-specific data.
Definition: VectorAddOCLExampleAlg.h:87
AthExXRT
Definition: VectorAddOCLExampleAlg.cxx:11
AthExXRT::VectorAddOCLExampleAlg::s_krnl_name
static constexpr char s_krnl_name[]
Definition: VectorAddOCLExampleAlg.h:50
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_queue
std::unique_ptr< cl::CommandQueue > m_queue
Kernel run object.
Definition: VectorAddOCLExampleAlg.h:74
AthExXRT::VectorAddOCLExampleAlg::s_krnl_param_in1
static constexpr int s_krnl_param_in1
Definition: VectorAddOCLExampleAlg.h:54
AthExXRT::VectorAddOCLExampleAlg::m_DeviceMgmtSvc
ServiceHandle< AthXRT::IDeviceMgmtSvc > m_DeviceMgmtSvc
The XRT device manager to use.
Definition: VectorAddOCLExampleAlg.h:45
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
AthExXRT::VectorAddOCLExampleAlg::SlotData
Slot-specific state.
Definition: VectorAddOCLExampleAlg.h:63
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_dev_buf_in1
std::unique_ptr< cl::Buffer > m_dev_buf_in1
Buffer objects.
Definition: VectorAddOCLExampleAlg.h:77
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_host_buf_in1
uint32_t * m_host_buf_in1
Definition: VectorAddOCLExampleAlg.h:81
SG::SlotSpecificObj
Maintain a set of objects, one per slot.
Definition: AthenaKernel/AthenaKernel/SlotSpecificObj.h:70
AthExXRT::VectorAddOCLExampleAlg::finalize
virtual StatusCode finalize() override
Function finalising the algorithm.
Definition: VectorAddOCLExampleAlg.cxx:163
AthReentrantAlgorithm::AthReentrantAlgorithm
AthReentrantAlgorithm()
Default constructor:
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_context
std::shared_ptr< cl::Context > m_context
OpenCL context pointer.
Definition: VectorAddOCLExampleAlg.h:65
AthExXRT::VectorAddOCLExampleAlg::s_krnl_param_size
static constexpr int s_krnl_param_size
Definition: VectorAddOCLExampleAlg.h:57
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_kernel
std::unique_ptr< cl::Kernel > m_kernel
Kernel object.
Definition: VectorAddOCLExampleAlg.h:71
IDeviceMgmtSvc.h
AthReentrantAlgorithm.h
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_dev_buf_in2
std::unique_ptr< cl::Buffer > m_dev_buf_in2
Definition: VectorAddOCLExampleAlg.h:78
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_host_buf_in2
uint32_t * m_host_buf_in2
Definition: VectorAddOCLExampleAlg.h:82
AthExXRT::VectorAddOCLExampleAlg::s_krnl_param_in2
static constexpr int s_krnl_param_in2
Definition: VectorAddOCLExampleAlg.h:55
SlotSpecificObj.h
Maintain a set of objects, one per slot.
AthExXRT::VectorAddOCLExampleAlg::s_element_count
static constexpr int s_element_count
Definition: VectorAddOCLExampleAlg.h:60
AthExXRT::VectorAddOCLExampleAlg
Example algorithm exercising the AthXRT core services.
Definition: VectorAddOCLExampleAlg.h:28
AthExXRT::VectorAddOCLExampleAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition: VectorAddOCLExampleAlg.cxx:110
AthExXRT::VectorAddOCLExampleAlg::SlotData::m_program
std::shared_ptr< cl::Program > m_program
OpenCL program pointer.
Definition: VectorAddOCLExampleAlg.h:68
ServiceHandle< AthXRT::IDeviceMgmtSvc >