Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16597 Discussions

Got CL_INVALID_BINARY error when emulated HelloWorld example on Windows

Altera_Forum
Honored Contributor II
4,362 Views

I followed the "aocl_getting_started.pdf" instruction to implement the hello_world example on Window. But I got error message about CL_INVALID_BINARY when I tried to run the emulator. 

 

 

The steps that I've done are as following: 

 

 

1. "%ALTERAOCLSDKROOT%\init_opencl.bat", set environment. 

 

 

2. "aoc -march=emulator -v --board s5_ref device/hello_world.cl -o bin/hello_world.aocx", built hello_world.aocx file successlly. 

 

 

3. "set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 host.exe"  

 

 

4. Built host program(host.exe) from Visual Studio 2010 successlly. 

 

 

5. Under folder hello_world\bin. Run host.exe on cmd, and get the error message as the image in the attachment. 

 

Using AOCX: hello_world.aocx 

Context callback: Invalid binary. 

ERROR: CL_INVALID_BINARY 

Location: ..\common\src\AOCLUtils\opencl.cpp:392 

Failed to create program with binary 

 

Is there any step I missed? Please advice.  

Thank you.
0 Kudos
12 Replies
Altera_Forum
Honored Contributor II
2,276 Views

You should run your host code using the following command: 

 

env CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 host.exe 

 

Or run "set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1" in the same command window right before running your host code. The way it is, the host code is trying to use your integrated GPU (iGPU) which obviously wouldn't work using the FPGA emulator binary.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

 

--- Quote Start ---  

You should run your host code using the following command: 

 

env CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 host.exe 

 

Or run "set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1" in the same command window right before running your host code. The way it is, the host code is trying to use your integrated GPU (iGPU) which obviously wouldn't work using the FPGA emulator binary. 

--- Quote End ---  

 

 

Hi,  

Thanks for the reply. 

I tried "env CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 host.exe", but the command window showed "'env' is not an internal or external command". So I tried to run "set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1", and execute host.exe right away (in the same command window). However, I still got the same error message about CL_INVALID_BINARY.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

Apparently the "env" command does not work on windows, but the "set" command should. Can you post the output of the command window when you first run "set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1" and then the host code?

0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

Commands and results are as following: 

 

 

C:\Users\1705061\exm_opencl_hello_world_x64_windows\hello_world\bin>set CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 

 

C:\Users\1705061\exm_opencl_hello_world_x64_windows\hello_world\bin>host.exe 

Querying platform for info: 

========================== 

CL_PLATFORM_NAME = Intel(R) OpenCL 

CL_PLATFORM_VENDOR = Intel(R) Corporation 

CL_PLATFORM_VERSION = OpenCL 2.0 

 

Querying device for info: 

======================== 

CL_DEVICE_NAME = Intel(R) HD Graphics 520 

CL_DEVICE_VENDOR = Intel(R) Corporation 

CL_DEVICE_VENDOR_ID = 32902 

CL_DEVICE_VERSION = OpenCL 2.0 

CL_DRIVER_VERSION = 20.19.15.4331 

CL_DEVICE_ADDRESS_BITS = 64 

CL_DEVICE_AVAILABLE = true 

CL_DEVICE_ENDIAN_LITTLE = true 

CL_DEVICE_GLOBAL_MEM_CACHE_SIZE = 524288 

CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE = 64 

CL_DEVICE_GLOBAL_MEM_SIZE = 1360632218 

CL_DEVICE_IMAGE_SUPPORT = true 

CL_DEVICE_LOCAL_MEM_SIZE = 65536 

CL_DEVICE_MAX_CLOCK_FREQUENCY = 1000 

CL_DEVICE_MAX_COMPUTE_UNITS = 24 

CL_DEVICE_MAX_CONSTANT_ARGS = 8 

CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE = 65536 

CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = 3 

CL_DEVICE_MEM_BASE_ADDR_ALIGN = 1024 

CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE = 128 

CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR = 1 

CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT = 1 

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 

Context callback: Invalid binary. 

ERROR: CL_INVALID_BINARY 

Location: ..\common\src\AOCLUtils\opencl.cpp:392 

Failed to create program with binary 

 

C:\Users\1705061\exm_opencl_hello_world_x64_windows\hello_world\bin>
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

It is still trying to use your GPU. The GPU should not be detected at all if the host code is compiled correctly; you probably have made some mistake in compiling your host code. 

 

Still, try this: 

 

host\src\main.cpp, line 136, change: 

 

devices.reset(getDevices(platform, CL_DEVICE_TYPE_ALL, &num_devices)); 

 

with: 

 

devices.reset(getDevices(platform, CL_DEVICE_TYPE_ACCELERATOR, &num_devices)); 

 

And see if it detects Altera's emulated device instead. If it doesn't find anything, then you have made some mistake in compiling/linking the host code.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

This is the result after I modified main.cpp and re-complied. 

 

C:\Users\1705061\exm_opencl_hello_world_x64_windows\hello_world\bin>host.exe 

Querying platform for info: 

========================== 

CL_PLATFORM_NAME = Intel(R) OpenCL 

CL_PLATFORM_VENDOR = Intel(R) Corporation 

CL_PLATFORM_VERSION = OpenCL 2.0 

 

ERROR: CL_DEVICE_NOT_FOUND 

Location: ..\common\src\AOCLUtils\opencl.cpp:356 

Query for number of devices failed 

 

 

The instruction mentioned "Link your host application to the libraries returned by the aocl linkflags utility command.", but didn't point out how to link... 

May I ask how to link the host.exe with libraries? 

This is the result after run "aocl linkflages". 

 

C:\Users\1705061\exm_opencl_hello_world_x64_windows\hello_world\bin>aocl linkflags 

/libpath:C:\intelFPGA\17.0\hld\board\s5_ref/windows64/lib /libpath:C:/intelFPGA/17.0/hld/host/windows64/lib altera_s5_ref_mmd.lib alteracl.lib acl_emulator_kern 

el_rt.lib pkg_editor.lib libelf.lib acl_hostxml.lib 

 

 

Thank you.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

You should put the output of that command in the linker settings of visual studio. Though, if you don't do this, compilation should fail. Don't you get any warning or errors during compilation of the host code? It seems to me that you are compiling the host code against some other OpenCL SDK (maybe AMD's or Intel's CPU SDK?) or else non-FPGA devices should not at all be detected when you compile using Altera's OpenCL SDK. 

 

Unfortunately I do not have my FPGA environment set up on Windows and hence, I cannot give you exact instructions.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

Hi,  

 

Thanks for the hint. I removed the OpenCL.lib which was added by project's default in Visual Studio and kept other libraries I've added before, then it works!
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

I am facing same issue. If I remove the OpenCL.lib compilation is now failing - as now the cl<Funcs> are not found.  

 

1>ClCompile: 

1> options.cpp 

1> opencl.cpp 

1> main.cpp 

1> Generating Code... 

1>main.obj : error LNK2019: unresolved external symbol clFinish referenced in function main 

1>main.obj : error LNK2019: unresolved external symbol clEnqueueNDRangeKernel referenced in function main 

1>main.obj : error LNK2019: unresolved external symbol clSetKernelArg referenced in function main 

1>main.obj : error LNK2019: unresolved external symbol clCreateKernel referenced in function "bool __cdecl init(void)" (?init@@YA_NXZ) 

1>main.obj : error LNK2019: unresolved external symbol clBuildProgram referenced in function "bool __cdecl init(void)" (?init@@YA_NXZ) 

1>main.obj : error LNK2019: unresolved external symbol clCreateCommandQueue referenced in function "bool __cdecl init(void)" (?init@@YA_NXZ) 

1>main.obj : error LNK2019: unresolved external symbol clCreateContext referenced in function "bool __cdecl init(void)" (?init@@YA_NXZ) 

1>main.obj : error LNK2019: unresolved external symbol clGetPlatformInfo referenced in function "bool __cdecl init(void)" (?init@@YA_NXZ) 

1>opencl.obj : error LNK2001: unresolved external symbol clGetPlatformInfo 

1>main.obj : error LNK2019: unresolved external symbol clReleaseContext referenced in function "void __cdecl cleanup(void)" (?cleanup@@YAXXZ) 

1>main.obj : error LNK2019: unresolved external symbol clReleaseCommandQueue referenced in function "void __cdecl cleanup(void)" (?cleanup@@YAXXZ) 

1>main.obj : error LNK2019: unresolved external symbol clReleaseProgram referenced in function "void __cdecl cleanup(void)" (?cleanup@@YAXXZ) 

1>main.obj : error LNK2019: unresolved external symbol clReleaseKernel referenced in function "void __cdecl cleanup(void)" (?cleanup@@YAXXZ) 

1>main.obj : error LNK2019: unresolved external symbol clGetDeviceInfo referenced in function "void __cdecl display_device_info(struct _cl_device_id *)" (?display_device_info@@YAXPEAU_cl_device_id@@@Z) 

1>opencl.obj : error LNK2001: unresolved external symbol clGetDeviceInfo 

1>opencl.obj : error LNK2019: unresolved external symbol clGetPlatformIDs referenced in function "struct _cl_platform_id * __cdecl aocl_utils::findPlatform(char const *)" (?findPlatform@aocl_utils@@YAPEAU_cl_platform_id@@PEBD@Z) 

1>opencl.obj : error LNK2019: unresolved external symbol clGetDeviceIDs referenced in function "struct _cl_device_id * * __cdecl aocl_utils::getDevices(struct _cl_platform_id *,unsigned __int64,unsigned int *)" (?getDevices@aocl_utils@@YAPEAPEAU_cl_device_id@@PEAU_cl_platform_id@@_KPEAI@Z) 

1>opencl.obj : error LNK2019: unresolved external symbol clCreateProgramWithBinary referenced in function "struct _cl_program * __cdecl aocl_utils::createProgramFromBinary(struct _cl_context *,char const *,struct _cl_device_id * const *,unsigned int)" (?createProgramFromBinary@aocl_utils@@YAPEAU_cl_program@@PEAU_cl_context@@PEBDPEBQEAU_cl_device_id@@I@Z) 

1>opencl.obj : error LNK2019: unresolved external symbol clGetEventProfilingInfo referenced in function "unsigned __int64 __cdecl aocl_utils::getStartEndTime(struct _cl_event *)" (?getStartEndTime@aocl_utils@@YA_KPEAU_cl_event@@@Z) 

1>C:\Users\mmhazra\Desktop\P-CSTN-OPNCL-16-1-v2\eg1\hello_world\bin\host.exe : fatal error LNK1120: 17 unresolved externals 

1> 

1>Build FAILED.
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

Hello  

You need to add the library name and directory which you run "aocl linkflags" command  

You can follow the step to do this  

Step1  

remove OpenCL.lib from Project->Properites->Linker->Input->Additional Dependencis  

add altera_a10_ref_mmd.lib alteracl.lib acl_emulator_kernel_rt.lib pkg_editor.lib libelf.lib acl_hostxml.lib 

 

Step2 add correspond lib's path select Project->Properites->Linker->General->Additional Library Dictories  

C:\intelFPGA_pro\17.0\hld\board\a10_ref/windows64/lib;C:/intelFPGA_pro/17.0/hld/host/windows64/lib 

 

Step3 copy the WDAPI1021.dll from your board directory to "C:\Windows\System32

EX: My reference FPGA board is a10gx so i need to copy wdapi1021.dll from "C:\intelFPGA_pro\17.0\hld\board\a10_ref\windows64\driver" directory to "C:\Windows\System32

 

After finishing the steps, you can run the host and get correct result 

Querying platform for info: 

========================== 

CL_PLATFORM_NAME = Intel(R) FPGA SDK for OpenCL(TM) 

CL_PLATFORM_VENDOR = Intel(R) Corporation 

CL_PLATFORM_VERSION = OpenCL 1.0 Intel(R) FPGA SDK for OpenCL(TM), Version 17.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 Intel(R) FPGA SDK for OpenCL(TM), Version 17.0 

CL_DRIVER_VERSION = 17.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 = 2147483648 

 

............................................................................................................ 

 

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. 

 

CL_DEVICE_IMAGE_SUPPORT = true 

 

 

 

Good luck
0 Kudos
Altera_Forum
Honored Contributor II
2,276 Views

Hi, 

 

Could you build a Hello world kernel with out emulator mode, and do an aocl program, then try to rerun the host ? 

 

Thanks, 

 

Regards, 

CloseCL 

(This message was posted on behalf of Intel Corporation)
0 Kudos
SOUMYA_D_Intel
Employee
2,276 Views

Can somebody tell me how to link the host application with the OpenCL host runtime libraries using aocl linkflags?

The guide only tells to do it, but didn't point out how to link it..

 

This is the output after running aocl linkflags:

 

C:\intelFPGA_pro\19.1\hld\examples_aoc\hello_world> aocl linkflags

/libpath:C:/intelFPGA_pro/19.1/hld/host/windows64/lib OpenCL.lib

0 Kudos
Reply