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?
Note: This question is related.
The Stack Overflow page you mention does state that:
clinfocommand reports the OpenCL version supported by your GPU.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_VERSIONbefore including the OpenCL headers.For example, if you want to target OpenCL 1.2, you would define it as follows:
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/hwlocissue 319, which diddefine CL_TARGET_OPENCL_VERSIONbeforeCL/cl_ext.h, with the following comment: