Intel® FPGA SDK for OpenCL™ Standard Edition: Best Practices Guide

ID 683176
Date 9/24/2018
Document Table of Contents

3.4. Allocating Aligned Memory

When allocating host-side memories that will be used to transfer data to and from the FPGA,the memory must be at least 64-byte aligned.

Aligning the host-side memories allows direct memory access (DMA) transfers to occur to and from the FPGA and improves buffer transfer efficiency.

Attention: Depending on how the host-side memory is used, recommends to allocate more strict alignment. For example, if the allocated memory is used to create a buffer using the CL_MEM_USE_HOST_PTR flag, the memory should also be properly aligned to the data types used to access the buffer in kernel(s). For more information on the alignment requirements of host-side memory, refer to section C.3 of the OpenCL Specification version 1.2.

To set up aligned memory allocations, add the following source code to your host program:

  • For Windows:
    #define AOCL_ALIGNMENT 64
    #include <malloc.h>
    void *ptr = _aligned_malloc (size, AOCL_ALIGNMENT);

    To free up an aligned memory block, include the function call _aligned_free(ptr);

  • For Linux:
    #define AOCL_ALIGNMENT 64
    #include <stdlib.h>
    void *ptr = NULL;
    posix_memalign (&ptr, AOCL_ALIGNMENT, size);

    To free up an aligned memory block, include the function call free(ptr);

Did you find the information on this page useful?

Characters remaining:

Feedback Message