ARM-software / ComputeLibrary

The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
MIT License
2.76k stars 767 forks source link

A problem when compiling opencl application. #986

Closed shumeigiku closed 1 year ago

shumeigiku commented 2 years ago

Hi all,

I want to compile an OpenCL-based application on Ubuntu (I find it doesn't have any OpenCL files), and pass it to an Arm device (with Linux kernel, not Android) to execute.

First I compile the compute library with the following commands: scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=linux arch=arm64-v8a

Then I compile the file, but get an error: /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: cannot find -lOpenCL

I follow the issue here (https://github.com/ARM-software/ComputeLibrary/issues/133), and realize that I don't have the "opencl-1.2-stubs" folder. Also, Libopencl.so is not found under the /usr/lib/aarch64-linux-gnu/

So, if I want to fix the error, where can I get the Libopencl.so, and the folder? If I get them, will the error be fixed?

Any suggestions and comments are helpful.

Sincerely, Shumeigiku

morgolock commented 2 years ago

Hi @shumeigiku

Could you please share the command you used to build the application?

Please refer to the documentation for instructions on how to build the examples

Make sure you use tell the linker to link against -larm_compute -larm_compute_core as shown below: aarch64-linux-gnu-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -larm_compute_core -o cl_sgemm -DARM_COMPUTE_CL

Hope this helps.

shumeigiku commented 2 years ago

Hi morgolock,

Make sure you use tell the linker to link against -larm_compute -larm_compute_core as shown below: aarch64-linux-gnu-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -larm_compute_core -o cl_sgemm -DARM_COMPUTE_CL

Yes, it passes when I append a "-LComputeLibrary-main/build". But when I build an application with "-lOpenCL", it goes wrong. Here are partial commands:

CC= aarch64-linux-gnu-g++ SOURCE_FILE= xxx.cpp CC_FLAGS= -g -O3 MY_INCLUDE= -I. -Iinclude -IComputeLibrary-main/include MY_LIB= -larm_compute-static -larm_compute_core-static -lOpenCL MY_LINK= -LComputeLibrary-main/build

$(CC) $(CC_FLAGS) -fopenmp $(SOURCE_FILE) -o xxx.out $(MY_INCLUDE) $(MY_LIB) $(MY_LINK)

I think it is because I don't have the libopencl.so in the "MY_LINK" (I cannot find it in the built computelibrary). I think it may be fixed by a correct Mali OpenCL SDK, but I cannot find where to download it.

Can you help me?

Sincerely, Shumeigiku

shumeigiku commented 2 years ago

I find some similar issue here (https://community.arm.com/support-forums/f/graphics-gaming-and-vr-forum/9417/mali-opencl-sdk-not-found). Seems that the Mali OpenCL SDK is disappeared.

Also, I forget to provide what I want to do with ComputeLibrary. Here is my purpose: I want to compile some OpenCL applications and run them on Arm FVP's Mali G76 GPU.

morgolock commented 2 years ago

Hi @shumeigiku

You don't need to specify -lOpenCL

First build the library: PATH=$JENKINS_TOOLCHAINS/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/:$PATH scons arch=armv8a neon=1 opencl=1 validation_tests=0 examples=0 benchmark_examples=0 opencl=1 standalone=0 examples=0 -j18

This will build the library binaries in the build folder

Then build the cl example: user@host:~/work/acl/ComputeLibrary$ PATH=$JENKINS_TOOLCHAINS/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/:$PATH aarch64-linux-gnu-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -larm_compute_core -L./build -o cl_sgemm -DARM_COMPUTE_CL

Hope this helps.

shumeigiku commented 2 years ago

Hi morgolock,

Yeah in the example applications I will not use the -lOpenCL option. But, when I build some real applications (e.g., a GPU benchmark), they may use this option. I initially think something wrong in ComputeLibrary, but now I realize it is because the lack of libopencl.so

Thus, can you help me to get the Mali OpenCL SDK (if better, v1.2) for ubuntu/android? If not, I may close this question.

morgolock commented 1 year ago

Hi @shumeigiku

The error /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: cannot find -lOpenCL suggests the linker cannot find libOpenCL.so.

Try to locate where is this file in your file-system and then just use -L/path/to/libOpenCL.so in your build command to let the linker know the path to this file.

Hope this helps.

shumeigiku commented 1 year ago

Thanks.