Skip to content

[SYCL][NATIVECPU] Allow building Native CPU with shared libraries #13830

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 11 commits into from
Jul 4, 2024
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 <[email protected]>
# 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 <[email protected]>
# 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 @@ -281,7 +281,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
Loading