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

ID 683846
Date 10/04/2021
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

11.1.6. Specifying an OpenCL Library when Compiling an OpenCL Kernel

To use an OpenCL™ library in an OpenCL kernel, specify the library file name and directory when you compile the kernel.
Important: Using a library does not reduce kernel compilation time.
To specify an OpenCL library to the Intel® FPGA SDK for OpenCL™ Offline Compiler, invoke the following command: aoc -l <library_file_name>.aoclib [-L <library directory>] <kernel file name>.cl
where the -l <library_file_name>.aoclib command option specifies the library file name, and the -L <library directory> command option specifies the directory containing the library files.

You may include multiple instances of -l <library file name> and -L <library directory> in the offline compiler command.

For example, if you create a library that includes the functions my_div_fd(), my_sqrtfd(), and myrsqrtfd(), the OpenCL kernel code might resemble the following:

#include “lib_header.hcl”

kernel void test_lib (
    global double * restrict in,
    global double * restrict out,
    int N) {
        int i = get_global_id(0);
        for (int k =0; k < N; k++) {
            double x = in[i*N + k];
            out[i*N + k] = my_divfd
                (my_rsqrtfd(x),
                my_sqrtfd(my_rsqrtfd (x)));
        }
}  
Note: Library-related lines are highlighted in bold.

The corresponding lib_header.h file might resemble the following:

double my_sqrtfd (double x);
double my_rsqrtfd(double x);
double my_divfd(double a, double b);