Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed parser of OpenCL 3.0 for NVIDIA GPU #2001

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions cmake/FindOpenCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,56 @@ if(opencl_root_hints)
endif()

function(_FIND_OPENCL_VERSION)
include(CheckSymbolExists)
include(CMakePushCheckState)
set(CMAKE_REQUIRED_QUIET ${OpenCL_FIND_QUIETLY})

CMAKE_PUSH_CHECK_STATE()
foreach(VERSION "2_2" "2_1" "2_0" "1_2" "1_1" "1_0")
set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}")

if(APPLE)
CHECK_SYMBOL_EXISTS(
CL_VERSION_${VERSION}
"${OpenCL_INCLUDE_DIR}/Headers/cl.h"
OPENCL_VERSION_${VERSION})
foreach(VERSION "3_0" "2_2" "2_1" "2_0" "1_2" "1_1" "1_0")
Copy link
Contributor

@densamoilov densamoilov Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(random place)

There are a few things that look suspicious to me:

  • We didn't implement FindOpenCL.cmake module, we've taken it from CMake (see here) and it still uses CHECK_SYMBOL_EXISTS and the community seems to be fine with it
  • The version macros are standardized by the OpenCL specification so if the macros are missing then it likely means that there is something wrong with the OpenCL implementation you use
  • It should be fine to check cl.h header as it includes cl_version.h header and CHECK_SYMBOL_EXISTS does perform a preprocessing

Given all this, I think the issue you encounter is somewhere on your end.

Copy link
Author

@redradist redradist Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@densamoilov Here is my OpenCL files for NVIDIA GPU:
cl_files.zip

It looks fine for me

# Write the test program to check OpenCL
set(SOURCE_CODE
"
#include <CL/cl.h>
#ifndef CL_VERSION_${VERSION}
#error \"CL_VERSION_${VERSION} is not defined\"
#endif
int main() {
return 0\;
}
")

# Create a temporary directory for the test
set(TEST_DIR "${CMAKE_BINARY_DIR}/CheckOpenCLSymbol")
file(MAKE_DIRECTORY ${TEST_DIR})

# Write the test program to a file
set(TEST_SOURCE "${TEST_DIR}/test_opencl_symbol.c")
file(WRITE ${TEST_SOURCE} ${SOURCE_CODE})
file(WRITE "${TEST_DIR}/CMakeLists.txt"
"
cmake_minimum_required(VERSION 3.8)
project(CheckOpenCLSymbol)
add_executable(TestOpenCL test_opencl_symbol.c)
target_include_directories(TestOpenCL PUBLIC ${OpenCL_INCLUDE_DIR})
target_link_libraries(TestOpenCL PUBLIC ${OpenCL_LIBRARIES})
")

# Use try_compile to check if the symbol exists
try_compile(
COMPILE_RESULT
PROJECT "CheckOpenCLSymbol"
SOURCE_DIR ${TEST_DIR}
BINARY_DIR ${TEST_DIR}
)

# Clean up temporary directory
file(REMOVE_RECURSE ${TEST_DIR})

# Output the result
if(COMPILE_RESULT)
set(OPENCL_VERSION_${VERSION} ${VERSION})
else()
CHECK_SYMBOL_EXISTS(
CL_VERSION_${VERSION}
"${OpenCL_INCLUDE_DIR}/CL/cl.h"
OPENCL_VERSION_${VERSION})
set(OPENCL_VERSION_${VERSION} "")
endif()

if(OPENCL_VERSION_${VERSION})
string(REPLACE "_" "." VERSION "${VERSION}")
set(OpenCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
Expand All @@ -73,7 +103,6 @@ function(_FIND_OPENCL_VERSION)
break()
endif()
endforeach()
CMAKE_POP_CHECK_STATE()
endfunction()

find_path(OpenCL_INCLUDE_DIR
Expand All @@ -94,8 +123,6 @@ find_path(OpenCL_INCLUDE_DIR
OpenCL/common/inc
"AMD APP/include")

_FIND_OPENCL_VERSION()

message(STATUS "Found OpenCL headers: ${OpenCL_INCLUDE_DIR}")

if(WIN32)
Expand Down Expand Up @@ -159,6 +186,8 @@ endif()
set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})

_FIND_OPENCL_VERSION()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
OpenCL
Expand Down
Loading