Skip to content

Commit

Permalink
[SYCL][NATIVECPU] Allow building Native CPU with shared libraries (#1…
Browse files Browse the repository at this point in the history
…3830)

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.
  • Loading branch information
PietroGhg authored Jul 4, 2024
1 parent f57c921 commit 3006324
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 75 deletions.
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(LLVM_LINK_COMPONENTS
ScalarOpts
Support
SYCLLowerIR
SYCLNativeCPUUtils
Target
TargetParser
TransformUtils
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_subdirectory(LineEditor)
add_subdirectory(ProfileData)
add_subdirectory(Passes)
add_subdirectory(SYCLLowerIR)
add_subdirectory(SYCLNativeCPUUtils)
add_subdirectory(TargetParser)
add_subdirectory(TextAPI)
add_subdirectory(ToolDrivers)
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ add_llvm_component_library(LLVMSYCLLowerIR
LocalAccessorToSharedMemory.cpp
GlobalOffset.cpp
TargetHelpers.cpp
PrepareSYCLNativeCPU.cpp
RenameKernelSYCLNativeCPU.cpp
ConvertToMuxBuiltinsSYCLNativeCPU.cpp
PipelineSYCLNativeCPU.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR
Expand Down
98 changes: 98 additions & 0 deletions llvm/lib/SYCLNativeCPUUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
add_llvm_component_library(LLVMSYCLNativeCPUUtils
PipelineSYCLNativeCPU.cpp
PrepareSYCLNativeCPU.cpp
RenameKernelSYCLNativeCPU.cpp
ConvertToMuxBuiltinsSYCLNativeCPU.cpp


ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR

LINK_COMPONENTS
Analysis
Core
Support
Passes
Target
TargetParser
TransformUtils
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.
if(NOT "native_cpu" IN_LIST SYCL_ENABLE_PLUGINS)
set(NATIVECPU_USE_OCK Off CACHE BOOL "Use the oneAPI Construction Kit for Native CPU" FORCE)
endif()

if(NATIVECPU_USE_OCK)
if(NATIVECPU_OCK_USE_FETCHCONTENT)
set(OCK_GIT_INTERNAL_REPO "https://github.com/codeplaysoftware/oneapi-construction-kit.git")
# commit 05e6e1b211704224fbdc6394d85d637f57fafdaf
# Merge: 256027e8 fbc2e567
# Author: Pietro Ghiglio <pietro.ghiglio@codeplay.com>
# Date: Fri May 17 13:08:15 2024 +0200
# Merge pull request #458 from PietroGhg/pietro/link_aggressiveinstcombine
# Link vecz to aggressiveinstcombine
set(OCK_GIT_INTERNAL_TAG 05e6e1b211704224fbdc6394d85d637f57fafdaf)

# 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()
include(FetchContent)
FetchContent_Declare(oneapi-ck
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
GIT_TAG "${OCK_GIT_INTERNAL_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}")
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})
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)

install(TARGETS compiler-pipeline
EXPORT;LLVMExports
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS compiler-pipeline)
install(TARGETS vecz
EXPORT;LLVMExports
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS vecz)
install(TARGETS multi_llvm EXPORT;LLVMExports)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS multi_llvm)
target_compile_definitions(LLVMSYCLNativeCPUUtils PRIVATE NATIVECPU_USE_OCK)
target_include_directories(LLVMSYCLNativeCPUUtils PRIVATE
${oneapi-ck_SOURCE_DIR}/modules/compiler/multi_llvm/include
${oneapi-ck_SOURCE_DIR}/modules/cargo/include
${oneapi-ck_SOURCE_DIR}/modules/compiler/vecz/include
${oneapi-ck_SOURCE_DIR}/modules/compiler/utils/include)
target_link_libraries(LLVMSYCLNativeCPUUtils PRIVATE compiler-pipeline vecz)

endif()
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include "compiler/utils/prepare_barriers_pass.h"
#include "compiler/utils/sub_group_analysis.h"
#include "compiler/utils/work_item_loops_pass.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "vecz/pass.h"
#include "vecz/vecz_target_info.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#endif

using namespace llvm;
Expand Down Expand Up @@ -85,5 +85,4 @@ void llvm::sycl::utils::addSYCLNativeCPUBackendPasses(
#endif
MPM.addPass(PrepareSYCLNativeCPUPass());
MPM.addPass(RenameKernelSYCLNativeCPUPass());

}
69 changes: 1 addition & 68 deletions sycl/plugins/native_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,9 @@ add_sycl_plugin(native_cpu
UnifiedRuntimeCommon
)

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)

if(NATIVECPU_USE_OCK)
if(NATIVECPU_OCK_USE_FETCHCONTENT)
set(OCK_GIT_INTERNAL_REPO "https://github.com/codeplaysoftware/oneapi-construction-kit.git")
# commit bd7eadaf7ffc7d74c88dd309119e858b7ffae0cf
# Merge: e4f71dc16 792461086
# Author: Colin Davidson <colin.davidson@codeplay.com>
# Date: Tue May 7 09:40:38 2024 +0100
# Merge pull request #448 from coldav/colin/support_compiler_passes_only
# Add top level directory which can be used to just build compiler passes
set(OCK_GIT_INTERNAL_TAG bd7eadaf7ffc7d74c88dd309119e858b7ffae0cf)

# 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()
include(FetchContent)
FetchContent_Declare(oneapi-ck
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
GIT_TAG "${OCK_GIT_INTERNAL_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}")
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})
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)

install(TARGETS compiler-pipeline
EXPORT;LLVMExports
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS compiler-pipeline)
install(TARGETS vecz
EXPORT;LLVMExports
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS vecz)
install(TARGETS multi_llvm EXPORT;LLVMExports)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS multi_llvm)
target_compile_definitions(LLVMSYCLLowerIR PRIVATE NATIVECPU_USE_OCK)
target_include_directories(LLVMSYCLLowerIR PRIVATE
${oneapi-ck_SOURCE_DIR}/modules/compiler/multi_llvm/include
${oneapi-ck_SOURCE_DIR}/modules/cargo/include
${oneapi-ck_SOURCE_DIR}/modules/compiler/vecz/include
${oneapi-ck_SOURCE_DIR}/modules/compiler/utils/include)
target_link_libraries(LLVMSYCLLowerIR PRIVATE compiler-pipeline vecz)
target_compile_definitions(pi_native_cpu PRIVATE NATIVECPU_USE_OCK)

endif()

set_target_properties(pi_native_cpu PROPERTIES LINKER_LANGUAGE CXX)
1 change: 0 additions & 1 deletion sycl/plugins/unified_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ endif()
if ("native_cpu" IN_LIST SYCL_ENABLE_PLUGINS)
add_dependencies(sycl-runtime-libraries ur_adapter_native_cpu)

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

if(NATIVECPU_USE_OCK)
message(STATUS "Compiling Native CPU adapter with OCK support.")
Expand Down

0 comments on commit 3006324

Please sign in to comment.