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

ID 683342
Date 4/22/2019
Public
Document Table of Contents

5.4.5.3.1. Implementing Nonblocking Channel Reads

Perform nonblocking reads to facilitate applications where data is not always available and the operation should not wait for data to become available.
The nonblocking read signature is similar to a blocking read. However, it populates the address pointed to by the bool pointer valid indicating whether a read operation successfully read data from the channel.

On a successful read (valid set to true), the value read from the channel is returned by the read_channel_nb_intel function. On a failed read (valid set to false), the return value of the read_channel_nb_intel function is not defined.

To implement a blocking channel write, use the following read_channel_nb_intel function signature:
<type> read_channel_nb_intel(channel <type> channel_id, bool * valid);
The following code snippet demonstrates the use of the nonblocking channel read extension:
channel long chan;

__kernel void kernel_read_channel (__global long * dst) {
  int i = 0;
  while (i < N) {
    bool valid0, valid1;
    long data0 = read_channel_nb_intel(chan, &valid0);
    long data1 = read_channel_nb_intel(chan, &valid1);
    if (valid0) {
       process(data0);
    }
    if (valid1) {
       process(data1); 
    } 
  }
}