简体   繁体   中英

CMake can not find opencl sdk by NVIDA

I just installed NVIDIA CUDA tool kit to use it for developing the OpenCL application on windows 8.1.

I came across some problems:

1- FinedOpenCl.cmake doesn't work since opencl_dir is not set by the Nvidia tool kit.

cmake file is:

FIND_PACKAGE(OpenCL REQUIRED)
INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIR})

and cmake error is:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
  Could NOT find OpenCL (missing: OPENCL_LIBRARY OPENCL_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindOpenCL.cmake:35 (find_package_handle_standard_args)
  CMakeLists.txt:5 (FIND_PACKAGE)

2- There is no cl.hpp for c++ interface.

3- Headers and libraries are on different directories and hence it is difficult to use them with the application.

My questions:

1- Is there anything that I can do to solve them?

2- Is there any option during setup that does the required setting automatically.

  1. There is no standard FindOpenCl.cmake, so I don't know what file you are using, but in my code I search in a bunch of different folders, including these:
$ENV{OPENCL_DIR}
$ENV{NVSDKCOMPUTE_ROOT}     # NVIDIA on Windows
$ENV{CUDA_PATH_V6_5}
$ENV{CUDA_PATH}

In addition, I have seen some trouble depending on whether the paths has a final '\\' or not - it seems like some kind of bug in CMake, where it fails to automatically handle both situations. So try adding a backslash to your environment variables.

  1. That's a fact - NVIDIA simply doesn't include cl.hpp, but you can download it from Khronos: https://www.khronos.org/registry/cl/api/1.1/cl.hpp .
  2. This should also be handled by the FindOpenCl.cmake - if not, you will have to write your own, or find one that sets up the include and lib variables properly.

Finally, there is no secret option to fix any of these during installation :)

Using definitions found here: http://www.cmake.org/cmake/help/v3.1/module/FindOpenCL.html

Try the below (I did a quick test on Windows 10 Pro and Ubuntu 14.04LTS):

FIND_PACKAGE(OpenCL REQUIRED)

INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIRS}) 

LINK_DIRECTORIES(${OpenCL_LIBRARY})

You may also want to check: How to add header file path in CMake file

You can run cmake with additional -D options, like:

cmake [some_your_options] -DOpenCL_LIBRARY=/cygdrive/c/cuda/lib -DOpenCL_INCLUDE_DIR=/cygdrive/c/cuda/include [some_your_other_options] .....

So it will see OpenCL such manually specified paths.

Upper example provided for my CygWin64 , where in the folder C:\\cygdrive I added several symbolic links by mklink for all needed logical drives before, so "c" links to "C:\\" , "d" links to "D:\\" and so on.

My NVidia CUDA install path is really C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\ , but it is not very handy, so I also maked symlink ( mklink /D linkname "path" ) on C: named "cuda", so /cygdrive/c/cuda/lib is really points to C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\lib .

Unix environment emulation on windows and compiling in command promt is very tricky, yes..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM