Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

Clarity regarding Altera OpenCL basics

Hi all,

I started my foray into OpenCL through GPUs, such as nVIDIA or AMD graphics cards. However I've recently moved onto research using FPGAs.

Unfortunately even after querying the usual suspects (aocl_programming.pdf, Altera's online tutorials, etc.) I find myself no closer to understanding it.

Usually when I install an OpenCL platform, I'd need to install an .icd into /etc/OpenCL/vendors (Ubuntu) or HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors (Windows), which is used by the ICD loader to load the specific platform's library. This is true for Intel, nVidia and AMD, as far as I am aware.

However this is not the case with the Altera OpenCL SDK? How does it define OpenCL functions (eg. clGetPlatformID(), etc.) if it does not even have the libOpenCL.so (in the Linux case) library?

I've checked around if any of the libraries libalteracl.so act as stand-ins, but think I've just confused myself further.

My confusion arises from the fact that the examples I've downloaded from Altera (written in C++) look similar to the code I've written when programming OpenCL for nVidia or AMD GPUs.

When initializing contexts they call the exact same functions (eg. clGetDeviceInfo(), etc.), and these examples compile and execute just fine. However when I code my own host utility programs (written in C), the GCC spits out that several basic utility OpenCL functions are undefined:

undefined reference to `clGetPlatformIDs'
undefined reference to `clGetPlatformInfo'
undefined reference to `clReleaseKernel'
undefined reference to `clReleaseProgram'
undefined reference to `clReleaseCommandQueue'
undefined reference to `clReleaseContext'

What did I miss? I know that the host-side code must be compiled with GCC; I've done this all before with GPUs, but what is the difference when using Altera's OpenCL SDK?

Regards,

Victor

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    As you said, the Altera OpenCL SDK does not use the ICD loader. You instead have to link to the library instead. My guess is you are probably including the header, cl.h or cl.hpp, but you are forgetting the link flag for compilation. It should look something like this:

    
    g++ -lOpenCL main.cpp
    

    Regards,

    Smith
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Smith,

    Thank you for your reply. I could not find the libOpenCL.so, which is what I'd usually expect to be provided by the Altera BSPs or the Altera OpenCL SDK environment.

    I say that from experience using the AMD and nVidia OpenCL platforms. They would usually have libOpenCL.so and then the Installable Client Driver loader would check for the vendor-specific .icd file to load the right libOpenCL.so.

    In the Altera OpenCL environment instead, I see that the Altera OpenCL SDK links using the following libraries in my environment:

    >> aocl ldlibs
    -lalteracl -ldl -lacl_emulator_kernel_rt  -lalterahalmmd -laltera_apb_14_0_mmd -lelf -lrt -lstdc++

    I compile OpenCL host code perfectly fine when it is written in C++, but I run into problems as stated in my first post when I use C code.

    Surely the case cannot be that Altera's OpenCL environment does not support host code written in C?

    I have never run into this problem compiling host code on AMD or nVidia's OpenCL development environments.

    I am using a Terasic DE5-Net board. the libaltera_apb_14_0_mmd.so is provided from Terasic's BSP, and the rest from the s5_ref Stratix V BSP from Altera, if I understand correctly.

    Kind regards,

    Victor
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Victor,

    There are two things you want to look for when currently compiling and linking with the Altera SDK for OpenCL: ldflags and ldlibs. Below are the ldflags and ldlibs for my Windows environment with a Bittware BSP.

    >> aocl ldflags

    /libpath:C:\altera\14.0\hld\board\bittware/windows64/lib /libpath:C:/altera/14.0/hld/host/windows64/lib

    >> aocl ldlibs

    alterahalmmd.lib altera_s5phq_mmd.lib alteracl.lib acl_emulator_kernel_rt.lib pkg_editor.lib libelf.lib acl_hostxml.lib

    Yours should be similar except replace the Bittware BSP directory with your Terasic equivalent, and likewise for the altera_s5phq_mmd.lib.

    Obviously it would be nicer if we supported the cl_khr_icd extension to OpenCL so things would be more seamless. We are working on improving such user experience features and appreciate your feedback.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi all,

    Thank you for the continued support. I managed to find out what was going on, and embarrassingly admit that I made a mistake in some post-scripts in the makefile of my C files, whereas the makefile for my C++ files was correct.

    It is curious that the Altera OpenCL SDK does not use the libOpenCL.so and so linking with the -lOpenCL flag is useless, but I guess that just comes with the unfamiliarity as I migrate over to OpenCL development in FPGAs.

    Now I usually link with

    >> aocl link-config
    -L/opt/altera/14.0/hld/board/terasic/de5net/linux64/lib -L/opt/altera/14.0/hld/host/linux64/lib -lalteracl -ldl -lacl_emulator_kernel_rt  -lalterahalmmd -laltera_apb_14_0_mmd -lelf -lrt -lstdc++

    and the compilation goes ahead just fine.

    As I said, the problem was in some silly mistake in some post-script. On the positive side, this counts as an enlightening experience, more or less, haha.

    Thank you again for the insight,

    Victor