Software Archive
Read-only legacy content
17061 Discussions

Building an OpenCL example

David_B_16
Beginner
589 Views

I have a simple OpenCL test application that woeks on a CPU and GPU, but won't build on the MIC.

I've tried the build option:

icpc vector_add.cpp -O3 -std=c++11 -I/opt/intel/opencl-1.2-3.0.56860/include -L/opt/intel/opencl-1.2-3.0.56860/lib64 -lOpenCL -lrt -o vector_add

and get the error message is : "cl.hpp(1943): error: identifier "alloca" is undefined"

When I modified the build options to:

icpc vector_add.cpp -mmic -O3 -std=c++11 -I/opt/intel/opencl-1.2-3.0.56860/include -L/opt/intel/opencl-1.2-3.0.56860/lib64 -lOpenCL -lrt -o vector_add

I get the following error message:
x86_64-k1om-linux-ld: skipping incompatible /opt/intel/opencl-1.2-3.0.56860/lib64/libOpenCL.so when searching for -lOpenCL
x86_64-k1om-linux-ld: cannot find -lOpenCL

I am using the 13.1 compiler and assumed it it was making a 64bit version, which should be compatible with the with intel 64bit libOpenCL.so

Below is the makefile.

CC=icpc

CCFLAGS=-mmic -O3 -std=c++11 -I/opt/intel/opencl-1.2-3.0.56860/include

LIBS = -L/opt/intel/opencl-1.2-3.0.56860/lib64 -lOpenCL -lrt


vector_add: vector_add.cpp
    $(CC) $^ $(CCFLAGS) $(LIBS) -o $@

0 Kudos
5 Replies
Vladimir_P_1234567890
589 Views

hello David,

If i understand correct ...lib64 points to regular linux host intel64  libraries you need to add path to OpenCL MIC libraries to the -L option. 

--Vladimir

0 Kudos
Sumedh_N_Intel
Employee
589 Views

Hi David, 

To  clarify on what Vladimir said: If you look within the OpenCL installation folder, you will find two sets of libraries lib64 and libmic. lib64 are host libraries where as libmic are libraries for the Intel Xeon Phi coprocessor. So, to run the application on the coprocoessor you would need to change your library path to -L/opt/intel/opencl-1.2-3.0.56860/libmic to make use of there libraries. 

0 Kudos
David_B_16
Beginner
589 Views

Vladimir,

I am still getting the same error using the MIC icpc compiler and linking libraries. Even after installing all the latest rpm's.

/opt/intel/composer_xe_2013.0.079/bin/intel64_mic/icpc vector_add.cpp -O3 -std=c++11 -I/opt/intel/opencl-1.2-3.0.56860/include -L/opt/intel/opencl-1.2-3.0.56860/libmic -L/opt/intel/composer_xe_2013.0.079/compiler/lib/mic/ -L/opt/intel/opencl-1.2-3.0.56860/lib64  -lOpenCL -lrt -o vector_add
x86_64-k1om-linux-ld: skipping incompatible /opt/intel/opencl-1.2-3.0.56860/lib64/libOpenCL.so when searching for -lOpenCL
x86_64-k1om-linux-ld: cannot find -lOpenCL

When I try with the standatd IntelX86 icpc compiler I get an undefined alloca in the Intel cl.hpp file.

/opt/intel/composer_xe_2013.0.079/bin/intel64/icpc vector_add.cpp -O3 -std=c++11 -I/opt/intel/opencl-1.2-3.0.56860/include -L/opt/intel/opencl-1.2-3.0.56860/libmic -L/opt/intel/composer_xe_2013.0.079/compiler/lib/mic/ -L/opt/intel/opencl-1.2-3.0.56860/lib64  -lOpenCL -lrt -o vector_add
/opt/intel/opencl-1.2-3.0.56860/include/CL/cl.hpp(1945): error: identifier "alloca" is undefined
          cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));


David

0 Kudos
Yuri_K_Intel
Employee
589 Views
Hi David, You should not use MIC icpc compiler (or use -mmic option) to build an OpenCL application. When you use it you build an application that runs natively on MIC, but OpenCL application should run on host system (it will then send calculations to a device according to your program). So, the 1st command in your original post looks OK to me. The questions is why do you get "undefined alloca" error. What OS are you using? I guees, the header file "alloca.h" should be in /usr/include (at least on the systems that we officially support - RHEL and SLES). And it's included in cl.hpp using #ifdef: #if defined(linux) || defined(__APPLE__) || defined(__MACOSX) You can also try to add -H compiler option to get a list of include files to see if it has been included. BTW, please post OpenCL related questions to dedicated forum - http://software.intel.com/en-us/forums/intel-opencl-sdk/ Thanks, Yuri
0 Kudos
David_B_16
Beginner
589 Views

Yuri,

The problem was I need to use C++11 but forgot to add the compile option -Dlinux which meant that the #if defined(linux) || defined(__APPLE__) || defined(__MACOSX) preprocessor returned false and alloca.h wasn't being included.

0 Kudos
Reply