Intel® FPGA SDK for OpenCL™ Pro Edition: Programming Guide

ID 683846
Date 12/19/2022
Public
Document Table of Contents

5.5.6.4. Example Use of the cl_intel_fpga_host_pipe Extension

The following are the example kernel and host codes of the cl_intel_fpga_host_pipe extension:

Kernel Code

#pragma OPENCL EXTENSION cl_intel_fpga_host_pipe : enable

kernel void reader(__attribute__((intel_host_accessible)) 
                   __read_only pipe ulong4 host_in) {
  ulong4 val;
  if (read_pipe(host_in, &val)) {
    ....
  }
  ....
}

kernel void writer(__attribute__((intel_host_accessible)) 
                   __write_only pipe ulong4 device_out) {
  ulong4 val;
  ....
  if (write_pipe(device_out, &val)) {
    ....
  }
}

Host Code

....

cl_kernel read_kern = clCreateKernel(program, "reader", NULL);

cl_kernel write_kern = clCreateKernel(program, "writer", NULL);

cl_mem read_pipe = clCreatePipe(context, CL_MEM_HOST_READ_ONLY,
                                sizeof( cl_ulong4 ), 128,
								// Number of packets that can be buffered
                                NULL, &error);

cl_mem write_pipe = clCreatePipe(context, CL_MEM_HOST_WRITE_ONLY, 
                                 sizeof( cl_ulong4 ), 64,
								 // Number of packets that can be buffered
                                 NULL, &error);

// Bind pipes to kernels
clSetKernelArg(read_kern, 0, sizeof(cl_mem), (void *)&write_pipe);
clSetKernelArg(write_kern, 0, sizeof(cl_mem), (void *)&read_pipe);

// Enqueue kernels
....

cl_ulong4 val
if (!clReadPipeIntelFPGA (read_pipe, &val)) {
  cl_int result = clWritePipeIntelFPGA (write_pipe, &val);
  // Check write success/failure and handle
  ....
}

....