-
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 4 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,84 @@ | |
|
||
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_GIT https://github.com/llvm/llvm-project.git) | ||
set(LLVM_PROJECT_TAG ffddf33beb8097e760fafcbdd28d56c1d055e820) | ||
message(STATUS "UR_OFFLOAD_INSTALL_DIR and/or UR_OFFLOAD_INCLUDE_DIR not set, building liboffload runtime from source using llvm-project tag: ${LLVM_PROJECT_TAG}") | ||
set(LLVM_PROJECT_SOURCE_DIR ${CMAKE_BINARY_DIR}/llvm-project-src) | ||
set(OPENMP_INSTALL_DIR ${CMAKE_BINARY_DIR}/openmp-install) | ||
# Install to the same directory as main build | ||
set(UR_OFFLOAD_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) | ||
set(UR_OFFLOAD_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include) | ||
# Clone llvm-project only once | ||
ExternalProject_Add(llvm_project_src | ||
GIT_REPOSITORY ${LLVM_PROJECT_GIT} | ||
GIT_TAG ${LLVM_PROJECT_TAG} | ||
SOURCE_DIR ${LLVM_PROJECT_SOURCE_DIR} | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
UPDATE_COMMAND "" | ||
) | ||
# 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_project_src llvm-tblgen LLVMSupport clang lld | ||
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 | ||
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) | ||
endif() | ||
|
||
# When targetting CUDA devices, we need a workaround to avoid sending PTX to | ||
|
@@ -29,22 +99,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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.