简体   繁体   中英

CMake detects a wrong version of OpenCL

Following this post , where I have used these instructions to install NVIDIA's OpenCL SDK. The clinfo tool detects a 1.2 OpenCL version correctly. However, The below CMakeLists.txt file:

cmake_minimum_required(VERSION 3.1)

project(OpenCL_Example)

find_package(OpenCL REQUIRED)
include_directories(${OpenCL_INCLUDE_DIRS})
link_directories(${OpenCL_LIBRARY})

add_executable(main main.c)
target_include_directories(main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(main ${OpenCL_LIBRARY})

copied from here , detects the wrong version of OpenCL 1.1:

-- Looking for CL_VERSION_1_1 - found
-- Found OpenCL: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2/lib/Win32/OpenCL.lib (found version "1.1")

I would appreciate it if you could help me know what is the problem and how I can resolve it.

PS1. you may use the below dummy main.c C code just for testing

#include <CL/cl.h>
#include <stdio.h>

int main() {
    printf("Hello, World! \n");
    return 0;
}

PS2. Following this Tweet , I ran the cmake.. --debug-find command and got this log . But still not sure what is the problem.

PS3. Following this Tweet , it turns out that I had installed a very outdated CUDA toolkit . Uninstalling that, now I get

-- Found OpenCL: C:/Program Files (x86)/IntelSWTools/system_studio_2020/OpenCL/sdk/lib/x86/OpenCL.lib (found version "2.2")

which is Intel's SDK. It was basically the second result on Google search " NVIDIA OpenCL SDK download", firstly being completely confusing. So I had to uninstall it and install the latest version from here. NVIDIA could at least mention that one has to install CUDA toolkit to get the OpenCL SDK!

NVidia Cuda v3.2 was released according to this on Nov 2010 and OpenCL 1.2 spec was released one year later on November 15, 2011. So I suspect cmake is detecting OpenCL 1.1 correctly.

If you have another SDK installed and you want cmake to detect OpenCL 1.2 despite having another SDKs supporting older version you need to specify that information in cmake . Otherwise it will find the first OpenCL on the search path and stop. So it should be specified find_package(OpenCL 1.2 REQUIRED) or as @squareskittles pointed find_package(OpenCL 1.2 EXACT REQUIRED) if you want exact version.

However you may need to add other SDKs paths to PATH or specify them in cmake so that it has a chance to examine other OpenCL versions. If you have a look at find cmake macros content they contain some typical search paths specified and if you have SDK installed in other not standard path you have to tell that cmake yourself. That is especially the case on Windows where you don't have standard more specific install paths for includes or libraries like for example on Linux . On Windows there is really Program Files but that is too generic and cmake would have to search through it recursively and I'm not sure if that is even supported.

I suspect you may have nvidia cuda 3.2 toolkit path added to PATH only or you specified that path in cmake only. So here would the problem lie. Adding other SDKs paths may resolve the issue.

Also I think clinfo checks runtime OpenCL installations meaning it can be any vendor OpenCL.dll which supports OpenCL 1.2 on your NVidia GPU and cmake checks in SDK's header which OpenCL version your installed SDK supports. So here can be the discrepancy. In this case you may need to install newer cuda toolkit.

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