ATLAS Offline Software
Loading...
Searching...
No Matches
VectorAddOCLExampleAlg.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2025 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).
13
14// Framework include(s).
17#include "GaudiKernel/ServiceHandle.h"
18
19namespace AthExXRT {
20
30
31 public:
32 // Inherit the base class's constructor(s).
33 using ::AthReentrantAlgorithm::AthReentrantAlgorithm;
34
35 virtual StatusCode initialize() override {
36 return StateHandler::initialize();
37 }
38
39 virtual StatusCode initialize_global() override;
40 virtual StatusCode initialize_worker() override;
41
42 virtual StatusCode execute(const EventContext& ctx) const override;
43
44 virtual StatusCode stop() override {
45 return StateHandler::stop();
46 }
47 virtual StatusCode stop_worker() override;
48
49 private:
50
53 this, "DeviceMgmtSvc", "AthXRT::DeviceMgmtSvc",
54 "The XRT device manager service to use"};
55
56 // Kernel name string
57 static constexpr char s_krnl_name[] = "krnl_VectorAdd";
58
59 // Kernel arguments indexes
60 // Must match the kernel arguments order.
61 static constexpr int s_krnl_param_in1 = 0;
62 static constexpr int s_krnl_param_in2 = 1;
63 static constexpr int s_krnl_param_out = 2;
64 static constexpr int s_krnl_param_size = 3;
65
66 // Number of uint32_t element in the vectors
67 static constexpr int s_element_count = 4096;
68
69 std::vector<AthXRT::IDeviceMgmtSvc::OpenCLHandle> m_handles;
70
72 struct SlotData {
74 std::shared_ptr<cl::Context> m_context = nullptr;
75
77 std::shared_ptr<cl::Program> m_program = nullptr;
78
80 std::unique_ptr<cl::Kernel> m_kernel = nullptr;
81
83 std::unique_ptr<cl::CommandQueue> m_queue = nullptr;
84
86 std::unique_ptr<cl::Buffer> m_dev_buf_in1 = nullptr;
87 std::unique_ptr<cl::Buffer> m_dev_buf_in2 = nullptr;
88 std::unique_ptr<cl::Buffer> m_dev_buf_out = nullptr;
89
90 uint32_t* m_host_buf_in1 = nullptr;
91 uint32_t* m_host_buf_in2 = nullptr;
92 uint32_t* m_host_buf_out = nullptr;
93 };
94
97
98}; // class VectorAddOCLExampleAlg
99
100} // namespace AthExXRT
101
102#endif // ATHEXXRT_VECTORADDOCLEXAMPLEALG_H
Maintain a set of objects, one per slot.
Example algorithm exercising the AthXRT core services.
SG::SlotSpecificObj< SlotData > m_slots
List of slot-specific data.
virtual StatusCode initialize_worker() override
Initialization per process.
ServiceHandle< AthXRT::IDeviceMgmtSvc > m_DeviceMgmtSvc
The XRT device manager to use.
virtual StatusCode stop() override
virtual StatusCode initialize() override
virtual StatusCode initialize_global() override
Glocal XRT initialization.
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode stop_worker() override
clean up
std::vector< AthXRT::IDeviceMgmtSvc::OpenCLHandle > m_handles
An algorithm that can be simultaneously executed in multiple threads.
Base class to provide common infrastructure for handling multiprocess state transitions for FPGA.
Maintain a set of objects, one per slot.
std::shared_ptr< cl::Program > m_program
OpenCL program pointer.
std::unique_ptr< cl::Kernel > m_kernel
Kernel object.
std::shared_ptr< cl::Context > m_context
OpenCL context pointer.
std::unique_ptr< cl::CommandQueue > m_queue
Kernel run object.
std::unique_ptr< cl::Buffer > m_dev_buf_in1
Buffer objects.