Foad S. Farimani
Foad S. Farimani

Reputation: 14008

Getting "cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)" warning during runtime

Following this and this posts, I'm compiling the main.c code on this GitHub Gist.

Running CMake command find_package(OpenCL REQUIRED) I get this:

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

indicating that an OpenCL SDK version 2.2 was found. This is in contradiction with what I get from clinfo tool, detecting a 1.2 OpenCL for Intel's SDK/platforms. Now when running the executable I get:

cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)

My questions are:

  1. Why I get two different versions of OpenCL from CMake and clinfo?
  2. What is the warning I'm getting at runtime and how to fix that?

P.S. Here is the output of cmake .. --debug-find

Upvotes: 9

Views: 8490

Answers (2)

VojtaK
VojtaK

Reputation: 678

Adding how to do it in CMake as I am managing relatively big project with multiple targets.

If you want to add these for all targets do something like

find_package(OpenCL REQUIRED)
IF(OpenCL_FOUND)
    message("Found OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIRS}")
    message("Found path OpenCL_LIBRARY ${OpenCL_LIBRARY} and OpenCL_LIBRARIES ${OpenCL_LIBRARIES}")
    add_definitions("-DCL_HPP_TARGET_OPENCL_VERSION=220")
#CL_HPP_TARGET_OPENCL_VERSION != 100 && \
#CL_HPP_TARGET_OPENCL_VERSION != 110 && \
#CL_HPP_TARGET_OPENCL_VERSION != 120 && \
#CL_HPP_TARGET_OPENCL_VERSION != 200 && \
#CL_HPP_TARGET_OPENCL_VERSION != 210 && \
#CL_HPP_TARGET_OPENCL_VERSION != 220 && \
#CL_HPP_TARGET_OPENCL_VERSION != 300
    add_definitions("-DCL_TARGET_OPENCL_VERSION=220")
#CL_TARGET_OPENCL_VERSION != 100 && \
#CL_TARGET_OPENCL_VERSION != 110 && \
#CL_TARGET_OPENCL_VERSION != 120 && \
#CL_TARGET_OPENCL_VERSION != 200 && \
#CL_TARGET_OPENCL_VERSION != 210 && \
#CL_TARGET_OPENCL_VERSION != 220 && \
#CL_TARGET_OPENCL_VERSION != 300
     include_directories(${OpenCL_INCLUDE_DIRS})
ENDIF()

Note that I am also using CL_HPP_TARGET_OPENCL_VERSION for C++ bindings. The version might be different from CL_TARGET_OPENCL_VERSION but it is not the best idea I guess.

Now if you want to do it on the target level and e.g. specify OpenCL 1.2 version which is now considered deprecated you can do this

target_compile_definitions(target PUBLIC CL_USE_DEPRECATED_OPENCL_1_2_APIS)
target_compile_definitions(target PUBLIC CL_TARGET_OPENCL_VERSION=120)
target_compile_definitions(target PUBLIC CL_HPP_TARGET_OPENCL_VERSION=120)

Upvotes: 2

doqtor
doqtor

Reputation: 8484

OpenCL version in SDK and reported by clinfo are 2 different things:

  • clinfo reports OpenCL version supported by your GPU
  • SDK OpenCL version is the max version supported by SDK

Now if you use in your program OpenCL 2.0 and your GPU supports OpenCL 1.2 then I would suspect one of the CL functions will report error or the program will have undefined behavior. You can set the target OpenCL version in your program using #define CL_TARGET_OPENCL_VERSION <version>, for example

#define CL_TARGET_OPENCL_VERSION 120

and then the API above target version shouldn't be available.

Upvotes: 5

Related Questions