Intel® High Level Design
Support for Intel® High Level Synthesis Compiler, DSP Builder, OneAPI for Intel® FPGAs, Intel® FPGA SDK for OpenCL™
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
539 Discussions

OpenCL C++ API for Pipes doesn't provide read/write methods?

okramer
New Contributor I
576 Views

I'm looking for guidance here, as I'm confused on whether to use OpenCL C or C++ API. I'm learning to use host pipes. The examples use the C++ API for establishing queues and contexts, etc., but then the example pipes code is all in C. There is a C++ API for pipes (in cl2.hpp), namely, cl::Pipes. However, I don't see any method for reading or writing to a cl::Pipe object. How is this accomplished? Here is the relevant host code:

// Create host-to-FPGA pipe and bind to kernel, then launch: std::vector<cl::Device> DeviceList; cl::Context context; getContextAndDevices(mode, context, DeviceList); // Fetch items using OpenCL C++ API cl::Pipe p_out (context, sizeof(float), vectorSize, &err); host_reader_kernel.setArg(0, &p_out); err=queue1.enqueueTask(host_reader_kernel);   // Write data to the FPGA via pipe. THIS DOES NOT COMPILE because "write_pipe" not declared: float data=42.0; cl::write_pipe(p_out, data);

In the kernel code, there is `write_pipe()` so I took a guess that host-side would be the same API. It is supposed to be C++ though so would have expected write_pipe() to be a method on cl::Pipe. Are C++ Pipes not supported? Do I have to do everything (contexts, queues, etc) in OpenCL's C API?

0 Kudos
5 Replies
MEIYAN_L_Intel
Employee
365 Views

Hi,

The cl2.hpp is a wrapper API as shown in https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/opencl-sdk/aocl_getting_... table 1. However it is not fully supported C++ and tied to OpenCL specification based on the version.

 

To read and write between the kernel and host, you may need to refer https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/opencl-sdk/aocl_programm... in chapter 5.5.6.

 

Thanks

okramer
New Contributor I
365 Views

To summarize the answer: I found that the C++ wrappers (cl::Context, cl:Kernel, etc.) all have the parens operator () to access the underlying C struct (cl_context, cl_kernel, etc.). So it is a trivial matter to mix the C and C++ APIs.

 

For host-to-dev comms, there are clWritePipeIntelFPGA and clReadPipeIntelFPGA functions on the host side defined in CL/cl_ext_intelfpga.h that must be included in the host code. It seems Intel should have implemented Pipe::write() and Pipe::read() in the wrapper code to call the C Intel functions above.

 

I also had to declare the following before including any CL headers:

#define CL_HPP_TARGET_OPENCL_VERSION=200 #define CL_TARGET_OPENCL_VERSION=200

I have a good compile now, though getting "ERROR: Enqueue Task (-52)" while running emulation.

 

MEIYAN_L_Intel
Employee
365 Views

Hi,

 

Do you run compilation successfully?

 

Thanks

okramer
New Contributor I
365 Views

Yes. Now working on a hang associated with host write - kernel read pipe operation.

MEIYAN_L_Intel
Employee
365 Views

Hi,

The latest problem seem like same as here: https://forums.intel.com/s/question/0D50P00004XbSe1/host-pipes-not-working-as-documented-in-programm....

I will reply on the forum stated above.

Thanks

Reply