Service used for programming XRT compatible accelerators.
More...
#include <DeviceMgmtSvc.h>
|
struct | AthClContext |
| Struct to hold information about a context, as well as the devices, the program and XCLBIN file associated with the context. More...
|
|
struct | SystemInfo |
|
struct | XclbinInfo |
| Struct to hold information about an XCLBIN file, as well as the kernels it contains. More...
|
|
Service used for programming XRT compatible accelerators.
This service aims to be a central point for managing XRT compatible accelerators. It will enumerate the available devices, program them with the specified XCLBIN files and provide a way for client algorithms to request lists of devices by kernel name, either using native XRT API or OpenCL API.
- Author
- Quentin Berthet quent.nosp@m.in.b.nosp@m.erthe.nosp@m.t@ce.nosp@m.rn.ch
Definition at line 31 of file DeviceMgmtSvc.h.
◆ finalize()
StatusCode AthXRT::DeviceMgmtSvc::finalize |
( |
| ) |
|
|
overridevirtual |
Finalise the service.
Definition at line 470 of file DeviceMgmtSvc.cxx.
476 return StatusCode::SUCCESS;
◆ get_device_bdf()
std::string AthXRT::DeviceMgmtSvc::get_device_bdf |
( |
const cl::Device & |
device | ) |
const |
|
private |
Get the BDF (bus:device:function) string of a cl::device.
- Parameters
-
device | The device to get the BDF from. |
- Returns
- The BDF of the device as a string, or "error" in case of failure.
Definition at line 179 of file DeviceMgmtSvc.cxx.
181 cl_int
err = CL_SUCCESS;
182 std::string device_bdf;
183 err = device.getInfo(CL_DEVICE_PCIE_BDF, &device_bdf);
184 if (
err != CL_SUCCESS) {
186 return std::string(
"error");
◆ get_device_name()
std::string AthXRT::DeviceMgmtSvc::get_device_name |
( |
const cl::Device & |
device | ) |
const |
|
private |
Get the name of a cl::device.
- Parameters
-
device | The device to get the name from. |
- Returns
- The name of the device as a string, or "error" in case of failure.
Definition at line 164 of file DeviceMgmtSvc.cxx.
166 cl_int
err = CL_SUCCESS;
167 std::string device_name;
168 err = device.getInfo(CL_DEVICE_NAME, &device_name);
169 if (
err != CL_SUCCESS) {
171 return std::string(
"error");
◆ get_opencl_handles_by_kernel_name()
Get a list of OpenCL handles providing the specified kernel.
- Parameters
-
name | The name of the kernel to search for. |
- Returns
- A vector of OpenCL handles structs providing the specified kernel.
Definition at line 501 of file DeviceMgmtSvc.cxx.
504 std::vector<IDeviceMgmtSvc::OpenCLHandle> handles;
509 if (
std::find(ath_cl_context.xclbin_info.kernel_names.begin(),
510 ath_cl_context.xclbin_info.kernel_names.end(),
511 name) != ath_cl_context.xclbin_info.kernel_names.end()) {
512 IDeviceMgmtSvc::OpenCLHandle handle = {ath_cl_context.context,
513 ath_cl_context.program};
514 handles.push_back(handle);
◆ get_xrt_devices_by_kernel_name()
const std::vector< std::shared_ptr< xrt::device > > AthXRT::DeviceMgmtSvc::get_xrt_devices_by_kernel_name |
( |
const std::string & |
name | ) |
const |
|
overridevirtual |
Get a list of XRT devices providing the specified kernel.
- Parameters
-
name | The name of the kernel to search for. |
- Returns
- A vector of XRT device handles providing the specified kernel.
Definition at line 480 of file DeviceMgmtSvc.cxx.
482 std::vector<std::shared_ptr<xrt::device>> devices;
487 if (
std::find(ath_cl_context.xclbin_info.kernel_names.begin(),
488 ath_cl_context.xclbin_info.kernel_names.end(),
489 name) != ath_cl_context.xclbin_info.kernel_names.end()) {
490 for (
const cl::Device &device : ath_cl_context.devices) {
491 devices.push_back(std::make_shared<xrt::device>(
492 xrt::opencl::get_xrt_device(device())));
◆ initialize()
StatusCode AthXRT::DeviceMgmtSvc::initialize |
( |
| ) |
|
|
overridevirtual |
Initialise the service.
Initialize the service.
This function will inspect the available devices and XCLBIN files, pair them and create contexts based on the information gathered. It will then program the devices with the XCLBIN files and create contexts.
- Returns
- StatusCode::SUCCESS if the initialization was successful, or StatusCode::FAILURE otherwise.
Definition at line 446 of file DeviceMgmtSvc.cxx.
467 return StatusCode::SUCCESS;
◆ inspect_devices()
StatusCode AthXRT::DeviceMgmtSvc::inspect_devices |
( |
SystemInfo & |
si | ) |
|
|
private |
Inspect the available devices and fill the SystemInfo structure.
Find all available XRT compatible accelerator devices and group them by type.
- Parameters
-
Definition at line 18 of file DeviceMgmtSvc.cxx.
20 std::vector<cl::Platform> platforms;
24 for (
const cl::Platform &
platform : platforms) {
28 std::string platform_name;
30 if (platform_name !=
"Xilinx") {
36 std::vector<cl::Device> devices;
39 ATH_MSG_DEBUG(
"Found XRT/OpenCL platform '" << platform_name <<
"' with "
42 si.device_count += devices.size();
47 for (
const cl::Device &device : devices) {
52 for (std::vector<cl::Device> &
list : si.device_types) {
53 std::string list_device_name;
54 ATH_CHECK(
list[0].getInfo(CL_DEVICE_NAME, &list_device_name) ==
56 if (device_name == list_device_name) {
58 list.push_back(device);
63 std::vector<cl::Device> new_list = {device};
64 si.device_types.push_back(new_list);
70 if (si.device_count < 1) {
75 return StatusCode::FAILURE;
78 << si.device_count <<
" AMD FPGA device(s) ("
79 << si.device_types.size() <<
" device type(s))");
82 return StatusCode::SUCCESS;
◆ inspect_xclbins()
StatusCode AthXRT::DeviceMgmtSvc::inspect_xclbins |
( |
SystemInfo & |
si | ) |
|
|
private |
Inspect the provided XCLBIN files and fill the SystemInfo structure.
Gather information using XRT native API about the XCLBIN files and the kernel(s) they contain and perform some basic sanity checks.
- Parameters
-
Definition at line 90 of file DeviceMgmtSvc.cxx.
95 return StatusCode::FAILURE;
102 "More XCLBIN file(s) specified than "
103 "devices type available ("
104 << si.device_count <<
"): ");
108 return StatusCode::FAILURE;
115 ATH_MSG_ERROR(
"XCLBIN file does not exist: " << xclbin_path);
116 return StatusCode::FAILURE;
122 DeviceMgmtSvc::XclbinInfo xclbin_info;
124 xrt::xclbin xrt_xclbin(xclbin_path);
125 xclbin_info.path = xclbin_path;
126 xclbin_info.xsa_name = xrt_xclbin.get_xsa_name();
127 xclbin_info.fpga_device_name = xrt_xclbin.get_fpga_device_name();
128 xclbin_info.uuid = xrt_xclbin.get_uuid().to_string();
129 for (
const xrt::xclbin::kernel &kernel : xrt_xclbin.get_kernels()) {
134 if (!kernel.get_cus().empty()) {
135 xclbin_info.kernel_names.push_back(kernel.get_name());
139 ATH_MSG_ERROR(
"Could not create xrt::xclbin from " << xclbin_path);
140 return StatusCode::FAILURE;
148 std::set<std::string> uuids;
149 std::set<std::string> fpga_device_names;
151 uuids.insert(
info.uuid);
152 fpga_device_names.insert(
info.fpga_device_name);
154 si.different_xclbin_count = uuids.size();
155 si.different_xclbin_fpga_device_name = fpga_device_names.size();
157 return StatusCode::SUCCESS;
◆ is_xclbin_compatible_with_device()
Helper function to check if an XCLBIN file is compatible with a device.
Check if an XCLBIN is compatible with a device.
This is done by comparing the device name and the XSA name used in the XCLBIN file up to the second occurrence of the underscore character. This check is not a guarantee that the XCLBIN will work on the device, but mismatching XSA names are a strong indicator of incompatibility.
- Parameters
-
xclbin_info | The XCLBIN to check compatibility with. |
device | The device to check compatibility with. |
- Returns
- True if the XCLBIN is compatible with the device, false otherwise.
Definition at line 226 of file DeviceMgmtSvc.cxx.
230 const std::string device_prefix =
232 const std::string xsa_prefix =
233 getPrefixUpToNthOccurrence(xclbin_info.xsa_name,
'_', 2);
234 if (device_prefix == xsa_prefix) {
◆ pair_devices_and_xclbins()
StatusCode AthXRT::DeviceMgmtSvc::pair_devices_and_xclbins |
( |
const SystemInfo & |
si | ) |
|
|
private |
Pair devices and XCLBINs and create contexts.
This function will pair devices and XCLBINsd epending on the number of devices and XCLBINs, will attempt to program all provided XCLBINs according to the following rules:
- If we have only one FPGA type and one XCLBIN: Program all devices with the same XCLBIN and create one context.
- If we have only one FPGA type and multiple identical XCLBIN: Program the same number of devices that we have XCLBIN files, but put them in only one context as the XCLBIN will be identical for all programmed devices.
- If we have multiple type and multiple different XCLBIN, but all targeting the same device: Program all devices with a different XCLBIN and create one context per device/XCLBIN.
- If we have multiple type and multiple different XCLBIN, and the XCLBIN files target multiple device types: Program each device with a matching XCLBIN and create one context per device/XCLBIN. Some devices might be left un-programmed if no matching XCLBIN is found.
- Parameters
-
si | The SystemInfo structure containing information about the devices and XCLBINs available on the system. |
- Returns
- StatusCode::SUCCESS if the pairing was successful, or StatusCode::FAILURE otherwise.
Definition at line 261 of file DeviceMgmtSvc.cxx.
264 if (si.device_types.size() == 1) {
271 ATH_MSG_DEBUG(
"Case 1: One or multiple identical device(s), one xclbin");
272 DeviceMgmtSvc::AthClContext ath_cl_context;
273 for (
const cl::Device &device : si.device_types[0]) {
274 ath_cl_context.devices.push_back(device);
281 if (si.different_xclbin_fpga_device_name > 1) {
286 "Specified XCLBINs target multiple device types, but only one "
287 "device type is present");
288 return StatusCode::FAILURE;
291 if (si.different_xclbin_count == 1) {
297 "Case 2: Multiple identical devices, multiple identical xclbins");
298 DeviceMgmtSvc::AthClContext ath_cl_context;
300 ath_cl_context.devices.push_back(si.device_types[0][
i]);
312 "Case 3: Multiple identical devices, multiple different XCLBIN "
313 "files, but targeting the same device type");
315 DeviceMgmtSvc::AthClContext ath_cl_context;
317 ath_cl_context.devices.push_back(si.device_types[0][
i]);
328 ATH_MSG_DEBUG(
"Case 4: Multiple different devices, multiple xclbins");
330 for (
const std::vector<cl::Device> &device_type : si.device_types) {
331 for (
const cl::Device &device : device_type) {
332 DeviceMgmtSvc::AthClContext ath_cl_context;
333 ath_cl_context.devices.push_back(device);
338 for (iter = unaffected_xclbin_infos.begin();
339 iter != unaffected_xclbin_infos.end();) {
341 ath_cl_context.xclbin_info = *iter;
342 iter = unaffected_xclbin_infos.erase(iter);
363 for (
const XclbinInfo &xclbin_info : unaffected_xclbin_infos) {
367 "No compatible device found for XCLBIN: " << xclbin_info.path);
371 return StatusCode::SUCCESS;
◆ program_devices()
StatusCode AthXRT::DeviceMgmtSvc::program_devices |
( |
| ) |
|
|
private |
Program the devices with the XCLBIN files and create contexts.
This function will program the devices with the XCLBIN files and create contexts based on the information in m_ath_cl_contexts. If an incompatible XCLBIN is found for a device, the initialization will fail.
- Returns
- StatusCode::SUCCESS if the programming was successful, or StatusCode::FAILURE otherwise.
Definition at line 381 of file DeviceMgmtSvc.cxx.
383 cl_int
err = CL_SUCCESS;
388 ath_cl_context.context = std::make_shared<cl::Context>(
389 ath_cl_context.devices,
nullptr,
nullptr,
nullptr, &
err);
390 if (
err != CL_SUCCESS) {
392 return StatusCode::FAILURE;
398 file.open(ath_cl_context.xclbin_info.path.c_str(), std::ios::binary);
400 ATH_MSG_ERROR(
"Could not open " << ath_cl_context.xclbin_info.path
402 return StatusCode::FAILURE;
404 std::vector<char> xclbin_buffer((std::istreambuf_iterator<char>(
file)),
405 std::istreambuf_iterator<char>());
410 cl::Program::Binaries binary;
411 for (std::size_t
i = 0;
i < ath_cl_context.devices.size(); ++
i) {
412 binary.push_back({xclbin_buffer.data(), xclbin_buffer.size()});
417 ath_cl_context.program = std::make_shared<cl::Program>(
418 *ath_cl_context.context, ath_cl_context.devices, binary,
nullptr, &
err);
419 if (
err != CL_SUCCESS) {
421 return StatusCode::FAILURE;
425 std::string bdfs =
"";
426 for (
const cl::Device &device : ath_cl_context.devices) {
430 ATH_MSG_INFO(
"Loaded " << ath_cl_context.xclbin_info.path <<
" on "
431 << ath_cl_context.devices.size() <<
" "
433 <<
" device(s): " << bdfs);
436 return StatusCode::SUCCESS;
◆ m_ath_cl_contexts
std::vector<AthClContext> AthXRT::DeviceMgmtSvc::m_ath_cl_contexts |
|
private |
List of contexts configured for the service.
Definition at line 137 of file DeviceMgmtSvc.h.
◆ m_xclbin_infos
std::vector<XclbinInfo> AthXRT::DeviceMgmtSvc::m_xclbin_infos |
|
private |
List of XCLBIN files info configured for the service.
Definition at line 125 of file DeviceMgmtSvc.h.
◆ m_xclbin_path_list
Gaudi::Property<std::vector<std::string> > AthXRT::DeviceMgmtSvc::m_xclbin_path_list |
|
private |
Initial value:{
this,
"XclbinPathsList",
{},
"The list of XCLBIN files to program on FPGAs"}
The list of xclbin files to use.
This is a list of paths to XCLBIN files to load on accelerator devices.
Definition at line 72 of file DeviceMgmtSvc.h.
The documentation for this class was generated from the following files: