Skip to content

[XPTIFW] Enable in-tree builds #2849

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
Dec 15, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def do_configure(args):
sycl_dir = os.path.join(abs_src_dir, "sycl")
spirv_dir = os.path.join(abs_src_dir, "llvm-spirv")
xpti_dir = os.path.join(abs_src_dir, "xpti")
xptifw_dir = os.path.join(abs_src_dir, "xptifw")
libdevice_dir = os.path.join(abs_src_dir, "libdevice")
ocl_header_dir = os.path.join(abs_obj_dir, "OpenCL-Headers")
icd_loader_lib = os.path.join(abs_obj_dir, "OpenCL-ICD-Loader", "build")
llvm_targets_to_build = 'X86'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;libdevice'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;xptifw;libdevice'
libclc_targets_to_build = ''
sycl_build_pi_cuda = 'OFF'
sycl_werror = 'ON'
Expand Down Expand Up @@ -63,10 +64,12 @@ def do_configure(args):
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;libdevice",
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;xptifw;libdevice",
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
Copy link
Contributor

Choose a reason for hiding this comment

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

Previous builds used "-DLLVM_EXTERNAL_XPTI_SOURCE_DIR=$SYCL_HOME/xpti" variable to enable 'xpti' in LLVM. I see two variables now "LLVM_EXTERNAL_XPTI_SOURCE_DIR" and "XPTI_SOURCE_DIR" - is there a reason the second one was added? It might affect scripts people may have already created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LLVM_EXTERNAL_XPTI_SOURCE_DIR tells LLVM where to find xpti external project, so that it could load it. It is required, because LLVM is a monorepo of multiple projects, and LLVM needs to somehow know where to find non-standard sub-projects. It shouldn't affect other scripts.

"-DXPTI_SOURCE_DIR={}".format(xpti_dir),
"-DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR={}".format(xptifw_dir),
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
Expand Down
6 changes: 6 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ if (NOT WIN32)
COMPONENT sycl-headers-extras)
endif()

if (SYCL_ENABLE_XPTI_TRACING)
set(XPTIFW_LIBS xptifw)
endif()

# SYCL toolchain builds all components: compiler, libraries, headers, etc.
add_custom_target( sycl-toolchain
DEPENDS ${SYCL_RT_LIBS}
Expand All @@ -290,6 +294,7 @@ add_custom_target( sycl-toolchain
llvm-objcopy
sycl-post-link
sycl-ls
${XPTIFW_LIBS}
COMMENT "Building SYCL compiler toolchain..."
)

Expand Down Expand Up @@ -350,6 +355,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
pi_opencl
pi_level_zero
libsycldevice
${XPTIFW_LIBS}
)
if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET ocl-icd)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS opencl-icd)
Expand Down
6 changes: 6 additions & 0 deletions xptifw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ endif()

project (xptifw)

foreach(flag_var
Copy link
Contributor

Choose a reason for hiding this comment

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

Since my machine died, I have not been able to reproduce the Windows build failures. To be a part of LLVM builds, the Debug libraries must be of the format xxxxd.dll or they will overwrite the release version and vice-versa and they are not ABI compatible on Windows. The logic that is there in 'xpti' may be needed here to ensure that happens, especially when invoked by LLVM builds as the binaries may be placed in the same directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This piece of code changes static MSVC CRT to Dynamic. So, if there's a /MTd flag in command line options, it'll be replaced with /MDd. The d postfix is preserved, so, it should be fine for debug and non-debug builds.

CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
endforeach()

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
Expand Down
57 changes: 30 additions & 27 deletions xptifw/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ if (NOT EXISTS ${XPTI_SOURCE_DIR})
endif()
include_directories(${XPTI_SOURCE_DIR}/include)

# Download and unpack googletest at configure time
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Only download Google Test outside of LLVM tree.
if (NOT DEFINED LLVM_EXTERNAL_XPTIFW_SOURCE_DIR)
Copy link
Contributor

Choose a reason for hiding this comment

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

This was a simple enough change :) - looks good.

# Download and unpack googletest at configure time
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
endif()

# Now simply link against gtest or gtest_main as needed. Eg
Expand Down