-
Notifications
You must be signed in to change notification settings - Fork 791
[UR][Offload] Add option to build offload adapter #19864
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
Changes from 8 commits
2f8de1a
750d5aa
13d5408
d31e63c
de08c3f
b65d042
b9a0b9f
41ec405
0410a38
4a94f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,103 @@ | |
|
||
set(TARGET_NAME ur_adapter_offload) | ||
|
||
set(UR_OFFLOAD_INSTALL_DIR "" CACHE PATH "Path to the directory containing libomptarget.so etc") | ||
if (UR_OFFLOAD_INSTALL_DIR STREQUAL "") | ||
message(FATAL_ERROR "UR_OFFLOAD_INSTALL_DIR must be defined for the Offload adapter") | ||
endif() | ||
add_ur_adapter(${TARGET_NAME} | ||
SHARED | ||
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/enqueue.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/event.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/kernel.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/memory.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/ur2offload.hpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp | ||
) | ||
|
||
set(UR_OFFLOAD_INSTALL_DIR "" CACHE PATH "Path to the directory containing libomptarget.so etc") | ||
set(UR_OFFLOAD_INCLUDE_DIR "" CACHE PATH "Path to the directory containing LLVM headers") | ||
if (UR_OFFLOAD_INCLUDE_DIR STREQUAL "") | ||
message(FATAL_ERROR "UR_OFFLOAD_INCLUDE_DIR must be defined for the Offload adapter") | ||
if (UR_OFFLOAD_INSTALL_DIR STREQUAL "" OR UR_OFFLOAD_INCLUDE_DIR STREQUAL "") | ||
include(ExternalProject) | ||
set(LLVM_PROJECT_SOURCE_DIR ${CMAKE_BINARY_DIR}/llvm-src-offload) | ||
set(LLVM_PROJECT_TAG 4c0c295775cff0dcfc6439c3f51991ffac0345d8) | ||
set(OPENMP_INSTALL_DIR ${CMAKE_BINARY_DIR}/openmp-install) | ||
set(UR_OFFLOAD_INSTALL_DIR ${CMAKE_BINARY_DIR}/offload-install) | ||
set(UR_OFFLOAD_INCLUDE_DIR ${UR_OFFLOAD_INSTALL_DIR}/include) | ||
|
||
execute_process(COMMAND git -C "${CMAKE_SOURCE_DIR}" worktree prune) | ||
|
||
if(NOT IS_DIRECTORY "${LLVM_PROJECT_SOURCE_DIR}") | ||
execute_process( | ||
COMMAND git -C "${CMAKE_SOURCE_DIR}" worktree add --no-checkout --detach "${LLVM_PROJECT_SOURCE_DIR}" "${LLVM_PROJECT_TAG}" | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
endif() | ||
|
||
execute_process( | ||
COMMAND git sparse-checkout init --cone | ||
WORKING_DIRECTORY "${LLVM_PROJECT_SOURCE_DIR}" | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
|
||
execute_process( | ||
COMMAND git sparse-checkout set openmp offload cmake llvm/include libc | ||
WORKING_DIRECTORY "${LLVM_PROJECT_SOURCE_DIR}" | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
|
||
execute_process( | ||
COMMAND git checkout "${LLVM_PROJECT_TAG}" | ||
WORKING_DIRECTORY "${LLVM_PROJECT_SOURCE_DIR}" | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
|
||
# Build OpenMP runtime (required dependency for offload's libomptarget) from the cloned source | ||
ExternalProject_Add(openmp_ext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we not just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We’re not using Also, in the latest commit I improved this further: rather than cloning llvm-project again, I now create a git worktree from the already cloned intel/llvm repository, pulling in only the directories needed for the runtime build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into this a while ago and figured out how to build openmp without a dependency on clang. It required a few patches, which I should really figure out who to harass about.
What if the runtimes are using a newer version of llvm-project that hasn't been pulled down into intel/llvm yet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if the statement was confusing, worktree is created from fresh enough hash specified in LLVM_PROJECT_TAG, i.e. assumption is that llvm-project remote and its main branch is visible in the cloned intel/llvm repo, i.e. just trying to avoid re-cloning what's already available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue I'm thinking of is with, for example the commit Although, there's a commit from 13 minutes ago on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pulldowns approximately once per week/2weeks. |
||
# DeviceRTL uses -fuse-ld=lld, so add lld to the dependencies. | ||
DEPENDS llvm-tblgen LLVMSupport clang lld FileCheck not | ||
SOURCE_DIR ${LLVM_PROJECT_SOURCE_DIR}/openmp | ||
CMAKE_ARGS | ||
-DCMAKE_INSTALL_PREFIX=${OPENMP_INSTALL_DIR} | ||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
-DCMAKE_C_COMPILER=${CMAKE_BINARY_DIR}/bin/clang | ||
-DCMAKE_CXX_COMPILER=${CMAKE_BINARY_DIR}/bin/clang++ | ||
-DLIBOMP_OMPD_GDB_SUPPORT=OFF | ||
-DOPENMP_ENABLE_OMPT_TOOLS=OFF | ||
-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/bin | ||
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install | ||
UPDATE_COMMAND "" | ||
DOWNLOAD_COMMAND "" | ||
) | ||
|
||
# Build liboffload runtime from the same source tree | ||
ExternalProject_Add(offload_ext | ||
DEPENDS openmp_ext | ||
SOURCE_DIR ${LLVM_PROJECT_SOURCE_DIR}/offload | ||
LIST_SEPARATOR | | ||
CMAKE_ARGS | ||
-DCMAKE_INSTALL_PREFIX=${UR_OFFLOAD_INSTALL_DIR} | ||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
-DCMAKE_C_COMPILER=${CMAKE_BINARY_DIR}/bin/clang | ||
-DCMAKE_CXX_COMPILER=${CMAKE_BINARY_DIR}/bin/clang++ | ||
-DLIBOMPTARGET_LLVM_INCLUDE_DIRS=${LLVM_PROJECT_SOURCE_DIR}/llvm/include|${CMAKE_BINARY_DIR}/include | ||
-DLLVM_DIR=${CMAKE_BINARY_DIR}/lib/cmake/llvm | ||
-DLIBOMPTARGET_PLUGINS_TO_BUILD=cuda|amdgpu | ||
-DLIBOMP_INCLUDE_DIR=${OPENMP_INSTALL_DIR}/include | ||
-DLLVM_TABLEGEN=${CMAKE_BINARY_DIR}/bin/llvm-tblgen | ||
-DCMAKE_PREFIX_PATH=${OPENMP_INSTALL_DIR}|${CMAKE_BINARY_DIR}/bin | ||
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install | ||
UPDATE_COMMAND "" | ||
DOWNLOAD_COMMAND "" | ||
BUILD_BYPRODUCTS "${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload.so" | ||
) | ||
add_dependencies(${TARGET_NAME} offload_ext) | ||
install(DIRECTORY "${UR_OFFLOAD_INSTALL_DIR}/" | ||
DESTINATION "${CMAKE_INSTALL_PREFIX}" | ||
COMPONENT ur_adapter_offload) | ||
endif() | ||
|
||
# When targetting CUDA devices, we need a workaround to avoid sending PTX to | ||
|
@@ -29,22 +118,6 @@ if (NOT TARGET cudadrv) | |
) | ||
endif() | ||
|
||
add_ur_adapter(${TARGET_NAME} | ||
SHARED | ||
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/enqueue.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/event.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/kernel.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/memory.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/ur2offload.hpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp | ||
) | ||
install_ur_library(${TARGET_NAME}) | ||
|
||
set_target_properties(${TARGET_NAME} PROPERTIES | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a helper for this:
https://github.com/intel/llvm/blob/sycl/unified-runtime/cmake/helpers.cmake#L246
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I tried this, but the helper’s shallow checkout approach seems to work only with tags, and it becomes slow when used with commit hashes. So I am leaving this part as is for now if that's ok.