Skip to content

[SYCL][NativeCPU][CMake] Simplify OCK CMake handling #19704

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

Merged
merged 2 commits into from
Aug 5, 2025
Merged
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
50 changes: 23 additions & 27 deletions llvm/lib/SYCLNativeCPUUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ add_llvm_component_library(LLVMSYCLNativeCPUUtils
ipo
)

set(OCK_SOURCE_DIR "" CACHE PATH "Root of the local checkout of the oneAPI Construction Kit")
set(OCK_GIT_REPO "" CACHE STRING "Git repository for the oneAPI Construction Kit FetchContent")
set(OCK_GIT_TAG "" CACHE STRING "Git tag for the oneAPI Construction Kit FetchContent")
option(NATIVECPU_OCK_USE_FETCHCONTENT "Use FetchContent to acquire oneAPI Construction Kit source code" On)
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)

# Don't fetch OCK if Native CPU is not enabled.
Expand All @@ -31,8 +27,16 @@ if(NOT "native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
endif()

if(NATIVECPU_USE_OCK)
if(NATIVECPU_OCK_USE_FETCHCONTENT)
set(OCK_GIT_INTERNAL_REPO "https://github.com/uxlfoundation/oneapi-construction-kit.git")
set(OCK_SEARCH_LOC "oneapi-construction-kit/compiler_passes")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not overly convinced we should keep OCK_SEARCH_LOC since it was a convenience and isn't really tested. Feel free to keep though.

Copy link
Contributor Author

@sarnex sarnex Aug 5, 2025

Choose a reason for hiding this comment

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

Sorry this is something I added myself just to prevent copy-pasting oneapi-construction-kit/compiler_passes in the find_path and then the set(OCK_SOURCE_DIR), it can't be set by users. Thanks for the review!

if(NOT FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
find_path(OCK_SOURCE_DIR ${OCK_SEARCH_LOC} PATHS ${CMAKE_PREFIX_PATH})
endif()
if(OCK_SOURCE_DIR)
message(STATUS "Found system source location of oneAPI Construction Kit in ${OCK_SOURCE_DIR}")
set(OCK_SOURCE_DIR "${OCK_SOURCE_DIR}/${OCK_SEARCH_LOC}")
set(OCK_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
else()
set(OCK_GIT_REPO "https://github.com/uxlfoundation/oneapi-construction-kit.git")
# commit d0a32d701e34b3285de7ce776ea36abfec673df7
# Merge: a9f848e0e8 56473a8c25
# Author: Harald van Dijk <[email protected]>
Expand All @@ -41,39 +45,31 @@ if(NATIVECPU_USE_OCK)
# Merge pull request #878 from hvdijk/specify-fuse-ld-lld
#
# [RefSi] Explicitly specify -fuse-ld=lld.
set(OCK_GIT_INTERNAL_TAG d0a32d701e34b3285de7ce776ea36abfec673df7)

# Overwrite OCK_GIT_INTERNAL_REPO/OCK_GIT_INTERNAL_TAG if the corresponding options are set
if(OCK_GIT_REPO)
set(OCK_GIT_INTERNAL_REPO "${OCK_GIT_REPO}")
endif()
if(OCK_GIT_TAG)
set(OCK_GIT_INTERNAL_TAG "${OCK_GIT_TAG}")
endif()
set(OCK_GIT_TAG d0a32d701e34b3285de7ce776ea36abfec673df7)

include(FetchContent)
FetchContent_Declare(oneapi-ck
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
GIT_TAG "${OCK_GIT_INTERNAL_TAG}"
GIT_REPOSITORY "${OCK_GIT_REPO}"
GIT_TAG "${OCK_GIT_TAG}"
)
FetchContent_GetProperties(oneapi-ck)
if(NOT oneapi-ck_POPULATED)
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_INTERNAL_REPO}, tag ${OCK_GIT_INTERNAL_TAG}")
if(FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
message(STATUS "Using specified oneAPI Construction Kit repo location at ${FETCHCONTENT_SOURCE_DIR_ONEAPI-CK}")
else()
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_REPO}, tag ${OCK_GIT_TAG}")
endif()
FetchContent_Populate(oneapi-ck)
message(STATUS "oneAPI Construction Kit cloned in ${oneapi-ck_SOURCE_DIR}")
set(OCK_SOURCE_DIR_INTERNAL ${oneapi-ck_SOURCE_DIR}/compiler_passes)
set(OCK_BINARY_DIR_INTERNAL ${oneapi-ck_BINARY_DIR})
set(OCK_SOURCE_DIR ${oneapi-ck_SOURCE_DIR}/compiler_passes)
set(OCK_BINARY_DIR ${oneapi-ck_BINARY_DIR})
endif()
elseif(OCK_SOURCE_DIR)
set(OCK_SOURCE_DIR_INTERNAL "${OCK_SOURCE_DIR}/compiler_passes")
set(OCK_BINARY_DIR_INTERNAL "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
else()
message(FATAL_ERROR "NATIVECPU_OCK_USE_FETCHCONTENT is Off and OCK_SOURCE_DIR not set")
endif()

set(CA_ENABLE_API "cl" CACHE STRING "" FORCE)
add_subdirectory(
${OCK_SOURCE_DIR_INTERNAL}
${OCK_BINARY_DIR_INTERNAL} EXCLUDE_FROM_ALL)
${OCK_SOURCE_DIR}
${OCK_BINARY_DIR} EXCLUDE_FROM_ALL)

install(TARGETS compiler-pipeline
EXPORT;LLVMExports
Expand Down
Loading