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

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

5.9. Including Structure Data Types as Arguments in OpenCL Kernels

Convert each structure parameter (struct) to a pointer that points to a structure.

The table below describes how you can convert structure parameters:

Table 3.  Converting Structure Parameters to Pointers that Point to Structures
If your source code is structured as follows: Rewrite your code to resemble the following syntax:
struct Context
{
   float param1;
   float param2;
   int param3;
   uint param4;
};

__kernel void algorithm(__global float * A,
struct Context c)
{
   if (c.param3)
   {
      // statements
   }
}
struct Context
{
   float param1;
   float param2;
   int param3;
   uint param4;
};

__kernel void algorithm(__global float * A,
__global struct Context * restrict c)
{
   if (c->param3)
   {
      // Dereference through a
      // pointer and so on
   }
}
Attention: The __global struct argument points to a buffer that must be created in the host program to store the structure. To prevent pointer aliasing, include a restrict qualifier in the declaration of the pointer to the structure.