6 #include "GaudiKernel/ConcurrencyFlags.h"
18 cl_int
err = CL_SUCCESS;
21 std::vector<AthXRT::IDeviceMgmtSvc::OpenCLHandle> handles =
24 if (handles.empty()) {
26 return StatusCode::FAILURE;
30 std::size_t slotIdx = 0;
34 if (handles.size() > 1) {
37 <<
"), using the first one");
39 slot.m_context = handles[0].context;
40 slot.m_program = handles[0].program;
47 "Could not create OpenCL kernel '"
49 <<
"', check that correct XCLBIN is programmed by AthXRT service");
50 return StatusCode::FAILURE;
54 slot.m_queue = std::make_unique<cl::CommandQueue>(
55 *slot.m_context, slot.m_context->getInfo<CL_CONTEXT_DEVICES>()[0], 0,
63 slot.m_dev_buf_in1 = std::make_unique<cl::Buffer>(
64 *slot.m_context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
65 size_in_bytes,
nullptr, &
err);
68 slot.m_dev_buf_in2 = std::make_unique<cl::Buffer>(
69 *slot.m_context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
70 size_in_bytes,
nullptr, &
err);
73 slot.m_dev_buf_out = std::make_unique<cl::Buffer>(
74 *slot.m_context, CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
75 size_in_bytes,
nullptr, &
err);
78 slot.m_host_buf_in1 = (
uint32_t*)slot.m_queue->enqueueMapBuffer(
79 *slot.m_dev_buf_in1, CL_TRUE, CL_MAP_WRITE, 0, size_in_bytes,
nullptr,
83 slot.m_host_buf_in2 = (
uint32_t*)slot.m_queue->enqueueMapBuffer(
84 *slot.m_dev_buf_in2, CL_TRUE, CL_MAP_WRITE, 0, size_in_bytes,
nullptr,
88 slot.m_host_buf_out = (
uint32_t*)slot.m_queue->enqueueMapBuffer(
89 *slot.m_dev_buf_out, CL_TRUE, CL_MAP_READ, 0, size_in_bytes,
nullptr,
107 return StatusCode::SUCCESS;
125 nullptr) == CL_SUCCESS);
134 std::vector<cl::Memory> mems_out_vector = {*slot.
m_dev_buf_out};
136 mems_out_vector, CL_MIGRATE_MEM_OBJECT_HOST,
nullptr,
137 nullptr) == CL_SUCCESS);
146 <<
i <<
": CPU result = " << cpu_result
156 return StatusCode::FAILURE;
160 return StatusCode::SUCCESS;
167 ATH_CHECK(slot.m_queue->enqueueUnmapMemObject(
168 *slot.m_dev_buf_in1, slot.m_host_buf_in1) == CL_SUCCESS);
169 ATH_CHECK(slot.m_queue->enqueueUnmapMemObject(
170 *slot.m_dev_buf_in2, slot.m_host_buf_in2) == CL_SUCCESS);
171 ATH_CHECK(slot.m_queue->enqueueUnmapMemObject(
172 *slot.m_dev_buf_out, slot.m_host_buf_out) == CL_SUCCESS);
173 ATH_CHECK(slot.m_queue->finish() == CL_SUCCESS);
177 return StatusCode::SUCCESS;