ATLAS Offline Software
Loading...
Searching...
No Matches
DeviceMgmtSvc.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 ATHXRTSERVICES_DEVICEMGMTSVC_H
5#define ATHXRTSERVICES_DEVICEMGMTSVC_H
6
7// AthXRT include(s).
9
10// Framework include(s).
12#include "Gaudi/Parsers/Factory.h"
13#include "Gaudi/Property.h"
14#include "GaudiKernel/ServiceHandle.h"
15
16// System include(s).
17#include <string>
18
19namespace AthXRT {
20
31class DeviceMgmtSvc : public extends<AthService, IDeviceMgmtSvc> {
32
33 public:
35 using extends::extends;
36
39
41 virtual StatusCode initialize() override;
42
44 virtual StatusCode finalize() override;
45
47
50
54 virtual const std::vector<IDeviceMgmtSvc::OpenCLHandle>
55 get_opencl_handles_by_kernel_name(const std::string &name) const override;
56
60 virtual const std::vector<std::shared_ptr<xrt::device>>
61 get_xrt_devices_by_kernel_name(const std::string &name) const override;
62
64
65 private:
68
72 Gaudi::Property<std::vector<std::string>> m_xclbin_path_list{
73 this,
74 "XclbinPathsList",
75 {},
76 "The list of XCLBIN files to program on FPGAs"};
77
79
80 // Structure used to gather information about the devices and
81 // XCLBIN files available on the system during inspect_devices() and
82 // inspect_xclbins() functions. Later used by pair_devices_and_xclbins(),
83 // to make decision on which XCLBIN file to program on which device.
84 // Not created as a class member, as it is only used in the
85 // initialize() function.
86 struct SystemInfo {
87 // Used to accumulate the devices (inner vector) by device
88 // types (outter vector) during initialization, as final
89 // grouping (by contexts) is not known yet.
90 std::vector<std::vector<cl::Device>> device_types;
91
92 std::size_t device_count;
95 };
96
97 // Helpers to get device information.
98 std::string get_device_name(const cl::Device &device) const;
99 std::string get_device_bdf(const cl::Device &device) const;
100
101 // Main functions, called in sequence during initialize().
102 // Split into multiple methods for code readability, but have no other
103 // reason to be called separately.
104 StatusCode inspect_devices(SystemInfo &si);
105 StatusCode inspect_xclbins(SystemInfo &si);
106 StatusCode pair_devices_and_xclbins(const SystemInfo &si);
107 StatusCode program_devices();
108
111 struct XclbinInfo {
112 std::string path;
113 std::string xsa_name;
114 std::string fpga_device_name;
115 std::string uuid;
116 std::vector<std::string> kernel_names;
117 std::vector<std::string> cu_names;
118 };
119
122 const DeviceMgmtSvc::XclbinInfo &xclbin_info,
123 const cl::Device &device) const;
124
126 std::vector<XclbinInfo> m_xclbin_infos;
127
131 std::shared_ptr<cl::Context> context;
132 std::vector<cl::Device> devices;
134 std::shared_ptr<cl::Program> program;
135 };
136
138 std::vector<AthClContext> m_ath_cl_contexts;
139
140}; // class DeviceMgmtSvc
141
142} // namespace AthXRT
143
144#endif // ATHXRTSERVICES_DEVICEMGMTSVC_H
Service used for programming XRT compatible accelerators.
StatusCode program_devices()
Program the devices with the XCLBIN files and create contexts.
virtual const std::vector< IDeviceMgmtSvc::OpenCLHandle > get_opencl_handles_by_kernel_name(const std::string &name) const override
Get a list of OpenCL handles providing the specified kernel.
std::vector< XclbinInfo > m_xclbin_infos
List of XCLBIN files info configured for the service.
virtual const std::vector< std::shared_ptr< xrt::device > > get_xrt_devices_by_kernel_name(const std::string &name) const override
Get a list of XRT devices providing the specified kernel.
virtual StatusCode finalize() override
Finalise the service.
Gaudi::Property< std::vector< std::string > > m_xclbin_path_list
The list of xclbin files to use.
std::string get_device_name(const cl::Device &device) const
Get the name of a cl::device.
std::vector< AthClContext > m_ath_cl_contexts
List of contexts configured for the service.
StatusCode pair_devices_and_xclbins(const SystemInfo &si)
Pair devices and XCLBINs and create contexts.
StatusCode inspect_xclbins(SystemInfo &si)
Inspect the provided XCLBIN files and fill the SystemInfo structure.
StatusCode inspect_devices(SystemInfo &si)
Inspect the available devices and fill the SystemInfo structure.
bool is_xclbin_compatible_with_device(const DeviceMgmtSvc::XclbinInfo &xclbin_info, const cl::Device &device) const
Helper function to check if an XCLBIN file is compatible with a device.
virtual StatusCode initialize() override
Initialise the service.
std::string get_device_bdf(const cl::Device &device) const
Get the BDF (bus:device:function) string of a cl::device.
Struct to hold information about a context, as well as the devices, the program and XCLBIN file assoc...
std::shared_ptr< cl::Program > program
std::vector< cl::Device > devices
std::shared_ptr< cl::Context > context
std::vector< std::vector< cl::Device > > device_types
Struct to hold information about an XCLBIN file, as well as the kernels it contains.
std::vector< std::string > cu_names
std::vector< std::string > kernel_names