インテル® FPGA SDK for OpenCL™プロ・エディション: プログラミング・ガイド

ID 683846
日付 4/01/2019
Public
ドキュメント目次

5.5.6.4. cl_intel_fpga_host_pipe拡張機能の使用例

以下は、cl_intel_fpga_host_pipe拡張のカーネルとホストコードの例です。

カーネルコード

#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)) {
    ....
  }
}

ホストコード

....

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
  ....
}

....