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

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

5.3. Programming Strategies for Optimizing Pointer-to-Local Memory Size

When using a pointer-to-local kernel argument to create a local memory allocation, the Intel® FPGA SDK for OpenCL™ Offline Compiler must decide at compilation time (not runtime) on the size of the local memory system to build on the FPGA. You can optimize the memory size by specifying the size that you will request at runtime using clSetKernelArg. This specification allows the offline compiler to build the correctly sized local memory system for the pointer argument. If you do not specify a size, the offline compiler will use the default size.
To specify a size other than the default of 16 kilobytes (kB), include the local_mem_size(N) attribute in the pointer declaration within your kernel source code.
The value N specifies the desired memory size in bytes. For efficiency, N should be a power of two.
For example:
__kernel void myLocalMemoryPointer(
                  __local float * A,
                  __attribute__((local_mem_size(1024))) __local float * B,
                  __attribute__((local_mem_size(32768))) __local float * C)
{
	//statements
}

In the myLocalMemoryPointer kernel, 16 kB of local memory (default) is allocated to pointer A, 1 kB is allocated to pointer B, and 32 kB is allocated to pointer C.

Attention: Instead of using point-to-local kernel arguments, Intel® recommends that you define local memory systems within the kernel scope.