Skip to content

[UR][CMake] Fix detection of preinstalled OpenCL (#21531)#21967

Open
sarnex wants to merge 1 commit intointel:sycl-rel-7_0from
sarnex:cherry_1
Open

[UR][CMake] Fix detection of preinstalled OpenCL (#21531)#21967
sarnex wants to merge 1 commit intointel:sycl-rel-7_0from
sarnex:cherry_1

Conversation

@sarnex
Copy link
Copy Markdown
Contributor

@sarnex sarnex commented May 8, 2026

Cherry pick of 5c7bdc8

There were a couple problems with the OpenCL detection.

  1. System install detection didn't work because I had to add the NO_CMAKE_PACKAGE_REGISTRY argument to find_package to prevent it finding the FetchContent checkout on subsequent calls. This CMake module is called at least twice, one for opencl-aot and once for the UR OpenCL adapter.

  2. If we remove NO_CMAKE_PACKAGE_REGISTRY to fix system install detection, then we hit a problem where if there is a system install, but it fails the check_cxx_source_compiles check because it doesn't support cl_khr_spirv_queries, we had no way to not use the system install it found, so we can't use find_package at all. Use find_path and find_library, whcih is what find_package(OpenCL) does internally anyway. Those two functions have nice validator functions we can use that do exactly what we need, to determine if the found OpenCL install is suitable, and if not, don't use it. However, this function is only available with CMake 3.25 (released in 2022) or later, and we currently require 3.20, but I think saying we don't support system installs with older CMake is reasonable, it still fetches and builds OpenCL from upstream fine.

Also do some minor cleanup like making sure there is always a target named OpenCL that callers can rely on.

Tested the following 3 cases manually:
a) No system OpenCL install
b) System OpenCL install that's too old
c) Working system OpenCL install
and all work as expected.

Closes: #21513


There were a couple problems with the OpenCL detection.

1) System install detection didn't work because I had to add the
`NO_CMAKE_PACKAGE_REGISTRY` argument to `find_package` to prevent it
finding the `FetchContent` checkout on subsequent calls. This CMake
module is called at least twice, one for `opencl-aot` and once for the
UR OpenCL adapter.

2) If we remove `NO_CMAKE_PACKAGE_REGISTRY` to fix system install
detection, then we hit a problem where if there is a system install, but
it fails the `check_cxx_source_compiles` check because it doesn't
support `cl_khr_spirv_queries`, we had no way to not use the system
install it found, so we can't use `find_package` at all. Use `find_path`
and `find_library`, whcih is what `find_package(OpenCL)` does internally
anyway. Those two functions have nice validator functions we can use
that do exactly what we need, to determine if the found OpenCL install
is suitable, and if not, don't use it. However, this function is only
available with CMake 3.25 (released in 2022) or later, and we currently
require `3.20`, but I think saying we don't support system installs with
older CMake is reasonable, it still fetches and builds OpenCL from
upstream fine.


Also do some minor cleanup like making sure there is always a target
named `OpenCL` that callers can rely on.

Tested the following 3 cases manually:
a) No system OpenCL install
b) System OpenCL install that's too old
c) Working system OpenCL install
and all work as expected.

Closes: intel#21513

---------

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
@sarnex sarnex temporarily deployed to WindowsCILock May 8, 2026 14:11 — with GitHub Actions Inactive
@sarnex sarnex marked this pull request as ready for review May 8, 2026 14:14
@sarnex sarnex requested a review from KornevNikita as a code owner May 8, 2026 14:14
@sarnex sarnex requested a review from dm-vodopyanov May 8, 2026 14:15
@sarnex sarnex temporarily deployed to WindowsCILock May 8, 2026 14:35 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to WindowsCILock May 8, 2026 14:35 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to WindowsCILock May 8, 2026 14:35 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant