CMAke can not find opencl sdk by NVIDA

Deadly 提交于 2019-12-11 02:39:08

问题


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

I came accress some problems:

1- FinedOpenCl.cmake doesn't work since opencl_dir is not set by nvida 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 application.

My questions:

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

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


回答1:


  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 :)




回答2:


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




回答3:


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..



来源:https://stackoverflow.com/questions/28346403/cmake-can-not-find-opencl-sdk-by-nvida

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!