-
Notifications
You must be signed in to change notification settings - Fork 14k
[OpenMP] Change build of OpenMP device runtime to be a separate runtime #136729
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
Open
jhuber6
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jhuber6:OpenMPGPURuntime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−29
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Ensure the compiler is a valid clang when building the GPU target. | ||
set(req_ver "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") | ||
if(LLVM_VERSION_MAJOR AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND | ||
${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "${req_ver}")) | ||
message(FATAL_ERROR "Cannot build GPU device runtime. CMake compiler " | ||
"'${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' " | ||
" is not 'Clang ${req_ver}'.") | ||
endif() | ||
|
||
set(src_files | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Allocator.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Configuration.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Debug.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Kernel.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/LibC.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Mapping.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Misc.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Parallelism.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Profiling.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Reduction.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/State.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Synchronization.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Tasking.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/DeviceUtils.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/Workshare.cpp | ||
) | ||
|
||
list(APPEND compile_options -flto) | ||
list(APPEND compile_options -fvisibility=hidden) | ||
list(APPEND compile_options -nogpulib) | ||
list(APPEND compile_options -nostdlibinc) | ||
list(APPEND compile_options -fno-rtti) | ||
list(APPEND compile_options -fno-exceptions) | ||
list(APPEND compile_options -fconvergent-functions) | ||
list(APPEND compile_options -Wno-unknown-cuda-version) | ||
if(LLVM_DEFAULT_TARGET_TRIPLE) | ||
list(APPEND compile_options --target=${LLVM_DEFAULT_TARGET_TRIPLE}) | ||
endif() | ||
|
||
# We disable the slp vectorizer during the runtime optimization to avoid | ||
# vectorized accesses to the shared state. Generally, those are "good" but | ||
# the optimizer pipeline (esp. Attributor) does not fully support vectorized | ||
# instructions yet and we end up missing out on way more important constant | ||
# propagation. That said, we will run the vectorizer again after the runtime | ||
# has been linked into the user program. | ||
list(APPEND compile_flags "SHELL: -mllvm -vectorize-slp=false") | ||
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn" OR | ||
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn") | ||
set(target_name "amdgpu") | ||
list(APPEND compile_flags "SHELL:-Xclang -mcode-object-version=none") | ||
elseif("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx" OR | ||
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^nvptx") | ||
set(target_name "nvptx") | ||
list(APPEND compile_flags --cuda-feature=+ptx63) | ||
endif() | ||
|
||
# Trick to combine these into a bitcode file via the linker's LTO pass. | ||
add_executable(libompdevice ${src_files}) | ||
set_target_properties(libompdevice PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
LINKER_LANGUAGE CXX | ||
BUILD_RPATH "" | ||
INSTALL_RPATH "" | ||
RUNTIME_OUTPUT_NAME libomptarget-${target_name}.bc) | ||
|
||
# If the user built with the GPU C library enabled we will use that instead. | ||
if(LIBOMPTARGET_GPU_LIBC_SUPPORT) | ||
target_compile_definitions(libompdevice PRIVATE OMPTARGET_HAS_LIBC) | ||
endif() | ||
target_compile_definitions(libompdevice PRIVATE SHARED_SCRATCHPAD_SIZE=512) | ||
|
||
target_include_directories(libompdevice PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../libc | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../offload/include) | ||
target_compile_options(libompdevice PRIVATE ${compile_options}) | ||
target_link_options(libompdevice PRIVATE | ||
"-flto" "-r" "-nostdlib" "-Wl,--lto-emit-llvm") | ||
if(LLVM_DEFAULT_TARGET_TRIPLE) | ||
target_link_options(libompdevice PRIVATE "--target=${LLVM_DEFAULT_TARGET_TRIPLE}") | ||
endif() | ||
install(TARGETS libompdevice | ||
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ | ||
DESTINATION ${OPENMP_INSTALL_LIBDIR}) | ||
|
||
add_library(ompdevice.all_objs OBJECT IMPORTED) | ||
set_property(TARGET ompdevice.all_objs APPEND PROPERTY IMPORTED_OBJECTS | ||
${CMAKE_CURRENT_BINARY_DIR}/libomptarget-${target_name}.bc) | ||
|
||
# Archive all the object files generated above into a static library | ||
add_library(ompdevice STATIC) | ||
add_dependencies(ompdevice libompdevice) | ||
set_target_properties(ompdevice PROPERTIES | ||
ARCHIVE_OUTPUT_DIRECTORY "${OPENMP_INSTALL_LIBDIR}" | ||
ARCHIVE_OUTPUT_NAME ompdevice | ||
LINKER_LANGUAGE CXX | ||
) | ||
target_link_libraries(ompdevice PRIVATE ompdevice.all_objs) | ||
install(TARGETS ompdevice ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[serious] What happens with host offloading? They also need device-like functions such as
omp_get_device_num()
. The device-side implementation and host-side implementation are different. This also matter when e.g. offloading to a remote cluster (non-GPU) node via MPI.I don't think we should (or can) assume that the triple determines whether it is executing on the host or device.
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.
Host offloading uses 'libomp.so'. The way I think about it is that this 'ompdevice
is basically
libomp` for GPUs.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.
The device-side
omp_get_device_num()
(defined inlibomptarget.so
, notlibomp.so
) only returnsomp_get_initial_device()
, which is wrong for any kind of offloading.After trying out what actuall happens I found that it actually executes the Fortran wrapper (in
libomp.so
). It also incorrectly assumes it is always executing on the host. That looks like a bug.