CMake检测到错误版本的OpenCL [英] CMake detects a wrong version of OpenCL

查看:225
本文介绍了CMake检测到错误版本的OpenCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章之后,我在其中使用过这些说明,以安装NVIDIA的OpenCL SDK。 clinfo 工具可以正确检测到1.2 OpenCL版本。但是,下面的 CMakeLists.txt 文件:

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

在此检测到错误的OpenCL 1.1版本:

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 。您可以使用下面的虚拟 main.c C代码用于测试

P.S.1. 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。以下是此推文,我运行了 cmake .. --debug-find 命令,并得到此日志。但是仍然不确定是什么问题。

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

PS3。按照此推文,结果证明我已经安装了一个非常过时的CUDA工具包。卸载后,现在我得到

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


-找到OpenCL:C:/ Program Files(x86)/ IntelSWTools / system_studio_2020 / OpenCL / sdk / lib / x86 / OpenCL.lib(找到的版本为 2.2)

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

这是Intel的SDK。基本上,这是谷歌搜索 NVIDIA的OpenCL SDK下载,首先是完全乱了套。因此,我必须将其卸载并从此处安装最新版本。 NVIDIA至少可以说一个人必须安装CUDA工具箱才能获得OpenCL SDK!

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 于11月根据发布2010年和 OpenCL 1.2 规范在一年后的2011年11月15日发布。所以我怀疑 cmake 正在检测 OpenCL 1.1 正确。

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.

如果安装了另一个SDK,并且想要 cmake 来检测 OpenCL 1.2 ,尽管还有其他支持较早版本的SDK,您仍需要在 cmake 中指定该信息。否则,它将在搜索路径中找到第一个 OpenCL 并停止。因此,应将其指定为 find_package(需要OpenCL 1.2)或如@squareskittles所指出的那样 find_package(需要OpenCL 1.2完全正确)您想要确切的版本。

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.

但是,您可能需要将其他SDK路径添加到PATH或在 cmake 中指定它们检查其他 OpenCL 版本。如果您查看查找 cmake 宏的内容,它们将包含一些指定的典型搜索路径,并且您是否在其中安装了SDK其他非标准路径,您必须告诉cmake自己。在 Windows 上尤其如此,您没有标准的包含或库的更具体安装路径,例如在 Linux 。在 Windows 上确实有 Program Files ,但这太通用了,cmake必须递归地搜索它,而我我不确定您是否支持它。

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.

我怀疑您可能已将 nvidia cuda 3.2工具包路径添加到PATH仅或您仅在cmake中指定了该路径。因此,问题就出在这里。添加其他SDK路径可能会解决问题。

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.

我还认为 clinfo 检查运行时 OpenCL 安装意味着它可以是任何供应商 OpenCL.dll ,它们可以在NVidia GPU和 cmake 检入SDK的标头,其中表示您所安装的SDK支持的 OpenCL 版本。因此,这可能是差异。在这种情况下,您可能需要安装更新的cuda工具包。

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.

这篇关于CMake检测到错误版本的OpenCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆