Skip to content

Commit 3006324

Browse files
authored
[SYCL][NATIVECPU] Allow building Native CPU with shared libraries (#13830)
Currently building Native CPU with shared libraries enabled leads to a CMake error when configuring: some components of the oneAPI Construction Kit depend on `LLVMPasses`, and since they are also added as `link_libraries` to `SYCLLowerIR` (which `LLVMPasses` depends on), that creates a circular dependency that is not allowed when building with shared libraries enabled. This PR addresses this by moving all the Native CPU components to a new folder (`SYCLNativeCPUUtils`), that is not linked to `LLVMPasses`, thus breaking the circular dependencies.
1 parent f57c921 commit 3006324

File tree

10 files changed

+102
-75
lines changed

10 files changed

+102
-75
lines changed

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(LLVM_LINK_COMPONENTS
2929
ScalarOpts
3030
Support
3131
SYCLLowerIR
32+
SYCLNativeCPUUtils
3233
Target
3334
TargetParser
3435
TransformUtils

llvm/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_subdirectory(LineEditor)
3838
add_subdirectory(ProfileData)
3939
add_subdirectory(Passes)
4040
add_subdirectory(SYCLLowerIR)
41+
add_subdirectory(SYCLNativeCPUUtils)
4142
add_subdirectory(TargetParser)
4243
add_subdirectory(TextAPI)
4344
add_subdirectory(ToolDrivers)

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ add_llvm_component_library(LLVMSYCLLowerIR
7070
LocalAccessorToSharedMemory.cpp
7171
GlobalOffset.cpp
7272
TargetHelpers.cpp
73-
PrepareSYCLNativeCPU.cpp
74-
RenameKernelSYCLNativeCPU.cpp
75-
ConvertToMuxBuiltinsSYCLNativeCPU.cpp
76-
PipelineSYCLNativeCPU.cpp
7773

7874
ADDITIONAL_HEADER_DIRS
7975
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
add_llvm_component_library(LLVMSYCLNativeCPUUtils
2+
PipelineSYCLNativeCPU.cpp
3+
PrepareSYCLNativeCPU.cpp
4+
RenameKernelSYCLNativeCPU.cpp
5+
ConvertToMuxBuiltinsSYCLNativeCPU.cpp
6+
7+
8+
ADDITIONAL_HEADER_DIRS
9+
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR
10+
11+
LINK_COMPONENTS
12+
Analysis
13+
Core
14+
Support
15+
Passes
16+
Target
17+
TargetParser
18+
TransformUtils
19+
ipo
20+
)
21+
22+
set(OCK_SOURCE_DIR "" CACHE PATH "Root of the local checkout of the oneAPI Construction Kit")
23+
set(OCK_GIT_REPO "" CACHE STRING "Git repository for the oneAPI Construction Kit FetchContent")
24+
set(OCK_GIT_TAG "" CACHE STRING "Git tag for the oneAPI Construction Kit FetchContent")
25+
option(NATIVECPU_OCK_USE_FETCHCONTENT "Use FetchContent to acquire oneAPI Construction Kit source code" On)
26+
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)
27+
28+
# Don't fetch OCK if Native CPU is not enabled.
29+
if(NOT "native_cpu" IN_LIST SYCL_ENABLE_PLUGINS)
30+
set(NATIVECPU_USE_OCK Off CACHE BOOL "Use the oneAPI Construction Kit for Native CPU" FORCE)
31+
endif()
32+
33+
if(NATIVECPU_USE_OCK)
34+
if(NATIVECPU_OCK_USE_FETCHCONTENT)
35+
set(OCK_GIT_INTERNAL_REPO "https://github.com/codeplaysoftware/oneapi-construction-kit.git")
36+
# commit 05e6e1b211704224fbdc6394d85d637f57fafdaf
37+
# Merge: 256027e8 fbc2e567
38+
# Author: Pietro Ghiglio <[email protected]>
39+
# Date: Fri May 17 13:08:15 2024 +0200
40+
# Merge pull request #458 from PietroGhg/pietro/link_aggressiveinstcombine
41+
# Link vecz to aggressiveinstcombine
42+
set(OCK_GIT_INTERNAL_TAG 05e6e1b211704224fbdc6394d85d637f57fafdaf)
43+
44+
# Overwrite OCK_GIT_INTERNAL_REPO/OCK_GIT_INTERNAL_TAG if the corresponding options are set
45+
if(OCK_GIT_REPO)
46+
set(OCK_GIT_INTERNAL_REPO "${OCK_GIT_REPO}")
47+
endif()
48+
if(OCK_GIT_TAG)
49+
set(OCK_GIT_INTERNAL_TAG "${OCK_GIT_TAG}")
50+
endif()
51+
include(FetchContent)
52+
FetchContent_Declare(oneapi-ck
53+
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
54+
GIT_TAG "${OCK_GIT_INTERNAL_TAG}"
55+
)
56+
FetchContent_GetProperties(oneapi-ck)
57+
if(NOT oneapi-ck_POPULATED)
58+
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_INTERNAL_REPO}, tag ${OCK_GIT_INTERNAL_TAG}")
59+
FetchContent_Populate(oneapi-ck)
60+
message(STATUS "oneAPI Construction Kit cloned in ${oneapi-ck_SOURCE_DIR}")
61+
set(OCK_SOURCE_DIR_INTERNAL ${oneapi-ck_SOURCE_DIR}/compiler_passes)
62+
set(OCK_BINARY_DIR_INTERNAL ${oneapi-ck_BINARY_DIR})
63+
endif()
64+
elseif(OCK_SOURCE_DIR)
65+
set(OCK_SOURCE_DIR_INTERNAL "${OCK_SOURCE_DIR}/compiler_passes")
66+
set(OCK_BINARY_DIR_INTERNAL "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
67+
else()
68+
message(FATAL_ERROR "NATIVECPU_OCK_USE_FETCHCONTENT is Off and OCK_SOURCE_DIR not set")
69+
endif()
70+
71+
set(CA_ENABLE_API "cl" CACHE STRING "" FORCE)
72+
add_subdirectory(
73+
${OCK_SOURCE_DIR_INTERNAL}
74+
${OCK_BINARY_DIR_INTERNAL} EXCLUDE_FROM_ALL)
75+
76+
install(TARGETS compiler-pipeline
77+
EXPORT;LLVMExports
78+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
79+
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
80+
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline)
81+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS compiler-pipeline)
82+
install(TARGETS vecz
83+
EXPORT;LLVMExports
84+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
85+
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
86+
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz)
87+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS vecz)
88+
install(TARGETS multi_llvm EXPORT;LLVMExports)
89+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS multi_llvm)
90+
target_compile_definitions(LLVMSYCLNativeCPUUtils PRIVATE NATIVECPU_USE_OCK)
91+
target_include_directories(LLVMSYCLNativeCPUUtils PRIVATE
92+
${oneapi-ck_SOURCE_DIR}/modules/compiler/multi_llvm/include
93+
${oneapi-ck_SOURCE_DIR}/modules/cargo/include
94+
${oneapi-ck_SOURCE_DIR}/modules/compiler/vecz/include
95+
${oneapi-ck_SOURCE_DIR}/modules/compiler/utils/include)
96+
target_link_libraries(LLVMSYCLNativeCPUUtils PRIVATE compiler-pipeline vecz)
97+
98+
endif()

llvm/lib/SYCLLowerIR/PipelineSYCLNativeCPU.cpp renamed to llvm/lib/SYCLNativeCPUUtils/PipelineSYCLNativeCPU.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include "compiler/utils/prepare_barriers_pass.h"
2323
#include "compiler/utils/sub_group_analysis.h"
2424
#include "compiler/utils/work_item_loops_pass.h"
25-
#include "llvm/Transforms/IPO/AlwaysInliner.h"
2625
#include "vecz/pass.h"
2726
#include "vecz/vecz_target_info.h"
27+
#include "llvm/Transforms/IPO/AlwaysInliner.h"
2828
#endif
2929

3030
using namespace llvm;
@@ -85,5 +85,4 @@ void llvm::sycl::utils::addSYCLNativeCPUBackendPasses(
8585
#endif
8686
MPM.addPass(PrepareSYCLNativeCPUPass());
8787
MPM.addPass(RenameKernelSYCLNativeCPUPass());
88-
8988
}

sycl/plugins/native_cpu/CMakeLists.txt

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,9 @@ add_sycl_plugin(native_cpu
2323
UnifiedRuntimeCommon
2424
)
2525

26-
set(OCK_SOURCE_DIR "" CACHE PATH "Root of the local checkout of the oneAPI Construction Kit")
27-
set(OCK_GIT_REPO "" CACHE STRING "Git repository for the oneAPI Construction Kit FetchContent")
28-
set(OCK_GIT_TAG "" CACHE STRING "Git tag for the oneAPI Construction Kit FetchContent")
29-
option(NATIVECPU_OCK_USE_FETCHCONTENT "Use FetchContent to acquire oneAPI Construction Kit source code" On)
3026

3127
if(NATIVECPU_USE_OCK)
32-
if(NATIVECPU_OCK_USE_FETCHCONTENT)
33-
set(OCK_GIT_INTERNAL_REPO "https://github.com/codeplaysoftware/oneapi-construction-kit.git")
34-
# commit bd7eadaf7ffc7d74c88dd309119e858b7ffae0cf
35-
# Merge: e4f71dc16 792461086
36-
# Author: Colin Davidson <[email protected]>
37-
# Date: Tue May 7 09:40:38 2024 +0100
38-
# Merge pull request #448 from coldav/colin/support_compiler_passes_only
39-
# Add top level directory which can be used to just build compiler passes
40-
set(OCK_GIT_INTERNAL_TAG bd7eadaf7ffc7d74c88dd309119e858b7ffae0cf)
41-
42-
# Overwrite OCK_GIT_INTERNAL_REPO/OCK_GIT_INTERNAL_TAG if the corresponding options are set
43-
if(OCK_GIT_REPO)
44-
set(OCK_GIT_INTERNAL_REPO "${OCK_GIT_REPO}")
45-
endif()
46-
if(OCK_GIT_TAG)
47-
set(OCK_GIT_INTERNAL_TAG "${OCK_GIT_TAG}")
48-
endif()
49-
include(FetchContent)
50-
FetchContent_Declare(oneapi-ck
51-
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
52-
GIT_TAG "${OCK_GIT_INTERNAL_TAG}"
53-
)
54-
FetchContent_GetProperties(oneapi-ck)
55-
if(NOT oneapi-ck_POPULATED)
56-
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_INTERNAL_REPO}, tag ${OCK_GIT_INTERNAL_TAG}")
57-
FetchContent_Populate(oneapi-ck)
58-
message(STATUS "oneAPI Construction Kit cloned in ${oneapi-ck_SOURCE_DIR}")
59-
set(OCK_SOURCE_DIR_INTERNAL ${oneapi-ck_SOURCE_DIR}/compiler_passes)
60-
set(OCK_BINARY_DIR_INTERNAL ${oneapi-ck_BINARY_DIR})
61-
endif()
62-
elseif(OCK_SOURCE_DIR)
63-
set(OCK_SOURCE_DIR_INTERNAL "${OCK_SOURCE_DIR}/compiler_passes")
64-
set(OCK_BINARY_DIR_INTERNAL "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
65-
else()
66-
message(FATAL_ERROR "NATIVECPU_OCK_USE_FETCHCONTENT is Off and OCK_SOURCE_DIR not set")
67-
endif()
68-
69-
set(CA_ENABLE_API "cl" CACHE STRING "" FORCE)
70-
add_subdirectory(
71-
${OCK_SOURCE_DIR_INTERNAL}
72-
${OCK_BINARY_DIR_INTERNAL} EXCLUDE_FROM_ALL)
73-
74-
install(TARGETS compiler-pipeline
75-
EXPORT;LLVMExports
76-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
77-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
78-
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline)
79-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS compiler-pipeline)
80-
install(TARGETS vecz
81-
EXPORT;LLVMExports
82-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
83-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
84-
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz)
85-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS vecz)
86-
install(TARGETS multi_llvm EXPORT;LLVMExports)
87-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS multi_llvm)
88-
target_compile_definitions(LLVMSYCLLowerIR PRIVATE NATIVECPU_USE_OCK)
89-
target_include_directories(LLVMSYCLLowerIR PRIVATE
90-
${oneapi-ck_SOURCE_DIR}/modules/compiler/multi_llvm/include
91-
${oneapi-ck_SOURCE_DIR}/modules/cargo/include
92-
${oneapi-ck_SOURCE_DIR}/modules/compiler/vecz/include
93-
${oneapi-ck_SOURCE_DIR}/modules/compiler/utils/include)
94-
target_link_libraries(LLVMSYCLLowerIR PRIVATE compiler-pipeline vecz)
9528
target_compile_definitions(pi_native_cpu PRIVATE NATIVECPU_USE_OCK)
96-
9729
endif()
30+
9831
set_target_properties(pi_native_cpu PROPERTIES LINKER_LANGUAGE CXX)

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ endif()
282282
if ("native_cpu" IN_LIST SYCL_ENABLE_PLUGINS)
283283
add_dependencies(sycl-runtime-libraries ur_adapter_native_cpu)
284284

285-
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)
286285

287286
if(NATIVECPU_USE_OCK)
288287
message(STATUS "Compiling Native CPU adapter with OCK support.")

0 commit comments

Comments
 (0)