13 #include <CL/cl_ext_xilinx.h>
20 std::vector<cl::Platform> platforms;
23 if (
err == CL_SUCCESS)
25 ATH_MSG_INFO(
"Detected OpenCL platforms: " << platforms.size());
30 return StatusCode::FAILURE;
33 std::vector<cl::Device> allDevices;
37 for (cl::Platform
pf : platforms)
42 ATH_MSG_INFO(
"Platform profile: " <<
pf.getInfo<CL_PLATFORM_PROFILE>());
43 ATH_MSG_INFO(
"Platform vendor: " <<
pf.getInfo<CL_PLATFORM_VENDOR>());
45 pf.getDevices(CL_DEVICE_TYPE_ALL, &allDevices);
46 ATH_MSG_INFO(
"There are " << allDevices.size() <<
" devices in this platform.");
50 bool foundAccelerator =
false;
52 for(
auto device : allDevices)
58 foundAccelerator =
true;
62 if (device.getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_ACCELERATOR)
64 std::string deviceBDF =
"";
65 device.getInfo(CL_DEVICE_PCIE_BDF, &deviceBDF);
73 foundAccelerator =
true;
79 ATH_MSG_INFO(
"Using the first found accelerator card: " << device.getInfo<CL_DEVICE_NAME>());
81 foundAccelerator =
true;
91 ATH_MSG_ERROR(
"Couldn't find an FPGA accelerator card in this platform");
92 return StatusCode::FAILURE;
96 ATH_MSG_INFO(
"Using device number " << device_id <<
" which is a FPGA accelerator card: " <<
m_accelerator.getInfo<CL_DEVICE_NAME>());
101 return StatusCode::SUCCESS;
108 return StatusCode::SUCCESS;
114 std::ifstream bin_file(xclbin, std::ios_base::binary);
118 return StatusCode::FAILURE;
121 bin_file.seekg(0, bin_file.end);
122 unsigned bin_size = bin_file.tellg();
124 bin_file.seekg(0, bin_file.beg);
126 std::vector<char> buf(bin_size);
127 bin_file.read(buf.data(), bin_size);
131 std::vector<cl_int> binaryStatus;
132 cl::Program::Binaries
bins{{buf.data(), bin_size}};
137 if (
err == CL_SUCCESS && binaryStatus.at(0) == CL_SUCCESS)
144 return StatusCode::FAILURE;
147 return StatusCode::SUCCESS;
156 ATH_MSG_FATAL(
item.documentation()<<
" is empty. Please set it to a valid value");
157 return StatusCode::FAILURE;
164 ATH_MSG_WARNING(
"Device BDF is not set. Using the first found accelerator card. Set property 'bdfID' to specify the BDF of the device.");
167 return StatusCode::SUCCESS;