ATLAS Offline Software
DeviceMgmtSvc.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 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 
19 namespace AthXRT {
20 
31 class 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.
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  };
118 
121  const DeviceMgmtSvc::XclbinInfo &xclbin_info,
122  const cl::Device &device) const;
123 
125  std::vector<XclbinInfo> m_xclbin_infos;
126 
129  struct AthClContext {
130  std::shared_ptr<cl::Context> context;
131  std::vector<cl::Device> devices;
133  std::shared_ptr<cl::Program> program;
134  };
135 
137  std::vector<AthClContext> m_ath_cl_contexts;
138 
139 }; // class DeviceMgmtSvc
140 
141 } // namespace AthXRT
142 
143 #endif // ATHXRTSERVICES_DEVICEMGMTSVC_H
AthXRT::DeviceMgmtSvc::get_opencl_handles_by_kernel_name
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.
Definition: DeviceMgmtSvc.cxx:501
AthXRT::DeviceMgmtSvc::finalize
virtual StatusCode finalize() override
Finalise the service.
Definition: DeviceMgmtSvc.cxx:470
AthXRT::DeviceMgmtSvc::SystemInfo::different_xclbin_count
std::size_t different_xclbin_count
Definition: DeviceMgmtSvc.h:93
AthXRT::DeviceMgmtSvc::XclbinInfo::kernel_names
std::vector< std::string > kernel_names
Definition: DeviceMgmtSvc.h:116
AthXRT::DeviceMgmtSvc::AthClContext
Struct to hold information about a context, as well as the devices, the program and XCLBIN file assoc...
Definition: DeviceMgmtSvc.h:129
AthXRT::DeviceMgmtSvc::m_xclbin_infos
std::vector< XclbinInfo > m_xclbin_infos
List of XCLBIN files info configured for the service.
Definition: DeviceMgmtSvc.h:125
AthXRT::DeviceMgmtSvc::SystemInfo::different_xclbin_fpga_device_name
std::size_t different_xclbin_fpga_device_name
Definition: DeviceMgmtSvc.h:94
AthXRT::DeviceMgmtSvc::get_xrt_devices_by_kernel_name
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.
Definition: DeviceMgmtSvc.cxx:480
AthXRT::DeviceMgmtSvc::SystemInfo
Definition: DeviceMgmtSvc.h:86
AthXRT::DeviceMgmtSvc::get_device_bdf
std::string get_device_bdf(const cl::Device &device) const
Get the BDF (bus:device:function) string of a cl::device.
Definition: DeviceMgmtSvc.cxx:179
AthXRT::DeviceMgmtSvc::XclbinInfo::path
std::string path
Definition: DeviceMgmtSvc.h:112
AthXRT::DeviceMgmtSvc::inspect_xclbins
StatusCode inspect_xclbins(SystemInfo &si)
Inspect the provided XCLBIN files and fill the SystemInfo structure.
Definition: DeviceMgmtSvc.cxx:90
AthXRT::DeviceMgmtSvc::XclbinInfo::fpga_device_name
std::string fpga_device_name
Definition: DeviceMgmtSvc.h:114
AthXRT::DeviceMgmtSvc::AthClContext::xclbin_info
XclbinInfo xclbin_info
Definition: DeviceMgmtSvc.h:132
AthXRT::DeviceMgmtSvc::XclbinInfo::uuid
std::string uuid
Definition: DeviceMgmtSvc.h:115
AthXRT::DeviceMgmtSvc::XclbinInfo
Struct to hold information about an XCLBIN file, as well as the kernels it contains.
Definition: DeviceMgmtSvc.h:111
AthXRT::DeviceMgmtSvc::initialize
virtual StatusCode initialize() override
Initialise the service.
Definition: DeviceMgmtSvc.cxx:446
AthXRT::DeviceMgmtSvc::SystemInfo::device_count
std::size_t device_count
Definition: DeviceMgmtSvc.h:92
AthXRT::DeviceMgmtSvc::is_xclbin_compatible_with_device
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.
Definition: DeviceMgmtSvc.cxx:226
AthXRT::DeviceMgmtSvc::m_xclbin_path_list
Gaudi::Property< std::vector< std::string > > m_xclbin_path_list
The list of xclbin files to use.
Definition: DeviceMgmtSvc.h:72
AthXRT::DeviceMgmtSvc::XclbinInfo::xsa_name
std::string xsa_name
Definition: DeviceMgmtSvc.h:113
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthXRT::DeviceMgmtSvc
Service used for programming XRT compatible accelerators.
Definition: DeviceMgmtSvc.h:31
AthXRT::DeviceMgmtSvc::SystemInfo::device_types
std::vector< std::vector< cl::Device > > device_types
Definition: DeviceMgmtSvc.h:90
AthXRT::DeviceMgmtSvc::AthClContext::context
std::shared_ptr< cl::Context > context
Definition: DeviceMgmtSvc.h:130
AthXRT::DeviceMgmtSvc::AthClContext::devices
std::vector< cl::Device > devices
Definition: DeviceMgmtSvc.h:131
AthXRT::DeviceMgmtSvc::get_device_name
std::string get_device_name(const cl::Device &device) const
Get the name of a cl::device.
Definition: DeviceMgmtSvc.cxx:164
IDeviceMgmtSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthXRT::DeviceMgmtSvc::m_ath_cl_contexts
std::vector< AthClContext > m_ath_cl_contexts
List of contexts configured for the service.
Definition: DeviceMgmtSvc.h:137
AthXRT::DeviceMgmtSvc::AthClContext::program
std::shared_ptr< cl::Program > program
Definition: DeviceMgmtSvc.h:133
AthXRT::DeviceMgmtSvc::pair_devices_and_xclbins
StatusCode pair_devices_and_xclbins(const SystemInfo &si)
Pair devices and XCLBINs and create contexts.
Definition: DeviceMgmtSvc.cxx:261
AthXRT::DeviceMgmtSvc::inspect_devices
StatusCode inspect_devices(SystemInfo &si)
Inspect the available devices and fill the SystemInfo structure.
Definition: DeviceMgmtSvc.cxx:18
AthService.h
AthXRT::DeviceMgmtSvc::program_devices
StatusCode program_devices()
Program the devices with the XCLBIN files and create contexts.
Definition: DeviceMgmtSvc.cxx:381
AthXRT
Definition: IDeviceMgmtSvc.h:30