Project

General

Profile

Emulating Altera OpenCL Kernels

This example steps through compiling the host program and device kernel for emulation under an x64 Linux environment. Emulating the kernel gives the benefit of being able to compile and test the OpenCL kernels on a Linux system without the overhead of synthesizing an FPGA image. There are caveats to emulation which can be found in the Intel FPGA SDK for OpenCL Programming Guide.

This example will step through emulating the hello_world example. It assumes your environment is already setup to compile for one of the MitySOM devices.

NOTE ON Altera OpenCL SDK versions past version 16.0: After Intel acquired Altera, the Quartus and OpenCL development tools were rebranded, starting at version 16.1. To account for this and support emulation and using later versions of the library, you may need to change the reference platform from "Altera" to "Intel" in any findPlatform() calls in the example projects. This can be found on line 113 of the host/src/main.cpp file of the hello_world example from version 16.0 and included with the current MitySOM-5CSX dev-kit image. If you get a message with "Unable to Find Reference Platform" there is a good chance this is the root cause.

Compiling the Host Application

First, edit the Makefile to point at the x64 Linux libraries and include the headers:
  • Change
    CXX := arm-linux-gnueabihf-g++
    to
    CXX := g++
  • Change
    INC_DIRS := ../common/inc
    to
    INC_DIRS := ../common/inc $(ALTERAOCLSDKROOT)/host/include
  • Change
    LIB_DIRS := 
    to
    LIB_DIRS := $(ALTERAOCLSDKROOT)/host/linux64/lib
  • Change
    LIBS := rt
    to
    LIBS := rt OpenCL
  • Change or Comment out
    AOCL_COMPILE_CONFIG := $(shell aocl compile-config --arm)
    AOCL_LINK_CONFIG := $(shell aocl link-config --arm)
    
    to
    #AOCL_COMPILE_CONFIG := $(shell aocl compile-config --arm)
    #AOCL_LINK_CONFIG := $(shell aocl link-config --arm)
    

It might be more convenient to create a new Makefile flag to support using the same Makefile and code for emulation as well as final target builds. For example, create a variable called "EMULATION", and rework the lines mentioned above with something like:

ifeq ($(EMULATION),1)
CXX := g++
else
CXX := arm-linux-gnueabihf-g++
endif

and then for emulation builds you can run

users@host:~/.../hello_world] EMULATION=1 make

Set the board file to point at the s5_ref. Source "init_opencl.sh" and make the project:

export AOCL_BOARD_PACKAGE_ROOT=$ALTERAOCLSDKROOT/board/s5_ref
source $ALTERAOCLSDKROOT/init_opencl.sh
make

The bin directory should now contain an executable named "host."

Compiling the OpenCL Kernel

Compiling the kernel is done by replacing the board target with "-march=emulator" as shown here:

aoc -march=emulator -v device/hello_world.cl -o bin/hello_world

The bin directory should now contain a compiled kernel named "hello_world.aocx."

Running the Application

In the bin directory the file list should include "host" and "hello_world.aocx"

To execute the emulation, run:

env CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 ./host

CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 instructs "host" to include one emulated FPGA device to execute hello_world.aocx on.

The output result should be similar to the example on the MitySOM:

Querying platform for info:
==========================
CL_PLATFORM_NAME                         = Altera SDK for OpenCL
CL_PLATFORM_VENDOR                       = Altera Corporation
CL_PLATFORM_VERSION                      = OpenCL 1.0 Altera SDK for OpenCL, Version 16.0

Querying device for info:
========================
CL_DEVICE_NAME                           = EmulatorDevice : Emulated Device
CL_DEVICE_VENDOR                         = Altera Corporation
CL_DEVICE_VENDOR_ID                      = 4466
CL_DEVICE_VERSION                        = OpenCL 1.0 Altera SDK for OpenCL, Version 16.0
CL_DRIVER_VERSION                        = 16.0
CL_DEVICE_ADDRESS_BITS                   = 64
CL_DEVICE_AVAILABLE                      = true
CL_DEVICE_ENDIAN_LITTLE                  = true
CL_DEVICE_GLOBAL_MEM_CACHE_SIZE          = 32768
CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE      = 0
CL_DEVICE_GLOBAL_MEM_SIZE                = 8589934592
CL_DEVICE_IMAGE_SUPPORT                  = true
CL_DEVICE_LOCAL_MEM_SIZE                 = 16384
CL_DEVICE_MAX_CLOCK_FREQUENCY            = 1000
CL_DEVICE_MAX_COMPUTE_UNITS              = 1
CL_DEVICE_MAX_CONSTANT_ARGS              = 8
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE       = 2147483648
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS       = 3
CL_DEVICE_MEM_BASE_ADDR_ALIGN            = 8192
CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE       = 1024
CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR    = 4
CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT   = 2
CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT     = 1
CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG    = 1
CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT   = 1
CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE  = 0
Command queue out of order?              = false
Command queue profiling enabled?         = true
Using AOCX: hello_world.aocx

Kernel initialization is complete.
Launching the kernel...

Thread #2: Hello from Altera's OpenCL Compiler!

Kernel execution is complete.

One difference will be in the CL_DEVICE_NAME which should read "EmulatorDevice : Emulated Device"

Other differences will be in the GLOBAL_MEM_SIZE and other hardware specific parameters.

Add picture from clipboard (Maximum size: 500 MB)