“CL_TARGET_OPENCL_VERSION is not defined” – 为什么会出现这个错误?

huangapple go评论53阅读模式
英文:

"CL_TARGET_OPENCL_VERSION is not defined" - why should I get this?

问题

最近的CUDA版本 - 至少是12.1,可能也包括12.0 - 在编译时使用OpenCL头文件会收到一个警告消息:

#pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)")

事实上,我没有定义CL_TARGET_OPENCL_VERSION。但是 - 为什么我要定义呢?我已经使用OpenCL工作了很多年,一直以来的习惯是头文件对默认版本进行了隐式假设,如果我想要其他版本,我会明确表示。

为什么现在要求/期望我明确定义这个呢?

英文:

With recent CUDA versions - 12.1 for sure, probably 12.0 as well - I get a warning message when compiling against the OpenCL headers:

#pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)")

Indeed, I haven't defined CL_TARGET_OPENCL_VERSION. But - why should I? I've worked with OpenCL for quite a few years, and the custom/standard has been that the headers make implicit assumptions about default versions, and if I want something else then I actively say so.

Why is it now required/expected for me to define this explicitly?


<sub>Note: This question is related.</sub>

答案1

得分: 1

以下是翻译好的内容:

  • clinfo命令报告您的GPU支持的OpenCL版本。
  • SDK中的OpenCL版本是SDK支持的最高版本。

如果您的程序使用的OpenCL版本高于GPU支持的版本(例如,在GPU支持OpenCL 1.2时使用OpenCL 2.0),可能会遇到错误或未定义的行为。

为了避免这种情况,您可以在包含OpenCL头文件之前通过定义CL_TARGET_OPENCL_VERSION来明确设置程序的目标OpenCL版本。
例如,如果您想要目标OpenCL 1.2,可以定义如下:

#define CL_TARGET_OPENCL_VERSION 120
#include <CL/cl.h>

这确保您的程序不会无意中使用GPU不支持的OpenCL版本的功能。

例如,open-mpi/hwloc问题319中有示例,该问题在包含CL/cl_ext.h之前定义了CL_TARGET_OPENCL_VERSION,并包含了以下注释:

opencl: hide OpenCL warning about unspecified target API

Latest OpenCL warn unless CL_TARGET_OPENCL_VERSION defines the API revision that we want.

Set it to 220 (current default, and first revision that looks at this).

  • Older versions would enable some deprecated functions.
  • Later versions may not be supported by all installations that look at CL_TARGET_OPENCL_VERSION.

We only use basic functions that have existed for ever anyway.

英文:

The Stack Overflow page you mention does state that:

  • the clinfo command reports the OpenCL version supported by your GPU.
  • the OpenCL version in the SDK is the maximum version supported by the SDK.

If your program is using a higher version of OpenCL than what your GPU supports (e.g., using OpenCL 2.0 when your GPU supports OpenCL 1.2), you might encounter errors or undefined behavior.

To avoid this, you can explicitly set the target OpenCL version in your program by defining CL_TARGET_OPENCL_VERSION before including the OpenCL headers.
For example, if you want to target OpenCL 1.2, you would define it as follows:

#define CL_TARGET_OPENCL_VERSION 120
#include &lt;CL/cl.h&gt;

This ensures that your program does not inadvertently use features from a version of OpenCL that is not supported by your GPU.

This is illustrated for instance in open-mpi/hwloc issue 319, which did define CL_TARGET_OPENCL_VERSION before CL/cl_ext.h, with the following comment:

> ## opencl: hide OpenCL warning about unspecified target API
>
> Latest OpenCL warn unless CL_TARGET_OPENCL_VERSION defines the API revision that we want.
>
> Set it to 220 (current default, and first revision that looks at this).
>
> - Older versions would enable some deprecated functions.
> - Later versions may not be supported by all installations that look at CL_TARGET_OPENCL_VERSION.
>
> We only use basic functions that have existed for ever anyway.

huangapple
  • 本文由 发表于 2023年5月25日 15:57:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定