Intel® FPGA SDK for OpenCL™ Pro Edition: Getting Started Guide

ID 683188
Date 12/19/2022
Public
Document Table of Contents

3.6.4. Emulating Your OpenCL Kernel

To emulate your OpenCL™ kernel, run the emulation .aocx file on the platform on which you built your kernel. The OpenCL Emulator uses a different OpenCL platform than when targeting FPGA hardware.

To emulate your kernel, perform the following steps:

To run the host application for emulation, invoke the env CL_CONFIG_CPU_EMULATE_DEVICES=<number_of_devices> <host_application_filename> command.
This command specifies the number of identical emulation devices that the Emulator needs to provide. By default, the emulator platform provides a single emulator device. Therefore, if your host code requires only a single device, you do not need to set the CL_CONFIG_CPU_EMULATE_DEVICES environment variable.

For the hello_world design example, run bin/host -emulator. The -emulator argument informs the host program to select the Intel® FPGA Emulation Platform for OpenCL.

Upon successful emulation of your kernel, you see the following output:
...
...
...

Using AOCX: hello_world.aocx

Kernel initialization is complete.

Launching the kernel...

Thread #2: Hello from Intel FPGA OpenCL Compiler!

Kernel execution is complete.
Note:
  • The emulator in Intel® FPGA SDK for OpenCL™ Pro Edition is built with GCC 7.2.0 as part of the offline compiler. When executing the host program for an emulated OpenCL device, the version of libstdc++.so must be at least that of GCC 7.2.0. In other words, the LD_LIBRARY_PATH environment variable must ensure that the correct version of libstdc++.so is found.

    If the correct version of libstdc++.so is not found, the call to clGetPlatformIDs function fails to load the FPGA emulator platform and returns CL_PLATFORM_NOT_FOUND_KHR (error code -1001). Depending on which version of libstdc++.so is found, the call to clGetPlatformIDs may succeed, but a later call to the clCreateContext function may fail with CL_DEVICE_NOT_AVAILABLE (error code -2).

    If LD_LIBRARY_PATH does not point to a sufficiently new libstdc++.so, use the following syntax to invoke the host program:

    env LD_LIBRARY_PATH=<path to sufficiently new libstdc++.so>:$LD_LIBRARY_PATH <host> [host arguments]
  • To enable debugging of kernel code, optimizations are disabled by default for the FPGA emulator. This can lead to sub-optimal execution speed when emulating kernel code.

    You can pass the -g0 flag to the aoc compile command to disable debugging and enable optimizations. This enables faster emulator execution.